mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Starlink's energy consumption & usage cumulation fix (#135889)
* refactor: history_stats result indexing * fix: Energy consumption & Usage cumulation * fix: typo * fix: mypy error: Call to untyped function * refactor: Use generic tuple instead of typing's Tuple * fix: tuple * fix: just syntax test * fix: AttributeError: 'NoneType' object has no attribute 'usage' * refactor: Return type * refactor: Merge into single method * refactor: Complex unpack test
This commit is contained in:
parent
111906f54e
commit
4e29ac8e1b
@ -52,6 +52,7 @@ class StarlinkUpdateCoordinator(DataUpdateCoordinator[StarlinkData]):
|
||||
def __init__(self, hass: HomeAssistant, name: str, url: str) -> None:
|
||||
"""Initialize an UpdateCoordinator for a group of sensors."""
|
||||
self.channel_context = ChannelContext(target=url)
|
||||
self.history_stats_start = None
|
||||
self.timezone = ZoneInfo(hass.config.time_zone)
|
||||
super().__init__(
|
||||
hass,
|
||||
@ -67,7 +68,18 @@ class StarlinkUpdateCoordinator(DataUpdateCoordinator[StarlinkData]):
|
||||
location = location_data(context)
|
||||
sleep = get_sleep_config(context)
|
||||
status, obstruction, alert = status_data(context)
|
||||
usage, consumption = history_stats(parse_samples=-1, context=context)[-2:]
|
||||
index, _, _, _, _, usage, consumption, *_ = history_stats(
|
||||
parse_samples=-1, start=self.history_stats_start, context=context
|
||||
)
|
||||
self.history_stats_start = index["end_counter"]
|
||||
if self.data:
|
||||
if index["samples"] > 0:
|
||||
usage["download_usage"] += self.data.usage["download_usage"]
|
||||
usage["upload_usage"] += self.data.usage["upload_usage"]
|
||||
consumption["total_energy"] += self.data.consumption["total_energy"]
|
||||
else:
|
||||
usage = self.data.usage
|
||||
consumption = self.data.consumption
|
||||
return StarlinkData(
|
||||
location, sleep, status, obstruction, alert, usage, consumption
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user