-
-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update coordinator and deye mirco #356
Changes from all commits
32026e8
9d5507a
bbe8b4d
32019b7
0d4b5f7
9a66b3d
b0bd7de
84b1047
a0d146f
a2746c0
05d0bf1
5155743
d5c6464
16794a1
41d10e6
a45c08e
774aa55
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,25 +14,45 @@ | |
|
||
class InverterCoordinator(DataUpdateCoordinator[dict[str, Any]]): | ||
def __init__(self, hass: HomeAssistant, inverter: Inverter): | ||
super().__init__(hass, _LOGGER, name = inverter.config.name, update_interval = TIMINGS_UPDATE_INTERVAL, always_update = False) | ||
super().__init__( | ||
hass, | ||
_LOGGER, | ||
name=inverter.config.name, | ||
update_interval=TIMINGS_UPDATE_INTERVAL, | ||
always_update=False, | ||
) | ||
self.inverter = inverter | ||
self._counter = 0 | ||
self._last_successful_data: dict[str, Any] | None = None | ||
self._is_offline_logged = False | ||
|
||
async def _async_setup(self) -> None: | ||
try: | ||
return await self.inverter.load() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I took over "example" code from |
||
await self.inverter.load() | ||
except Exception as e: | ||
if isinstance(e, TimeoutError): | ||
raise | ||
raise UpdateFailed(e) from e | ||
|
||
async def _async_update_data(self) -> dict[str, Any]: | ||
try: | ||
return await self.inverter.get(int(self._counter * self._update_interval_seconds)) | ||
data = await self.inverter.get(int(self._counter * self._update_interval_seconds)) | ||
self._last_successful_data = data | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We already talked about this, did you forgot? self._last_successful_data is already stored in self.data. So this additional caching is completely unnecessary. |
||
self._is_offline_logged = False | ||
return data | ||
except Exception as e: | ||
self._counter = 0 | ||
|
||
if not self._is_offline_logged: | ||
_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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On top of that as we already discussed this, data are cached not just here in the |
||
|
||
if isinstance(e, TimeoutError): | ||
raise | ||
|
||
raise UpdateFailed(e) from e | ||
finally: | ||
if self.last_update_success: | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We already discussed this I want just single sensor for this so let's make it work in current format by bit shifting, okay? I want to avoid this 1, 2, 3, ... nonsense. 😉 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, don't reformat code like this. The line is not that long and I'm not really a fan of using just narrow columns of the code. 😉