Skip to content

Commit

Permalink
feat: Propagate exceptions out of main flow
Browse files Browse the repository at this point in the history
  • Loading branch information
davidrapan committed Oct 2, 2024
1 parent cb98702 commit 44c44f0
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions custom_components/solarman/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def get_result(self, middleware = None):
result_count = len(result) if result else 0

if result_count > 0:
_LOGGER.debug(f"[{self.serial}] Returning {result_count} new values to the Coordinator. [Previous State: {self.get_connection_state()} ({self.state}), Values: {result}]")
_LOGGER.debug(f"[{self.serial}] Returning {result_count} new values to the Coordinator. [Previous State: {self.get_connection_state()} ({self.state})]")
now = datetime.now()
self.state_interval = now - self.state_updated
self.state_updated = now
Expand Down Expand Up @@ -260,6 +260,9 @@ async def get(self, runtime = 0):
if not self.auto_reconnect:
await self.disconnect()

if not attempts_left > 0:
raise

await asyncio.sleep((ACTION_ATTEMPTS - attempts_left) * TIMINGS_WAIT_SLEEP)

_LOGGER.debug(f"[{self.serial}] Querying {start_end} {'succeeded.' if results[i] == 1 else f'attempts left: {attempts_left}{'' if attempts_left > 0 else ', aborting.'}'}")
Expand All @@ -270,7 +273,7 @@ async def get(self, runtime = 0):
if not 0 in results:
return self.get_result(self.profile)
else:
await self.get_failed(f"[{self.serial}] Querying {self.address}:{self.port} failed: {results}.")
await self.get_failed(f"[{self.serial}] Querying {self.address}:{self.port} failed: {results}")

except TimeoutError:
last_state = self.state
Expand All @@ -282,7 +285,8 @@ async def get(self, runtime = 0):
except UpdateFailed:
raise
except Exception as e:
await self.get_failed(f"[{self.serial}] Querying {self.address}:{self.port} failed: {results} with exception: {format_exception(e)}.")
#await self.get_failed(f"[{self.serial}] Querying {self.address}:{self.port} failed: {results} with exception: {format_exception(e)}.")
await self.get_failed(f"[{self.serial}] {format_exception(e)}: {results}")
finally:
self._is_busy = 0

Expand Down

0 comments on commit 44c44f0

Please sign in to comment.