Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 0 additions & 1 deletion custom_components/dimplex/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"iot_class": "cloud_polling",
"issue_tracker": "https://github.com/kroperuk/dimplex-controller-hass/issues",
"loggers": ["dimplex_controller"],
"quality_scale": "silver",
"requirements": ["dimplex-controller>=0.11.0"],
"version": "2.0.0"
}
30 changes: 23 additions & 7 deletions custom_components/dimplex/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,15 +450,31 @@ def _local_tz(self) -> Any:
return ZoneInfo("UTC")

def _summary(self) -> Any | None:
"""Memoised energy summary — computed once per coordinator update cycle.

The summary is used by available, native_value, last_reset, and
extra_state_attributes. Computing summarise_energy multiple times per
state read is wasted work for accounts with long telemetry histories.
"""
# Use the coordinator's last_updated timestamp as the cache key.
last_updated = getattr(self.coordinator, "last_update_success_time", None)
if last_updated is not None and last_updated == getattr(self, "_summary_ts", None):
return self._summary_cached

points = self._energy_points
if not points:
return None
return summarise_energy(
points,
mode=self.entity_description.mode, # type: ignore[arg-type]
now=dt_util.now(),
tz=self._local_tz(),
)
result = None
else:
result = summarise_energy(
points,
mode=self.entity_description.mode, # type: ignore[arg-type]
now=dt_util.now(),
tz=self._local_tz(),
)

self._summary_cached = result
self._summary_ts = last_updated
return result

@property
def available(self) -> bool:
Expand Down