Use runtime_data in Whirlpool (#132613)

Use runtime_data in whirlpool
This commit is contained in:
mkmer 2024-12-08 09:46:44 -05:00 committed by GitHub
parent a8713af8b8
commit b40d8074c0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 15 additions and 23 deletions

View File

@ -20,8 +20,10 @@ _LOGGER = logging.getLogger(__name__)
PLATFORMS = [Platform.CLIMATE, Platform.SENSOR] PLATFORMS = [Platform.CLIMATE, Platform.SENSOR]
type WhirlpoolConfigEntry = ConfigEntry[WhirlpoolData]
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
async def async_setup_entry(hass: HomeAssistant, entry: WhirlpoolConfigEntry) -> bool:
"""Set up Whirlpool Sixth Sense from a config entry.""" """Set up Whirlpool Sixth Sense from a config entry."""
hass.data.setdefault(DOMAIN, {}) hass.data.setdefault(DOMAIN, {})
@ -47,21 +49,15 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
_LOGGER.error("Cannot fetch appliances") _LOGGER.error("Cannot fetch appliances")
return False return False
hass.data[DOMAIN][entry.entry_id] = WhirlpoolData( entry.runtime_data = WhirlpoolData(appliances_manager, auth, backend_selector)
appliances_manager, auth, backend_selector
)
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: WhirlpoolConfigEntry) -> bool:
"""Unload a config entry.""" """Unload a config entry."""
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS) return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
if unload_ok:
hass.data[DOMAIN].pop(entry.entry_id)
return unload_ok
@dataclass @dataclass

View File

@ -23,7 +23,6 @@ from homeassistant.components.climate import (
ClimateEntityFeature, ClimateEntityFeature,
HVACMode, HVACMode,
) )
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ATTR_TEMPERATURE, UnitOfTemperature from homeassistant.const import ATTR_TEMPERATURE, UnitOfTemperature
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers.aiohttp_client import async_get_clientsession from homeassistant.helpers.aiohttp_client import async_get_clientsession
@ -31,7 +30,7 @@ from homeassistant.helpers.device_registry import DeviceInfo
from homeassistant.helpers.entity import generate_entity_id from homeassistant.helpers.entity import generate_entity_id
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
from . import WhirlpoolData from . import WhirlpoolConfigEntry
from .const import DOMAIN from .const import DOMAIN
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -70,11 +69,11 @@ SUPPORTED_TARGET_TEMPERATURE_STEP = 1
async def async_setup_entry( async def async_setup_entry(
hass: HomeAssistant, hass: HomeAssistant,
config_entry: ConfigEntry, config_entry: WhirlpoolConfigEntry,
async_add_entities: AddEntitiesCallback, async_add_entities: AddEntitiesCallback,
) -> None: ) -> None:
"""Set up entry.""" """Set up entry."""
whirlpool_data: WhirlpoolData = hass.data[DOMAIN][config_entry.entry_id] whirlpool_data = config_entry.runtime_data
aircons = [ aircons = [
AirConEntity( AirConEntity(

View File

@ -5,11 +5,9 @@ from __future__ import annotations
from typing import Any from typing import Any
from homeassistant.components.diagnostics import async_redact_data from homeassistant.components.diagnostics import async_redact_data
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from . import WhirlpoolData from . import WhirlpoolConfigEntry
from .const import DOMAIN
TO_REDACT = { TO_REDACT = {
"SERIAL_NUMBER", "SERIAL_NUMBER",
@ -24,11 +22,11 @@ TO_REDACT = {
async def async_get_config_entry_diagnostics( async def async_get_config_entry_diagnostics(
hass: HomeAssistant, hass: HomeAssistant,
config_entry: ConfigEntry, config_entry: WhirlpoolConfigEntry,
) -> dict[str, Any]: ) -> dict[str, Any]:
"""Return diagnostics for a config entry.""" """Return diagnostics for a config entry."""
whirlpool: WhirlpoolData = hass.data[DOMAIN][config_entry.entry_id] whirlpool = config_entry.runtime_data
diagnostics_data = { diagnostics_data = {
"Washer_dryers": { "Washer_dryers": {
wd["NAME"]: dict(wd.items()) wd["NAME"]: dict(wd.items())

View File

@ -15,7 +15,6 @@ from homeassistant.components.sensor import (
SensorEntity, SensorEntity,
SensorEntityDescription, SensorEntityDescription,
) )
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant, callback from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.aiohttp_client import async_get_clientsession from homeassistant.helpers.aiohttp_client import async_get_clientsession
from homeassistant.helpers.device_registry import DeviceInfo from homeassistant.helpers.device_registry import DeviceInfo
@ -23,7 +22,7 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import StateType from homeassistant.helpers.typing import StateType
from homeassistant.util.dt import utcnow from homeassistant.util.dt import utcnow
from . import WhirlpoolData from . import WhirlpoolConfigEntry
from .const import DOMAIN from .const import DOMAIN
TANK_FILL = { TANK_FILL = {
@ -132,12 +131,12 @@ SENSOR_TIMER: tuple[SensorEntityDescription] = (
async def async_setup_entry( async def async_setup_entry(
hass: HomeAssistant, hass: HomeAssistant,
config_entry: ConfigEntry, config_entry: WhirlpoolConfigEntry,
async_add_entities: AddEntitiesCallback, async_add_entities: AddEntitiesCallback,
) -> None: ) -> None:
"""Config flow entry for Whrilpool Laundry.""" """Config flow entry for Whrilpool Laundry."""
entities: list = [] entities: list = []
whirlpool_data: WhirlpoolData = hass.data[DOMAIN][config_entry.entry_id] whirlpool_data = config_entry.runtime_data
for appliance in whirlpool_data.appliances_manager.washer_dryers: for appliance in whirlpool_data.appliances_manager.washer_dryers:
_wd = WasherDryer( _wd = WasherDryer(
whirlpool_data.backend_selector, whirlpool_data.backend_selector,