mirror of
https://github.com/home-assistant/core.git
synced 2025-07-28 15:47:12 +00:00
Suez_water: store coordinator in runtime_data (#133204)
* Suez_water: store coordinator in runtime_data * jhfg
This commit is contained in:
parent
229a68dc73
commit
1b2cf68e82
@ -2,32 +2,27 @@
|
|||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
from homeassistant.const import Platform
|
from homeassistant.const import Platform
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
from .const import DOMAIN
|
from .coordinator import SuezWaterConfigEntry, SuezWaterCoordinator
|
||||||
from .coordinator import SuezWaterCoordinator
|
|
||||||
|
|
||||||
PLATFORMS: list[Platform] = [Platform.SENSOR]
|
PLATFORMS: list[Platform] = [Platform.SENSOR]
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
async def async_setup_entry(hass: HomeAssistant, entry: SuezWaterConfigEntry) -> bool:
|
||||||
"""Set up Suez Water from a config entry."""
|
"""Set up Suez Water from a config entry."""
|
||||||
|
|
||||||
coordinator = SuezWaterCoordinator(hass, entry)
|
coordinator = SuezWaterCoordinator(hass, entry)
|
||||||
await coordinator.async_config_entry_first_refresh()
|
await coordinator.async_config_entry_first_refresh()
|
||||||
|
|
||||||
hass.data.setdefault(DOMAIN, {})[entry.entry_id] = coordinator
|
entry.runtime_data = coordinator
|
||||||
|
|
||||||
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
async def async_unload_entry(hass: HomeAssistant, entry: SuezWaterConfigEntry) -> bool:
|
||||||
"""Unload a config entry."""
|
"""Unload a config entry."""
|
||||||
if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS):
|
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||||
hass.data[DOMAIN].pop(entry.entry_id)
|
|
||||||
|
|
||||||
return unload_ok
|
|
||||||
|
@ -37,13 +37,16 @@ class SuezWaterData:
|
|||||||
price: float
|
price: float
|
||||||
|
|
||||||
|
|
||||||
|
type SuezWaterConfigEntry = ConfigEntry[SuezWaterCoordinator]
|
||||||
|
|
||||||
|
|
||||||
class SuezWaterCoordinator(DataUpdateCoordinator[SuezWaterData]):
|
class SuezWaterCoordinator(DataUpdateCoordinator[SuezWaterData]):
|
||||||
"""Suez water coordinator."""
|
"""Suez water coordinator."""
|
||||||
|
|
||||||
_suez_client: SuezClient
|
_suez_client: SuezClient
|
||||||
config_entry: ConfigEntry
|
config_entry: SuezWaterConfigEntry
|
||||||
|
|
||||||
def __init__(self, hass: HomeAssistant, config_entry: ConfigEntry) -> None:
|
def __init__(self, hass: HomeAssistant, config_entry: SuezWaterConfigEntry) -> None:
|
||||||
"""Initialize suez water coordinator."""
|
"""Initialize suez water coordinator."""
|
||||||
super().__init__(
|
super().__init__(
|
||||||
hass,
|
hass,
|
||||||
|
@ -4,9 +4,7 @@ rules:
|
|||||||
test-before-configure: done
|
test-before-configure: done
|
||||||
unique-config-entry: done
|
unique-config-entry: done
|
||||||
config-flow-test-coverage: done
|
config-flow-test-coverage: done
|
||||||
runtime-data:
|
runtime-data: done
|
||||||
status: todo
|
|
||||||
comment: coordinator is created during setup, should be stored in runtime_data
|
|
||||||
test-before-setup: done
|
test-before-setup: done
|
||||||
appropriate-polling: done
|
appropriate-polling: done
|
||||||
entity-unique-id: done
|
entity-unique-id: done
|
||||||
|
@ -13,7 +13,6 @@ from homeassistant.components.sensor import (
|
|||||||
SensorEntity,
|
SensorEntity,
|
||||||
SensorEntityDescription,
|
SensorEntityDescription,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
from homeassistant.const import CURRENCY_EURO, UnitOfVolume
|
from homeassistant.const import CURRENCY_EURO, UnitOfVolume
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.device_registry import DeviceEntryType, DeviceInfo
|
from homeassistant.helpers.device_registry import DeviceEntryType, DeviceInfo
|
||||||
@ -21,7 +20,7 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
|||||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||||
|
|
||||||
from .const import CONF_COUNTER_ID, DOMAIN
|
from .const import CONF_COUNTER_ID, DOMAIN
|
||||||
from .coordinator import SuezWaterCoordinator, SuezWaterData
|
from .coordinator import SuezWaterConfigEntry, SuezWaterCoordinator, SuezWaterData
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True, kw_only=True)
|
@dataclass(frozen=True, kw_only=True)
|
||||||
@ -53,11 +52,11 @@ SENSORS: tuple[SuezWaterSensorEntityDescription, ...] = (
|
|||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
entry: ConfigEntry,
|
entry: SuezWaterConfigEntry,
|
||||||
async_add_entities: AddEntitiesCallback,
|
async_add_entities: AddEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up Suez Water sensor from a config entry."""
|
"""Set up Suez Water sensor from a config entry."""
|
||||||
coordinator = hass.data[DOMAIN][entry.entry_id]
|
coordinator = entry.runtime_data
|
||||||
counter_id = entry.data[CONF_COUNTER_ID]
|
counter_id = entry.data[CONF_COUNTER_ID]
|
||||||
|
|
||||||
async_add_entities(
|
async_add_entities(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user