1 """Support for Toon switches."""
3 from __future__
import annotations
5 from dataclasses
import dataclass
20 from .const
import DOMAIN
21 from .coordinator
import ToonDataUpdateCoordinator
22 from .entity
import ToonDisplayDeviceEntity, ToonEntity, ToonRequiredKeysMixin
23 from .helpers
import toon_exception_handler
27 hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
29 """Set up a Toon switches based on a config entry."""
30 coordinator = hass.data[DOMAIN][entry.entry_id]
33 [description.cls(coordinator, description)
for description
in SWITCH_ENTITIES]
38 """Defines an Toon switch."""
40 entity_description: ToonSwitchEntityDescription
44 coordinator: ToonDataUpdateCoordinator,
45 description: ToonSwitchEntityDescription,
47 """Initialize the Toon switch."""
52 f
"{coordinator.data.agreement.agreement_id}_{description.key}"
57 """Return the status of the binary sensor."""
58 section = getattr(self.coordinator.data, self.
entity_descriptionentity_description.section)
63 """Defines a Toon program switch."""
65 @toon_exception_handler
67 """Turn off the Toon program switch."""
68 await self.coordinator.toon.set_active_state(
69 ACTIVE_STATE_AWAY, PROGRAM_STATE_OFF
72 @toon_exception_handler
74 """Turn on the Toon program switch."""
75 await self.coordinator.toon.set_active_state(
76 ACTIVE_STATE_AWAY, PROGRAM_STATE_ON
81 """Defines a Toon Holiday mode switch."""
83 @toon_exception_handler
85 """Turn off the Toon holiday mode switch."""
86 await self.coordinator.toon.set_active_state(
87 ACTIVE_STATE_AWAY, PROGRAM_STATE_ON
90 @toon_exception_handler
92 """Turn on the Toon holiday mode switch."""
93 await self.coordinator.toon.set_active_state(
94 ACTIVE_STATE_HOLIDAY, PROGRAM_STATE_OFF
98 @dataclass(frozen=True)
100 """Mixin for switch required keys."""
102 cls: type[ToonSwitch]
105 @dataclass(frozen=True)
107 """Describes Toon switch entity."""
110 SWITCH_ENTITIES: tuple[ToonSwitchEntityDescription, ...] = (
111 ToonSwitchEntityDescription(
112 key=
"thermostat_holiday_mode",
114 section=
"thermostat",
115 measurement=
"holiday_mode",
117 cls=ToonHolidayModeSwitch,
119 ToonSwitchEntityDescription(
120 key=
"thermostat_program",
121 name=
"Thermostat Program",
122 section=
"thermostat",
123 measurement=
"program",
124 icon=
"mdi:calendar-clock",
125 cls=ToonProgramSwitch,
None async_turn_on(self, **Any kwargs)
None async_turn_off(self, **Any kwargs)
None async_turn_on(self, **Any kwargs)
None async_turn_off(self, **Any kwargs)
None __init__(self, ToonDataUpdateCoordinator coordinator, ToonSwitchEntityDescription description)
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)