Skip to content

Commit 7dbfebb

Browse files
Merge pull request #200 from upsuper-forks/async-read-grid-profile
Make grid profile reading async to avoid HASS warning
2 parents 17d5576 + 611e867 commit 7dbfebb

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

custom_components/enphase_envoy/envoy_reader.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,11 @@ def parse_devicedata(data):
176176
return idd
177177

178178

179+
def read_file_as_bytes(filename):
180+
with open(filename, "rb") as f:
181+
return f.read()
182+
183+
179184
class EnvoyReaderError(Exception):
180185
pass
181186

@@ -1335,9 +1340,9 @@ async def set_grid_profile(self, profile_id):
13351340
async def upload_grid_profile(self, file):
13361341
if self.endpoint_installer_agf is not None:
13371342
formatted_url = ENDPOINT_URL_INSTALLER_AGF_UPLOAD_PROFILE.format(self.host)
1338-
resp = await self._async_post(
1339-
formatted_url, files={"file": open(file, "rb")}
1340-
)
1343+
loop = asyncio.get_running_loop()
1344+
content = await loop.run_in_executor(None, read_file_as_bytes, file)
1345+
resp = await self._async_post(formatted_url, files={"file": content})
13411346
message = resp.json().get("message")
13421347
if message != "success":
13431348
raise EnvoyError(f"Failed uploading grid profile: {message}")

0 commit comments

Comments
 (0)