Skip to content

Commit

Permalink
refactor: Enhance coordinator
Browse files Browse the repository at this point in the history
  • Loading branch information
davidrapan authored Feb 10, 2025
1 parent 2018683 commit d9236cb
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions custom_components/solarman/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ def __init__(self, hass: HomeAssistant, device: Device):
super().__init__(hass, _LOGGER, name = device.config.name, update_interval = TIMINGS_UPDATE_INTERVAL, always_update = False)
self.device = device
self._counter = 0
self._last_successful_data: dict[str, Any] | None = None
self._is_offline_logged = False

async def _async_setup(self) -> None:
Expand All @@ -32,7 +31,6 @@ async def _async_update_data(self) -> dict[str, Any]:
try:
try:
data = await self.device.get(int(self._counter * self._update_interval_seconds))
self._last_successful_data = data
self._is_offline_logged = False
return data
#return await self.device.get(int(self._counter * self._update_interval_seconds))
Expand All @@ -45,8 +43,8 @@ async def _async_update_data(self) -> dict[str, Any]:
_LOGGER.warning("Error retrieving data. Use last known data.")
self._is_offline_logged = True

if self._last_successful_data is not None:
return self._last_successful_data
if self.last_update_success:
return self.data

if isinstance(e, TimeoutError):
raise
Expand Down

0 comments on commit d9236cb

Please sign in to comment.