diff --git a/custom_components/enphase_envoy/__init__.py b/custom_components/enphase_envoy/__init__.py index 04c4182..31e4c05 100644 --- a/custom_components/enphase_envoy/__init__.py +++ b/custom_components/enphase_envoy/__init__.py @@ -170,6 +170,16 @@ async def set_grid_profile(call: ServiceCall): set_grid_profile, ) + async def upload_grid_profile(call: ServiceCall): + await envoy_reader.upload_grid_profile(call.data["file"]) + await coordinator.async_request_refresh() + + hass.services.async_register( + DOMAIN, + "upload_grid_profile", + upload_grid_profile, + ) + @Throttle(time_between_realtime_updates) def update_production_meters(streamdata: StreamData): new_data = {} diff --git a/custom_components/enphase_envoy/envoy_reader.py b/custom_components/enphase_envoy/envoy_reader.py index 92bcabe..3b1fabb 100644 --- a/custom_components/enphase_envoy/envoy_reader.py +++ b/custom_components/enphase_envoy/envoy_reader.py @@ -37,6 +37,7 @@ ENDPOINT_URL_PDM_ENERGY = "https://{}/ivp/pdm/energy" ENDPOINT_URL_INSTALLER_AGF = "https://{}/installer/agf/index.json" ENDPOINT_URL_INSTALLER_AGF_SET_PROFILE = "https://{}/installer/agf/set_profile.json" +ENDPOINT_URL_INSTALLER_AGF_UPLOAD_PROFILE = "https://{}/installer/agf/upload_profile_package" ENVOY_MODEL_M = "Metered" ENVOY_MODEL_S = "Standard" @@ -1355,6 +1356,21 @@ async def set_grid_profile(self, profile_id): self._clear_endpoint_cache("endpoint_installer_agf") return resp + async def upload_grid_profile(self, file): + if self.endpoint_installer_agf is not None: + formatted_url = ENDPOINT_URL_INSTALLER_AGF_UPLOAD_PROFILE.format(self.host) + resp = await self._async_post( + formatted_url, files={"file": open(file, "rb")} + ) + message = resp.json().get("message") + if message != "success": + raise EnvoyError( + f"Failed uploading grid profile: {message}" + ) + + self._clear_endpoint_cache("endpoint_installer_agf") + return resp + def run_stream(self): print("Reading stream...") loop = asyncio.get_event_loop() diff --git a/custom_components/enphase_envoy/services.yaml b/custom_components/enphase_envoy/services.yaml index 550864c..65163c6 100644 --- a/custom_components/enphase_envoy/services.yaml +++ b/custom_components/enphase_envoy/services.yaml @@ -6,3 +6,10 @@ set_grid_profile: example: "EN 50549-1:2019 RfG E02 Netherlands:1.2.4" selector: text: +upload_grid_profile: + fields: + file: + required: true + example: "/share/grid_profiles/64d31e5868ac391817b21af1" + selector: + text: diff --git a/custom_components/enphase_envoy/translations/en.json b/custom_components/enphase_envoy/translations/en.json index 1f2c4e5..acbab5e 100644 --- a/custom_components/enphase_envoy/translations/en.json +++ b/custom_components/enphase_envoy/translations/en.json @@ -57,6 +57,16 @@ "get_grid_profiles": { "name": "Get grid profiles", "description": "Get currently selected and all available profiles." + }, + "upload_grid_profile": { + "name": "Upload grid profile", + "description": "Upload a grid profile package file to the Envoy so that it is available for selecting.", + "fields": { + "file": { + "name": "File", + "description": "Path to the grid profile package file" + } + } } } }