mirror of
https://github.com/home-assistant/core.git
synced 2026-09-25 07:51:46 -05:00
Use runtime_data in radiotherm (#167650)
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
1eead15c24
commit
d6342d51cc
@@ -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)
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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."""
|
||||
|
||||
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user