Skip to content

Commit

Permalink
Add upload_grid_profile service
Browse files Browse the repository at this point in the history
  • Loading branch information
upsuper committed Feb 11, 2024
1 parent efa9ef6 commit 4a1892b
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 0 deletions.
10 changes: 10 additions & 0 deletions custom_components/enphase_envoy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down
15 changes: 15 additions & 0 deletions custom_components/enphase_envoy/envoy_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -1355,6 +1356,20 @@ 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}"
)

return resp

def run_stream(self):
print("Reading stream...")
loop = asyncio.get_event_loop()
Expand Down
7 changes: 7 additions & 0 deletions custom_components/enphase_envoy/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
10 changes: 10 additions & 0 deletions custom_components/enphase_envoy/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}
}
}

0 comments on commit 4a1892b

Please sign in to comment.