diff --git a/CHANGELOG.md b/CHANGELOG.md index 6683927c0..465f85711 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Ongoing / v0.44.8a0 +- Fix for [#288](https://github.com/plugwise/plugwise_usb-beta/issues/288) via PR [293](https://github.com/plugwise/python-plugwise-usb/pull/293) - Chores move module publishing on (test)pypi to Trusted Publishing (and using uv) - released as alpha 0.44.8a0 to demonstrate functionality ## v0.44.7 - 2025-07-08 diff --git a/plugwise_usb/nodes/circle.py b/plugwise_usb/nodes/circle.py index dabb3051f..a7b9092a6 100644 --- a/plugwise_usb/nodes/circle.py +++ b/plugwise_usb/nodes/circle.py @@ -350,12 +350,12 @@ async def energy_update(self) -> EnergyStatistics | None: # noqa: PLR0911 PLR09 # Always request last energy log records at initial startup if not self._last_energy_log_requested: - self._last_energy_log_requested = await self.energy_log_update( + self._last_energy_log_requested, _ = await self.energy_log_update( self._current_log_address ) if self._energy_counters.log_rollover: - # Try updating node_info + # Try updating node_info to collect the updated energy log address if await self.node_info_update() is None: _LOGGER.debug( "async_energy_update | %s | Log rollover | node_info_update failed", @@ -364,7 +364,8 @@ async def energy_update(self) -> EnergyStatistics | None: # noqa: PLR0911 PLR09 return None # Try collecting energy-stats for _current_log_address - if not await self.energy_log_update(self._current_log_address): + result, _ = await self.energy_log_update(self._current_log_address) + if not result: _LOGGER.debug( "async_energy_update | %s | Log rollover | energy_log_update failed", self._mac_in_str, @@ -377,7 +378,8 @@ async def energy_update(self) -> EnergyStatistics | None: # noqa: PLR0911 PLR09 _prev_log_address, _ = calc_log_address( self._current_log_address, 1, -4 ) - if not await self.energy_log_update(_prev_log_address): + result, _ = await self.energy_log_update(_prev_log_address) + if not result: _LOGGER.debug( "async_energy_update | %s | Log rollover | energy_log_update %s failed", self._mac_in_str, @@ -397,7 +399,8 @@ async def energy_update(self) -> EnergyStatistics | None: # noqa: PLR0911 PLR09 return self._energy_counters.energy_statistics if len(missing_addresses) == 1: - if await self.energy_log_update(missing_addresses[0]): + result, _ = await self.energy_log_update(missing_addresses[0]) + if result: await self.power_update() _LOGGER.debug( "async_energy_update for %s | single energy log is missing | %s", @@ -447,7 +450,8 @@ async def _get_initial_energy_logs(self) -> None: log_address = self._current_log_address prev_address_timestamp: datetime | None = None while total_addresses > 0: - if not await self.energy_log_update(log_address): + result, empty_log = await self.energy_log_update(log_address) + if result and empty_log: # Handle case with None-data in all address slots _LOGGER.debug( "Energy None-data collected from log address %s, stopping collection", @@ -526,10 +530,12 @@ async def get_missing_energy_logs(self) -> None: if self._cache_enabled: await self._energy_log_records_save_to_cache() - async def energy_log_update(self, address: int | None) -> bool: + async def energy_log_update(self, address: int | None) -> tuple[bool, bool]: """Request energy log statistics from node. Returns true if successful.""" + empty_log = False + result = False if address is None: - return False + return result, empty_log _LOGGER.debug( "Request of energy log at address %s for node %s", @@ -543,7 +549,7 @@ async def energy_log_update(self, address: int | None) -> bool: str(address), self._mac_in_str, ) - return False + return result, empty_log _LOGGER.debug("EnergyLogs data from %s, address=%s", self._mac_in_str, address) await self._available_update_state(True, response.timestamp) @@ -560,6 +566,7 @@ async def energy_log_update(self, address: int | None) -> bool: ) if log_timestamp is None or log_pulses is None: self._energy_counters.add_empty_log(response.log_address, _slot) + empty_log = True elif await self._energy_log_record_update_state( response.log_address, _slot, @@ -579,15 +586,15 @@ async def energy_log_update(self, address: int | None) -> bool: ) last_energy_timestamp_collected = True + result = True self._energy_counters.update() if energy_record_update: _LOGGER.debug( "Saving energy record update to cache for %s", self._mac_in_str ) await self.save_cache() - return True - return False + return result, empty_log async def _energy_log_records_load_from_cache(self) -> bool: """Load energy_log_record from cache."""