1 """Switch platform for Sensibo integration."""
3 from __future__
import annotations
5 from collections.abc
import Callable, Mapping
6 from dataclasses
import dataclass
9 from pysensibo.model
import SensiboDevice
14 SwitchEntityDescription,
20 from .
import SensiboConfigEntry
21 from .const
import DOMAIN
22 from .coordinator
import SensiboDataUpdateCoordinator
23 from .entity
import SensiboDeviceBaseEntity, async_handle_api_call
28 @dataclass(frozen=True, kw_only=True)
30 """Describes Sensibo Switch entity."""
32 value_fn: Callable[[SensiboDevice], bool |
None]
33 extra_fn: Callable[[SensiboDevice], dict[str, str | bool |
None]] |
None
39 DEVICE_SWITCH_TYPES: tuple[SensiboDeviceSwitchEntityDescription, ...] = (
41 key=
"timer_on_switch",
42 translation_key=
"timer_on_switch",
43 device_class=SwitchDeviceClass.SWITCH,
44 value_fn=
lambda data: data.timer_on,
45 extra_fn=
lambda data: {
"id": data.timer_id,
"turn_on": data.timer_state_on},
46 command_on=
"async_turn_on_timer",
47 command_off=
"async_turn_off_timer",
51 key=
"climate_react_switch",
52 translation_key=
"climate_react_switch",
53 device_class=SwitchDeviceClass.SWITCH,
54 value_fn=
lambda data: data.smart_on,
55 extra_fn=
lambda data: {
"type": data.smart_type},
56 command_on=
"async_turn_on_off_smart",
57 command_off=
"async_turn_on_off_smart",
62 PURE_SWITCH_TYPES: tuple[SensiboDeviceSwitchEntityDescription, ...] = (
64 key=
"pure_boost_switch",
65 translation_key=
"pure_boost_switch",
66 device_class=SwitchDeviceClass.SWITCH,
67 value_fn=
lambda data: data.pure_boost_enabled,
69 command_on=
"async_turn_on_off_pure_boost",
70 command_off=
"async_turn_on_off_pure_boost",
71 data_key=
"pure_boost_enabled",
75 DESCRIPTION_BY_MODELS = {
"pure": PURE_SWITCH_TYPES}
80 entry: SensiboConfigEntry,
81 async_add_entities: AddEntitiesCallback,
83 """Set up Sensibo Switch platform."""
85 coordinator = entry.runtime_data
89 for device_id, device_data
in coordinator.data.parsed.items()
90 for description
in DESCRIPTION_BY_MODELS.get(
91 device_data.model, DEVICE_SWITCH_TYPES
97 """Representation of a Sensibo Device Switch."""
99 entity_description: SensiboDeviceSwitchEntityDescription
103 coordinator: SensiboDataUpdateCoordinator,
105 entity_description: SensiboDeviceSwitchEntityDescription,
107 """Initiate Sensibo Device Switch."""
117 """Return True if entity is on."""
121 """Turn the entity on."""
122 func = getattr(SensiboDeviceSwitch, self.
entity_descriptionentity_description.command_on)
130 """Turn the entity off."""
131 func = getattr(SensiboDeviceSwitch, self.
entity_descriptionentity_description.command_off)
140 """Return additional attributes."""
145 @async_handle_api_call
147 """Make service call to api for setting timer."""
148 new_state =
not self.
device_datadevice_data.device_on
150 "minutesFromNow": 60,
151 "acState": {**self.
device_datadevice_data.ac_states,
"on": new_state},
153 result = await self.
_client_client.async_set_timer(self.
_device_id_device_id, data)
154 return bool(result.get(
"status") ==
"success")
156 @async_handle_api_call
158 """Make service call to api for deleting timer."""
160 return bool(result.get(
"status") ==
"success")
162 @async_handle_api_call
164 """Make service call to api for setting Pure Boost."""
165 data: dict[str, Any] = {
"enabled": value}
166 if self.
device_datadevice_data.pure_measure_integration
is None:
167 data[
"sensitivity"] =
"N"
168 data[
"measurementsIntegration"] =
True
169 data[
"acIntegration"] =
False
170 data[
"geoIntegration"] =
False
171 data[
"primeIntegration"] =
False
172 result = await self.
_client_client.async_set_pureboost(self.
_device_id_device_id, data)
173 return bool(result.get(
"status") ==
"success")
175 @async_handle_api_call
177 """Make service call to api for setting Climate React."""
180 translation_domain=DOMAIN,
181 translation_key=
"climate_react_not_available",
183 data: dict[str, Any] = {
"enabled": value}
184 result = await self.
_client_client.async_enable_climate_react(self.
_device_id_device_id, data)
185 return bool(result.get(
"status") ==
"success")
SensiboDevice device_data(self)
Mapping[str, Any]|None extra_state_attributes(self)
bool async_turn_on_off_pure_boost(self, str key, bool value)
bool async_turn_on_timer(self, str key, bool value)
None async_turn_off(self, **Any kwargs)
bool async_turn_on_off_smart(self, str key, bool value)
None __init__(self, SensiboDataUpdateCoordinator coordinator, str device_id, SensiboDeviceSwitchEntityDescription entity_description)
None async_turn_on(self, **Any kwargs)
bool async_turn_off_timer(self, str key, bool value)
None async_setup_entry(HomeAssistant hass, SensiboConfigEntry entry, AddEntitiesCallback async_add_entities)