From d6342d51cc6070ef5c6c343cba2d56d3df505da0 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Wed, 8 Apr 2026 13:16:21 +0200 Subject: [PATCH] Use runtime_data in radiotherm (#167650) Co-authored-by: Claude Opus 4.6 (1M context) --- .../components/radiotherm/__init__.py | 19 ++++++++----------- .../components/radiotherm/climate.py | 9 +++------ .../components/radiotherm/coordinator.py | 6 ++++-- homeassistant/components/radiotherm/switch.py | 9 +++------ 4 files changed, 18 insertions(+), 25 deletions(-) diff --git a/homeassistant/components/radiotherm/__init__.py b/homeassistant/components/radiotherm/__init__.py index 1c5f7f571a65..54ddda99bc6f 100644 --- a/homeassistant/components/radiotherm/__init__.py +++ b/homeassistant/components/radiotherm/__init__.py @@ -8,13 +8,11 @@ from urllib.error import URLError from radiotherm.validate import RadiothermTstatError -from homeassistant.config_entries import ConfigEntry from homeassistant.const import CONF_HOST, Platform from homeassistant.core import HomeAssistant from homeassistant.exceptions import ConfigEntryNotReady -from .const import DOMAIN -from .coordinator import RadioThermUpdateCoordinator +from .coordinator import RadioThermConfigEntry, RadioThermUpdateCoordinator from .data import async_get_init_data from .util import async_set_time @@ -38,7 +36,7 @@ async def _async_call_or_raise_not_ready[_T]( raise ConfigEntryNotReady(msg) from ex -async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: +async def async_setup_entry(hass: HomeAssistant, entry: RadioThermConfigEntry) -> bool: """Set up Radio Thermostat from a config entry.""" host = entry.data[CONF_HOST] init_coro = async_get_init_data(hass, host) @@ -54,21 +52,20 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: time_coro = async_set_time(hass, init_data.tstat) await _async_call_or_raise_not_ready(time_coro, host) - hass.data.setdefault(DOMAIN, {})[entry.entry_id] = coordinator + entry.runtime_data = coordinator await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS) entry.async_on_unload(entry.add_update_listener(_async_update_listener)) return True -async def _async_update_listener(hass: HomeAssistant, entry: ConfigEntry) -> None: +async def _async_update_listener( + hass: HomeAssistant, entry: RadioThermConfigEntry +) -> None: """Handle options update.""" await hass.config_entries.async_reload(entry.entry_id) -async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: +async def async_unload_entry(hass: HomeAssistant, entry: RadioThermConfigEntry) -> 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) diff --git a/homeassistant/components/radiotherm/climate.py b/homeassistant/components/radiotherm/climate.py index 8ede90f27186..920523c2f437 100644 --- a/homeassistant/components/radiotherm/climate.py +++ b/homeassistant/components/radiotherm/climate.py @@ -17,13 +17,11 @@ from homeassistant.components.climate import ( HVACAction, HVACMode, ) -from homeassistant.config_entries import ConfigEntry from homeassistant.const import ATTR_TEMPERATURE, PRECISION_HALVES, UnitOfTemperature from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback -from . import DOMAIN -from .coordinator import RadioThermUpdateCoordinator +from .coordinator import RadioThermConfigEntry, RadioThermUpdateCoordinator from .entity import RadioThermostatEntity ATTR_FAN_ACTION = "fan_action" @@ -101,12 +99,11 @@ def round_temp(temperature): async def async_setup_entry( hass: HomeAssistant, - entry: ConfigEntry, + entry: RadioThermConfigEntry, async_add_entities: AddConfigEntryEntitiesCallback, ) -> None: """Set up climate for a radiotherm device.""" - coordinator: RadioThermUpdateCoordinator = hass.data[DOMAIN][entry.entry_id] - async_add_entities([RadioThermostat(coordinator)]) + async_add_entities([RadioThermostat(entry.runtime_data)]) class RadioThermostat(RadioThermostatEntity, ClimateEntity): diff --git a/homeassistant/components/radiotherm/coordinator.py b/homeassistant/components/radiotherm/coordinator.py index 7d483426c83e..2ed913bfb035 100644 --- a/homeassistant/components/radiotherm/coordinator.py +++ b/homeassistant/components/radiotherm/coordinator.py @@ -14,6 +14,8 @@ from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, Upda from .data import RadioThermInitData, RadioThermUpdate, async_get_data +type RadioThermConfigEntry = ConfigEntry[RadioThermUpdateCoordinator] + _LOGGER = logging.getLogger(__name__) UPDATE_INTERVAL = timedelta(seconds=15) @@ -22,12 +24,12 @@ UPDATE_INTERVAL = timedelta(seconds=15) class RadioThermUpdateCoordinator(DataUpdateCoordinator[RadioThermUpdate]): """DataUpdateCoordinator to gather data for radio thermostats.""" - config_entry: ConfigEntry + config_entry: RadioThermConfigEntry def __init__( self, hass: HomeAssistant, - config_entry: ConfigEntry, + config_entry: RadioThermConfigEntry, init_data: RadioThermInitData, ) -> None: """Initialize DataUpdateCoordinator.""" diff --git a/homeassistant/components/radiotherm/switch.py b/homeassistant/components/radiotherm/switch.py index 2952e1e58176..eaced4b43861 100644 --- a/homeassistant/components/radiotherm/switch.py +++ b/homeassistant/components/radiotherm/switch.py @@ -5,12 +5,10 @@ from __future__ import annotations from typing import Any from homeassistant.components.switch import SwitchEntity -from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback -from .const import DOMAIN -from .coordinator import RadioThermUpdateCoordinator +from .coordinator import RadioThermConfigEntry, RadioThermUpdateCoordinator from .entity import RadioThermostatEntity PARALLEL_UPDATES = 1 @@ -18,12 +16,11 @@ PARALLEL_UPDATES = 1 async def async_setup_entry( hass: HomeAssistant, - entry: ConfigEntry, + entry: RadioThermConfigEntry, async_add_entities: AddConfigEntryEntitiesCallback, ) -> None: """Set up switches for a radiotherm device.""" - coordinator: RadioThermUpdateCoordinator = hass.data[DOMAIN][entry.entry_id] - async_add_entities([RadioThermHoldSwitch(coordinator)]) + async_add_entities([RadioThermHoldSwitch(entry.runtime_data)]) class RadioThermHoldSwitch(RadioThermostatEntity, SwitchEntity):