Skip to content

Commit

Permalink
Suez_water: store coordinator in runtime_data (#133204)
Browse files Browse the repository at this point in the history
* Suez_water: store coordinator in runtime_data

* jhfg
  • Loading branch information
jb101010-2 authored Dec 15, 2024
1 parent 229a68d commit 1b2cf68
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 19 deletions.
15 changes: 5 additions & 10 deletions homeassistant/components/suez_water/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,27 @@

from __future__ import annotations

from homeassistant.config_entries import ConfigEntry
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant

from .const import DOMAIN
from .coordinator import SuezWaterCoordinator
from .coordinator import SuezWaterConfigEntry, SuezWaterCoordinator

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."""

coordinator = SuezWaterCoordinator(hass, entry)
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)

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."""
if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS):
hass.data[DOMAIN].pop(entry.entry_id)

return unload_ok
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
7 changes: 5 additions & 2 deletions homeassistant/components/suez_water/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,16 @@ class SuezWaterData:
price: float


type SuezWaterConfigEntry = ConfigEntry[SuezWaterCoordinator]


class SuezWaterCoordinator(DataUpdateCoordinator[SuezWaterData]):
"""Suez water coordinator."""

_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."""
super().__init__(
hass,
Expand Down
4 changes: 1 addition & 3 deletions homeassistant/components/suez_water/quality_scale.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ rules:
test-before-configure: done
unique-config-entry: done
config-flow-test-coverage: done
runtime-data:
status: todo
comment: coordinator is created during setup, should be stored in runtime_data
runtime-data: done
test-before-setup: done
appropriate-polling: done
entity-unique-id: done
Expand Down
7 changes: 3 additions & 4 deletions homeassistant/components/suez_water/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,14 @@
SensorEntity,
SensorEntityDescription,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CURRENCY_EURO, UnitOfVolume
from homeassistant.core import HomeAssistant
from homeassistant.helpers.device_registry import DeviceEntryType, DeviceInfo
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.update_coordinator import CoordinatorEntity

from .const import CONF_COUNTER_ID, DOMAIN
from .coordinator import SuezWaterCoordinator, SuezWaterData
from .coordinator import SuezWaterConfigEntry, SuezWaterCoordinator, SuezWaterData


@dataclass(frozen=True, kw_only=True)
Expand Down Expand Up @@ -53,11 +52,11 @@ class SuezWaterSensorEntityDescription(SensorEntityDescription):

async def async_setup_entry(
hass: HomeAssistant,
entry: ConfigEntry,
entry: SuezWaterConfigEntry,
async_add_entities: AddEntitiesCallback,
) -> None:
"""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]

async_add_entities(
Expand Down

0 comments on commit 1b2cf68

Please sign in to comment.