Skip to content

Commit

Permalink
fix: Run response to HEARTBEAT in asyncio.ensure_future
Browse files Browse the repository at this point in the history
  • Loading branch information
davidrapan committed Dec 18, 2024
1 parent d7c4e76 commit dd7aa49
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 6 deletions.
2 changes: 1 addition & 1 deletion custom_components/solarman/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def _received_frame_is_valid(self, frame):
return False
if frame.startswith(self.v5_start + b"\x01\x00\x10\x47"):
self.log.debug("[%s] V5_HEARTBEAT: %s", self.serial, frame.hex(" "))
execute_async(self._heartbeat_response(frame))
asyncio.ensure_future(self._heartbeat_response(frame))
return False
return True

Expand Down
6 changes: 1 addition & 5 deletions custom_components/solarman/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,7 @@ async def async_execute(x):
return await loop.run_in_executor(None, x)

async def async_listdir(path, prefix = ""):
return sorted([prefix + f for f in await async_execute(lambda: os.listdir(path)) if os.path.isfile(path + f)]) if os.path.exists(path) else []

def execute_async(x):
loop = asyncio.get_event_loop()
return loop.run_until_complete(x)
return sorted([prefix + f for f in await async_execute(os.listdir(path)) if os.path.isfile(path + f)]) if os.path.exists(path) else []

def get_coordinator_descriptions(hass: HomeAssistant, entry_id: str, platform: str):
coordinator = hass.data[DOMAIN][entry_id]
Expand Down

0 comments on commit dd7aa49

Please sign in to comment.