1 """The radiotherm component."""
3 from __future__
import annotations
5 from collections.abc
import Coroutine
7 from urllib.error
import URLError
9 from radiotherm.validate
import RadiothermTstatError
16 from .const
import DOMAIN
17 from .coordinator
import RadioThermUpdateCoordinator
18 from .data
import async_get_init_data
19 from .util
import async_set_time
21 PLATFORMS: list[Platform] = [Platform.CLIMATE, Platform.SWITCH]
24 async
def _async_call_or_raise_not_ready[_T](
25 coro: Coroutine[Any, Any, _T], host: str
27 """Call a coro or raise ConfigEntryNotReady."""
30 except RadiothermTstatError
as ex:
31 msg = f
"{host} was busy (invalid value returned): {ex}"
33 except TimeoutError
as ex:
34 msg = f
"{host} timed out waiting for a response: {ex}"
36 except (OSError, URLError)
as ex:
37 msg = f
"{host} connection error: {ex}"
42 """Set up Radio Thermostat from a config entry."""
43 host = entry.data[CONF_HOST]
45 init_data = await _async_call_or_raise_not_ready(init_coro, host)
47 await coordinator.async_config_entry_first_refresh()
53 if not coordinator.data.tstat[
"hold"]:
55 await _async_call_or_raise_not_ready(time_coro, host)
57 hass.data.setdefault(DOMAIN, {})[entry.entry_id] = coordinator
58 await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
59 entry.async_on_unload(entry.add_update_listener(_async_update_listener))
65 """Handle options update."""
66 await hass.config_entries.async_reload(entry.entry_id)
70 """Unload a config entry."""
71 if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS):
72 hass.data[DOMAIN].pop(entry.entry_id)
RadioThermInitData async_get_init_data(HomeAssistant hass, str host)
None async_set_time(HomeAssistant hass, CommonThermostat device)
None _async_update_listener(HomeAssistant hass, ConfigEntry entry)
bool async_setup_entry(HomeAssistant hass, ConfigEntry entry)
bool async_unload_entry(HomeAssistant hass, ConfigEntry entry)