Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 9 additions & 14 deletions plugwise_usb/nodes/circle.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ async def energy_update(self) -> EnergyStatistics | None: # noqa: PLR0911 PLR09

# Try collecting energy-stats for _current_log_address
result = await self.energy_log_update(
self._current_log_address, save_cache=True
self._current_log_address, save_cache=False
)
if not result:
_LOGGER.debug(
Expand All @@ -432,7 +432,7 @@ async def energy_update(self) -> EnergyStatistics | None: # noqa: PLR0911 PLR09
# Retry with previous log address as Circle node pointer to self._current_log_address
# could be rolled over while the last log is at previous address/slot
prev_log_address, _ = calc_log_address(self._current_log_address, 1, -4)
result = await self.energy_log_update(prev_log_address, save_cache=True)
result = await self.energy_log_update(prev_log_address, save_cache=False)
if not result:
_LOGGER.debug(
"async_energy_update | %s | Log rollover | energy_log_update from address %s failed",
Expand All @@ -441,6 +441,9 @@ async def energy_update(self) -> EnergyStatistics | None: # noqa: PLR0911 PLR09
)
return None

if self._cache_enabled:
await self.save_cache()

Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
if (
missing_addresses := self._energy_counters.log_addresses_missing
) is not None:
Expand Down Expand Up @@ -530,7 +533,7 @@ async def _get_initial_energy_logs(self) -> None:
total_addresses -= 1

if self._cache_enabled:
await self._energy_log_records_save_to_cache()
await self.save_cache()

Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
async def get_missing_energy_logs(self) -> None:
"""Task to retrieve missing energy logs."""
Expand Down Expand Up @@ -566,7 +569,7 @@ async def get_missing_energy_logs(self) -> None:
break

if self._cache_enabled:
await self._energy_log_records_save_to_cache()
await self.save_cache()

Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
async def energy_log_update(
self, address: int | None, save_cache: bool = True
Expand Down Expand Up @@ -713,8 +716,6 @@ async def _energy_log_records_save_to_cache(self) -> None:
cached_logs = "|".join(records)
_LOGGER.debug("Saving energy logrecords to cache for %s", self._mac_in_str)
self._set_cache(CACHE_ENERGY_COLLECTION, cached_logs)
# Persist new cache entries to disk immediately
await self.save_cache(trigger_only=True)

async def _energy_log_record_update_state(
self,
Expand Down Expand Up @@ -743,13 +744,7 @@ async def _energy_log_record_update_state(
str(slot),
self._mac_in_str,
)
new_cache = (
f"{log_cache_record}|{cached_logs}"
if cached_logs
else log_cache_record
)
self._set_cache(CACHE_ENERGY_COLLECTION, new_cache)
await self.save_cache(trigger_only=True)
await self._energy_log_records_save_to_cache()
return True

_LOGGER.debug(
Expand All @@ -763,7 +758,7 @@ async def _energy_log_record_update_state(
str(slot),
self._mac_in_str,
)
self._set_cache(CACHE_ENERGY_COLLECTION, log_cache_record)
await self._energy_log_records_save_to_cache()
return True

@raise_not_loaded
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "plugwise_usb"
version = "0.44.13"
version = "0.44.14a1"
license = "MIT"
keywords = ["home", "automation", "plugwise", "module", "usb"]
classifiers = [
Expand Down