Skip to content

Commit

Permalink
feat: Don't raise TimeoutError immediately
Browse files Browse the repository at this point in the history
  • Loading branch information
davidrapan committed Aug 8, 2024
1 parent aa5cc95 commit 57bcaac
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions custom_components/solarman/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,21 +139,21 @@ def get_result(self, middleware = None):
result = middleware.get_result() if middleware else {}

if len(result) > 0:
_LOGGER.debug(f"Returning new values to the Coordinator. [Previous Status: {self.get_connection_status()}]")
_LOGGER.debug(f"Returning new values to the Coordinator. [Previous State: {self.get_connection_status()} ({self.status})]")
now = datetime.now()
self.status_interval = now - self.status_updated
self.status_updated = now
self.status = 1

return result

async def async_get_failed(self, message):
_LOGGER.debug(f"Request failed. [Previous Status: {self.get_connection_status()}]")
async def async_get_failed(self, message = None):
_LOGGER.debug(f"Request failed. [Previous State: {self.get_connection_status()} ({self.status})]")
self.status = 0 if self.status == 1 else -1

await self.async_disconnect()

if self.status == -1:
if message and self.status == -1:
raise UpdateFailed(message)

async def async_get(self, runtime = 0):
Expand Down Expand Up @@ -200,6 +200,13 @@ async def async_get(self, runtime = 0):
else:
await self.async_get_failed(f"Querying {self.serial} at {self.address}:{self.port} failed.")

except TimeoutError:
last_state = self.status
await self.async_get_failed()
if last_state < 1:
raise
else:
_LOGGER.debug(f"Timeout fetching {self.name} data")
except UpdateFailed:
raise
except Exception as e:
Expand Down

0 comments on commit 57bcaac

Please sign in to comment.