Skip to content

Commit e5841e3

Browse files
committed
Fix list inex bug and bump to v2
1 parent d4f1a2a commit e5841e3

File tree

2 files changed

+6
-46
lines changed

2 files changed

+6
-46
lines changed

custom_components/load_shedding/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@
1515
"@wernerhp"
1616
],
1717
"iot_class": "cloud_polling",
18-
"version": "0.6.0"
18+
"version": "2.0.0"
1919
}

custom_components/load_shedding/sensor.py

Lines changed: 5 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,13 @@
1515
ATTR_MODEL,
1616
ATTR_NAME,
1717
ATTR_VIA_DEVICE,
18-
CONF_API_KEY,
19-
CONF_DESCRIPTION,
2018
CONF_ID,
2119
CONF_NAME,
2220
CONF_SCAN_INTERVAL,
23-
EVENT_HOMEASSISTANT_STARTED,
2421
STATE_OFF,
2522
STATE_ON,
2623
)
27-
from homeassistant.core import CoreState, HomeAssistant, callback
24+
from homeassistant.core import HomeAssistant, callback
2825
from homeassistant.helpers.entity import DeviceInfo, Entity
2926
from homeassistant.helpers.entity_platform import AddEntitiesCallback
3027
from homeassistant.helpers.restore_state import RestoreEntity
@@ -35,9 +32,9 @@
3532
UpdateFailed,
3633
)
3734

38-
from load_shedding import Provider, Stage
35+
from load_shedding import Stage
3936
from load_shedding.libs.sepush import SePush, SePushError
40-
from load_shedding.providers import Area, Province, Stage, to_utc
37+
from load_shedding.providers import Area, Stage, to_utc
4138

4239
from .const import (
4340
API,
@@ -421,7 +418,6 @@ def __init__(self, coordinator: CoordinatorEntity, area: Area) -> None:
421418
)
422419

423420
self.entity_description = description
424-
# self._device_id = "loadshedding.eskom.co.za"
425421
self._device_id = f"{NAME}"
426422
self._state: StateType = None
427423
self._attrs = {}
@@ -469,45 +465,9 @@ def extra_state_attributes(self) -> dict[str, list, Any]:
469465
if not self.data:
470466
return self._attrs
471467

472-
data = self._attrs
473-
474-
data = []
475468
now = datetime.now(timezone.utc)
476-
# stage_schedule = self.data.get(self.area.id, []).get(ATTR_SCHEDULE)
477-
# for stage in stage_schedule:
478-
# for s in stage_schedule[stage]:
479-
# start_time = s[0]
480-
# end_time = s[1]
481-
482-
# if start_time > now + timedelta(days=MAX_FORECAST_DAYS):
483-
# continue
484-
485-
# if end_time < now:
486-
# continue
487-
488-
# data.append(
489-
# {
490-
# ATTR_STAGE: Stage(stage),
491-
# ATTR_START_TIME: start_time,
492-
# ATTR_END_TIME: end_time,
493-
# }
494-
# )
495-
496-
# area_schedule = data
497-
498-
# if area_schedule:
499-
# data = get_sensor_attrs(area_schedule)
500-
# data[ATTR_SCHEDULE] = []
501-
# for s in area_schedule:
502-
# data[ATTR_SCHEDULE].append(
503-
# {
504-
# ATTR_STAGE: s.get(ATTR_STAGE).value,
505-
# ATTR_START_TIME: s.get(ATTR_START_TIME).isoformat(),
506-
# ATTR_END_TIME: s.get(ATTR_END_TIME).isoformat(),
507-
# }
508-
# )
509-
510-
area_forecast = self.data.get(self.area.id, []).get(ATTR_FORECAST)
469+
data = self._attrs
470+
area_forecast = self.data.get(self.area.id, {}).get(ATTR_FORECAST)
511471
if area_forecast:
512472
data = get_sensor_attrs(area_forecast)
513473
data[ATTR_FORECAST] = []

0 commit comments

Comments
 (0)