Skip to content

Commit

Permalink
support multiple installations properly
Browse files Browse the repository at this point in the history
fixes #15
  • Loading branch information
dreautall committed Mar 16, 2024
1 parent 30cfaa7 commit 9ab801c
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion custom_components/stromnetzgraz/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ async def async_setup_entry(

conn = hass.data[DOMAIN]

coordinator: SNGrazDataCoordinator | None = None
entities: list[SNGrazSensor] = []

base_readings = entry.data.get(CONF_BASE)
Expand All @@ -91,7 +90,11 @@ async def async_setup_entry(
raise PlatformNotReady() from err

for installation in conn.get_installations():
_LOGGER.debug(f"Got installation {installation._installation_id}")
coordinator: SNGrazDataCoordinator | None = None

for meter in installation.get_meters():
_LOGGER.debug(f"Got meter {meter.id}")
if str(meter.id) not in base_readings:
if (base_reading := await meter.get_first_reading()) is None:
_LOGGER.error("could not get first reading")
Expand All @@ -102,8 +105,10 @@ async def async_setup_entry(
hass.config_entries.async_update_entry(entry, data=data)

if coordinator is None:
_LOGGER.debug(f"creating new coordinator")
coordinator = SNGrazDataCoordinator(hass, installation)
for entity_description in SENSORS:
_LOGGER.debug(f"adding entity")
entities.append(
SNGrazSensor(meter, installation, coordinator, entity_description)
)
Expand Down

0 comments on commit 9ab801c

Please sign in to comment.