Skip to content

Commit

Permalink
Adding more details to scheduled challenges
Browse files Browse the repository at this point in the history
  • Loading branch information
valleedelisle committed Jan 3, 2022
1 parent b705ec6 commit af25dfd
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions custom_components/hilo/sensor.py
Expand Up @@ -440,6 +440,14 @@ async def _async_update(self):
for idx, season in enumerate(seasons):
if idx == 0:
self._state = season.get("totalReward", 0)
events = []
for event in season.get("events", []):
events.append(
await self._hilo._api.get_events(
self._hilo.devices.location_id, event_id=event["id"]
)
)
season["events"] = events
self._history.append(season)


Expand Down Expand Up @@ -503,6 +511,19 @@ async def _async_update(self):
event = event_parsing(raw_event)
if not event:
continue
details = await self._hilo._api.get_events(
self._hilo.devices.location_id, event_id=event["event_id"]
)
params = details.get("parameters", {})
devices = params.get("devices", [])
event["total_devices"] = len(devices)
event["opt_out_devices"] = len([x for x in devices if x["optOut"]])
event["pre_heat_devices"] = len([x for x in devices if x["preheat"]])
event["mode"] = details.get("parameters", {}).get("mode", "Unknown")
baseline = details.get("consumption", {}).get("baselineWh", 0) or 0
event["allowed_Wh"] = baseline
event["allowed_kWh"] = round(baseline / 1000, 2)
del event["event_id"]
self._next_events.append(event)
self._state = "off"
if len(self._next_events):
Expand Down

0 comments on commit af25dfd

Please sign in to comment.