Store Islamic Prayer Times coordinator in 'entry_id' key (#103405)
This commit is contained in:
parent
70196d5ee0
commit
1b17f6d837
2 changed files with 10 additions and 4 deletions
|
@ -32,7 +32,7 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b
|
||||||
coordinator = IslamicPrayerDataUpdateCoordinator(hass)
|
coordinator = IslamicPrayerDataUpdateCoordinator(hass)
|
||||||
await coordinator.async_config_entry_first_refresh()
|
await coordinator.async_config_entry_first_refresh()
|
||||||
|
|
||||||
hass.data.setdefault(DOMAIN, coordinator)
|
hass.data.setdefault(DOMAIN, {})[config_entry.entry_id] = coordinator
|
||||||
config_entry.async_on_unload(
|
config_entry.async_on_unload(
|
||||||
config_entry.add_update_listener(async_options_updated)
|
config_entry.add_update_listener(async_options_updated)
|
||||||
)
|
)
|
||||||
|
@ -46,15 +46,19 @@ async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry) ->
|
||||||
if unload_ok := await hass.config_entries.async_unload_platforms(
|
if unload_ok := await hass.config_entries.async_unload_platforms(
|
||||||
config_entry, PLATFORMS
|
config_entry, PLATFORMS
|
||||||
):
|
):
|
||||||
coordinator: IslamicPrayerDataUpdateCoordinator = hass.data.pop(DOMAIN)
|
coordinator: IslamicPrayerDataUpdateCoordinator = hass.data[DOMAIN].pop(
|
||||||
|
config_entry.entry_id
|
||||||
|
)
|
||||||
if coordinator.event_unsub:
|
if coordinator.event_unsub:
|
||||||
coordinator.event_unsub()
|
coordinator.event_unsub()
|
||||||
|
if not hass.data[DOMAIN]:
|
||||||
|
del hass.data[DOMAIN]
|
||||||
return unload_ok
|
return unload_ok
|
||||||
|
|
||||||
|
|
||||||
async def async_options_updated(hass: HomeAssistant, entry: ConfigEntry) -> None:
|
async def async_options_updated(hass: HomeAssistant, entry: ConfigEntry) -> None:
|
||||||
"""Triggered by config entry options updates."""
|
"""Triggered by config entry options updates."""
|
||||||
coordinator: IslamicPrayerDataUpdateCoordinator = hass.data[DOMAIN]
|
coordinator: IslamicPrayerDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
|
||||||
if coordinator.event_unsub:
|
if coordinator.event_unsub:
|
||||||
coordinator.event_unsub()
|
coordinator.event_unsub()
|
||||||
await coordinator.async_request_refresh()
|
await coordinator.async_request_refresh()
|
||||||
|
|
|
@ -54,7 +54,9 @@ async def async_setup_entry(
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up the Islamic prayer times sensor platform."""
|
"""Set up the Islamic prayer times sensor platform."""
|
||||||
|
|
||||||
coordinator: IslamicPrayerDataUpdateCoordinator = hass.data[DOMAIN]
|
coordinator: IslamicPrayerDataUpdateCoordinator = hass.data[DOMAIN][
|
||||||
|
config_entry.entry_id
|
||||||
|
]
|
||||||
|
|
||||||
async_add_entities(
|
async_add_entities(
|
||||||
IslamicPrayerTimeSensor(coordinator, description)
|
IslamicPrayerTimeSensor(coordinator, description)
|
||||||
|
|
Loading…
Add table
Reference in a new issue