1 """Support for switch entities."""
3 from __future__
import annotations
5 from dataclasses
import dataclass
9 from thinqconnect
import DeviceType
10 from thinqconnect.devices.const
import Property
as ThinQProperty
11 from thinqconnect.integration
import ActiveMode
16 SwitchEntityDescription,
22 from .
import ThinqConfigEntry
23 from .entity
import ThinQEntity
26 @dataclass(frozen=True, kw_only=True)
28 """Describes ThinQ switch entity."""
30 on_key: str |
None =
None
31 off_key: str |
None =
None
34 DEVICE_TYPE_SWITCH_MAP: dict[DeviceType, tuple[ThinQSwitchEntityDescription, ...]] = {
35 DeviceType.AIR_CONDITIONER: (
37 key=ThinQProperty.POWER_SAVE_ENABLED,
38 translation_key=ThinQProperty.POWER_SAVE_ENABLED,
41 entity_category=EntityCategory.CONFIG,
44 DeviceType.AIR_PURIFIER_FAN: (
46 key=ThinQProperty.AIR_FAN_OPERATION_MODE, translation_key=
"operation_power"
49 key=ThinQProperty.UV_NANO,
50 translation_key=ThinQProperty.UV_NANO,
53 entity_category=EntityCategory.CONFIG,
56 key=ThinQProperty.WARM_MODE,
57 translation_key=ThinQProperty.WARM_MODE,
60 entity_category=EntityCategory.CONFIG,
63 DeviceType.AIR_PURIFIER: (
65 key=ThinQProperty.AIR_PURIFIER_OPERATION_MODE,
66 translation_key=
"operation_power",
69 DeviceType.DEHUMIDIFIER: (
71 key=ThinQProperty.DEHUMIDIFIER_OPERATION_MODE,
72 translation_key=
"operation_power",
75 DeviceType.HUMIDIFIER: (
77 key=ThinQProperty.HUMIDIFIER_OPERATION_MODE,
78 translation_key=
"operation_power",
81 key=ThinQProperty.WARM_MODE,
82 translation_key=
"humidity_warm_mode",
85 entity_category=EntityCategory.CONFIG,
88 key=ThinQProperty.MOOD_LAMP_STATE,
89 translation_key=ThinQProperty.MOOD_LAMP_STATE,
92 entity_category=EntityCategory.CONFIG,
95 key=ThinQProperty.AUTO_MODE,
96 translation_key=ThinQProperty.AUTO_MODE,
99 entity_category=EntityCategory.CONFIG,
102 key=ThinQProperty.SLEEP_MODE,
103 translation_key=ThinQProperty.SLEEP_MODE,
106 entity_category=EntityCategory.CONFIG,
109 DeviceType.REFRIGERATOR: (
111 key=ThinQProperty.EXPRESS_MODE,
112 translation_key=ThinQProperty.EXPRESS_MODE,
115 entity_category=EntityCategory.CONFIG,
118 key=ThinQProperty.RAPID_FREEZE,
119 translation_key=ThinQProperty.RAPID_FREEZE,
122 entity_category=EntityCategory.CONFIG,
125 DeviceType.SYSTEM_BOILER: (
127 key=ThinQProperty.HOT_WATER_MODE,
128 translation_key=ThinQProperty.HOT_WATER_MODE,
131 entity_category=EntityCategory.CONFIG,
134 DeviceType.WINE_CELLAR: (
136 key=ThinQProperty.OPTIMAL_HUMIDITY,
137 translation_key=ThinQProperty.OPTIMAL_HUMIDITY,
140 entity_category=EntityCategory.CONFIG,
145 _LOGGER = logging.getLogger(__name__)
150 entry: ThinqConfigEntry,
151 async_add_entities: AddEntitiesCallback,
153 """Set up an entry for switch platform."""
154 entities: list[ThinQSwitchEntity] = []
155 for coordinator
in entry.runtime_data.coordinators.values():
157 descriptions := DEVICE_TYPE_SWITCH_MAP.get(
158 coordinator.api.device.device_type
161 for description
in descriptions:
164 for property_id
in coordinator.api.get_active_idx(
165 description.key, ActiveMode.READ_WRITE
174 """Represent a thinq switch platform."""
176 entity_description: ThinQSwitchEntityDescription
177 _attr_device_class = SwitchDeviceClass.SWITCH
180 """Update status itself."""
189 "[%s:%s] update status: %s -> %s",
190 self.coordinator.device_name,
197 """Turn on the switch."""
199 "[%s:%s] async_turn_on id: %s",
200 self.coordinator.device_name,
206 self.coordinator.api.post(self.
property_idproperty_id, on_command)
210 self.coordinator.api.async_turn_on(self.
property_idproperty_id)
214 """Turn off the switch."""
216 "[%s:%s] async_turn_off id: %s",
217 self.coordinator.device_name,
223 self.coordinator.api.post(self.
property_idproperty_id, off_command)
227 self.coordinator.api.async_turn_off(self.
property_idproperty_id)
None async_call_api(self, Coroutine[Any, Any, Any] target, Callable[[], None]|None on_fail_method=None)
None _update_status(self)
None async_turn_on(self, **Any kwargs)
None async_turn_off(self, **Any kwargs)
str|UndefinedType|None name(self)
None async_setup_entry(HomeAssistant hass, ThinqConfigEntry entry, AddEntitiesCallback async_add_entities)