Skip to content

Commit

Permalink
Fix coordinator update bug
Browse files Browse the repository at this point in the history
  • Loading branch information
wernerhp committed Nov 12, 2022
1 parent 310b963 commit faccf11
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion custom_components/load_shedding/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
VERSION: Final = "1.1.0"
DEFAULT_SCAN_INTERVAL: Final = 60
AREA_UPDATE_INTERVAL: Final = 86400 # 60sec * 60min * 24h / daily
QUOTA_UPDATE_INTERVAL: Final = 300 # 60sec * 5min
QUOTA_UPDATE_INTERVAL: Final = 1800 # 60sec * 30min
STAGE_UPDATE_INTERVAL: Final = 3600 # 60sec * 60min / hourly

CONF_DEFAULT_SCHEDULE_STAGE: Final = "default_schedule_stage"
Expand Down
8 changes: 4 additions & 4 deletions custom_components/load_shedding/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,14 @@ def __init__(self, coordinator: CoordinatorEntity, idx: str) -> None:
"""Initialize."""
super().__init__(coordinator)
self.idx = idx
self.data = self.coordinator.data.get(self.idx)

self.entity_description = LoadSheddingSensorDescription(
key=f"{DOMAIN} stage",
icon="mdi:lightning-bolt-outline",
name=f"{DOMAIN} stage",
entity_registry_enabled_default=True,
)
self.data = self.coordinator.data.get(self.idx)
self._attr_unique_id = f"{self.coordinator.config_entry.entry_id}_{self.idx}"
self.entity_id = f"{DOMAIN}.{DOMAIN}_stage_{idx}"

Expand Down Expand Up @@ -191,7 +191,7 @@ def extra_state_attributes(self) -> dict[str, list, Any]:
def _handle_coordinator_update(self) -> None:
"""Handle updated data from the coordinator."""
if data := self.coordinator.data:
self.data = data
self.data = data.get(self.idx)
self.async_write_ha_state()


Expand All @@ -205,8 +205,8 @@ class LoadSheddingAreaSensorEntity(
def __init__(self, coordinator: CoordinatorEntity, area: Area) -> None:
"""Initialize."""
super().__init__(coordinator)
self.data = self.coordinator.data.get(area.id)
self.area = area
self.data = self.coordinator.data.get(self.area.id)

self.entity_description = LoadSheddingSensorDescription(
key=f"{DOMAIN} schedule {area.id}",
Expand Down Expand Up @@ -297,7 +297,7 @@ def extra_state_attributes(self) -> dict[str, list, Any]:
def _handle_coordinator_update(self) -> None:
"""Handle updated data from the coordinator."""
if data := self.coordinator.data:
self.data = data
self.data = data.get(self.area.id)
self.async_write_ha_state()


Expand Down

0 comments on commit faccf11

Please sign in to comment.