Skip to content

Commit 8edc1b2

Browse files
authored
fix: Fix Today/Yesterday readings (#228)
1 parent df39429 commit 8edc1b2

File tree

3 files changed

+116
-93
lines changed

3 files changed

+116
-93
lines changed

custom_components/iec/__init__.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,16 @@
1616

1717
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
1818
"""Set up IEC from a config entry."""
19+
if DOMAIN not in hass.data:
20+
hass.data[DOMAIN] = {}
1921

2022
iec_coordinator = IecApiCoordinator(hass, entry)
21-
await iec_coordinator.async_config_entry_first_refresh()
2223
hass.data.setdefault(DOMAIN, {})[entry.entry_id] = iec_coordinator
24+
try:
25+
await hass.data[DOMAIN][entry.entry_id].async_config_entry_first_refresh()
26+
except Exception as err:
27+
# Log the error but don't fail the setup
28+
_LOGGER.error("Failed to fetch initial data: %s", err)
2329

2430
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
2531

@@ -40,6 +46,8 @@ async def handle_debug_get_coordinator_data(call) -> None: # noqa: ANN001 ARG00
4046
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
4147
"""Unload a config entry."""
4248
if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS):
43-
hass.data[DOMAIN].pop(entry.entry_id)
49+
coordinator = hass.data[DOMAIN].pop(entry.entry_id, None)
50+
if coordinator:
51+
await coordinator.async_unload()
4452

4553
return unload_ok

0 commit comments

Comments
 (0)