From b40d8074c065f0b2e12b58cd3d11db9373bc11b9 Mon Sep 17 00:00:00 2001 From: mkmer Date: Sun, 8 Dec 2024 09:46:44 -0500 Subject: [PATCH] Use runtime_data in Whirlpool (#132613) Use runtime_data in whirlpool --- homeassistant/components/whirlpool/__init__.py | 16 ++++++---------- homeassistant/components/whirlpool/climate.py | 7 +++---- .../components/whirlpool/diagnostics.py | 8 +++----- homeassistant/components/whirlpool/sensor.py | 7 +++---- 4 files changed, 15 insertions(+), 23 deletions(-) diff --git a/homeassistant/components/whirlpool/__init__.py b/homeassistant/components/whirlpool/__init__.py index 36f8fbec59d..64adcda4742 100644 --- a/homeassistant/components/whirlpool/__init__.py +++ b/homeassistant/components/whirlpool/__init__.py @@ -20,8 +20,10 @@ _LOGGER = logging.getLogger(__name__) 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.""" hass.data.setdefault(DOMAIN, {}) @@ -47,21 +49,15 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: _LOGGER.error("Cannot fetch appliances") return False - hass.data[DOMAIN][entry.entry_id] = WhirlpoolData( - appliances_manager, auth, backend_selector - ) + entry.runtime_data = WhirlpoolData(appliances_manager, auth, backend_selector) 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: WhirlpoolConfigEntry) -> bool: """Unload a config entry.""" - unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS) - if unload_ok: - hass.data[DOMAIN].pop(entry.entry_id) - - return unload_ok + return await hass.config_entries.async_unload_platforms(entry, PLATFORMS) @dataclass diff --git a/homeassistant/components/whirlpool/climate.py b/homeassistant/components/whirlpool/climate.py index e1cedd38c04..943c5d1c956 100644 --- a/homeassistant/components/whirlpool/climate.py +++ b/homeassistant/components/whirlpool/climate.py @@ -23,7 +23,6 @@ from homeassistant.components.climate import ( ClimateEntityFeature, HVACMode, ) -from homeassistant.config_entries import ConfigEntry from homeassistant.const import ATTR_TEMPERATURE, UnitOfTemperature from homeassistant.core import HomeAssistant 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_platform import AddEntitiesCallback -from . import WhirlpoolData +from . import WhirlpoolConfigEntry from .const import DOMAIN _LOGGER = logging.getLogger(__name__) @@ -70,11 +69,11 @@ SUPPORTED_TARGET_TEMPERATURE_STEP = 1 async def async_setup_entry( hass: HomeAssistant, - config_entry: ConfigEntry, + config_entry: WhirlpoolConfigEntry, async_add_entities: AddEntitiesCallback, ) -> None: """Set up entry.""" - whirlpool_data: WhirlpoolData = hass.data[DOMAIN][config_entry.entry_id] + whirlpool_data = config_entry.runtime_data aircons = [ AirConEntity( diff --git a/homeassistant/components/whirlpool/diagnostics.py b/homeassistant/components/whirlpool/diagnostics.py index 9b1dd00e7bd..87d6ea827e2 100644 --- a/homeassistant/components/whirlpool/diagnostics.py +++ b/homeassistant/components/whirlpool/diagnostics.py @@ -5,11 +5,9 @@ from __future__ import annotations from typing import Any from homeassistant.components.diagnostics import async_redact_data -from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant -from . import WhirlpoolData -from .const import DOMAIN +from . import WhirlpoolConfigEntry TO_REDACT = { "SERIAL_NUMBER", @@ -24,11 +22,11 @@ TO_REDACT = { async def async_get_config_entry_diagnostics( hass: HomeAssistant, - config_entry: ConfigEntry, + config_entry: WhirlpoolConfigEntry, ) -> dict[str, Any]: """Return diagnostics for a config entry.""" - whirlpool: WhirlpoolData = hass.data[DOMAIN][config_entry.entry_id] + whirlpool = config_entry.runtime_data diagnostics_data = { "Washer_dryers": { wd["NAME"]: dict(wd.items()) diff --git a/homeassistant/components/whirlpool/sensor.py b/homeassistant/components/whirlpool/sensor.py index 8c74f01298e..b84518cedf1 100644 --- a/homeassistant/components/whirlpool/sensor.py +++ b/homeassistant/components/whirlpool/sensor.py @@ -15,7 +15,6 @@ from homeassistant.components.sensor import ( SensorEntity, SensorEntityDescription, ) -from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.aiohttp_client import async_get_clientsession 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.util.dt import utcnow -from . import WhirlpoolData +from . import WhirlpoolConfigEntry from .const import DOMAIN TANK_FILL = { @@ -132,12 +131,12 @@ SENSOR_TIMER: tuple[SensorEntityDescription] = ( async def async_setup_entry( hass: HomeAssistant, - config_entry: ConfigEntry, + config_entry: WhirlpoolConfigEntry, async_add_entities: AddEntitiesCallback, ) -> None: """Config flow entry for Whrilpool Laundry.""" 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: _wd = WasherDryer( whirlpool_data.backend_selector,