Skip to content

Commit

Permalink
refactor: api.py error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
davidrapan committed Dec 16, 2024
1 parent d77eedd commit 5255e3e
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions custom_components/solarman/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,16 +234,12 @@ async def get(self, runtime = 0, requests = None):
_LOGGER.debug(f"[{self.config.serial}] Returning {rcount} new value{'s' if rcount > 1 else ''}. [Previous State: {self.state.print} ({self.state.value})]")
self.state.update()

except (TimeoutError, Exception) as e:
_LOGGER.debug(f"[{self.config.serial}] Fetching failed. [Previous State: {self.state.print} ({self.state.value})]")

except Exception as e:
await self.endpoint.discover()

if self.state.reevaluate():
await self.modbus.disconnect()
raise

_LOGGER.debug(f"[{self.config.serial}] {"Timeout" if isinstance(e, TimeoutError) else "Error"} fetching {self.config.name} data: {format_exception(e)}")
_LOGGER.debug(f"[{self.config.serial}] {"Timeout" if isinstance(e, TimeoutError) else "Error"} fetching {self.config.name} data. [Previous State: {self.state.print} ({self.state.value}), {format_exception(e)}]")

return result

Expand Down

0 comments on commit 5255e3e

Please sign in to comment.