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]
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

View File

@ -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(

View File

@ -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())

View File

@ -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,