1 """Support for deCONZ select entities."""
3 from __future__
import annotations
5 from pydeconz.models.event
import EventType
6 from pydeconz.models.sensor.air_purifier
import AirPurifier, AirPurifierFanMode
7 from pydeconz.models.sensor.presence
import (
9 PresenceConfigDeviceMode,
10 PresenceConfigSensitivity,
11 PresenceConfigTriggerDistance,
20 from .entity
import DeconzDevice
21 from .hub
import DeconzHub
23 SENSITIVITY_TO_DECONZ = {
24 "High": PresenceConfigSensitivity.HIGH.value,
25 "Medium": PresenceConfigSensitivity.MEDIUM.value,
26 "Low": PresenceConfigSensitivity.LOW.value,
28 DECONZ_TO_SENSITIVITY = {value: key
for key, value
in SENSITIVITY_TO_DECONZ.items()}
33 config_entry: ConfigEntry,
34 async_add_entities: AddEntitiesCallback,
36 """Set up the deCONZ button entity."""
37 hub = DeconzHub.get_hub(hass, config_entry)
38 hub.entities[SELECT_DOMAIN] = set()
41 def async_add_air_purifier_sensor(_: EventType, sensor_id: str) ->
None:
42 """Add air purifier select entity from deCONZ."""
43 sensor = hub.api.sensors.air_purifier[sensor_id]
46 hub.register_platform_add_device_callback(
47 async_add_air_purifier_sensor,
48 hub.api.sensors.air_purifier,
52 def async_add_presence_sensor(_: EventType, sensor_id: str) ->
None:
53 """Add presence select entity from deCONZ."""
54 sensor = hub.api.sensors.presence[sensor_id]
55 if sensor.presence_event
is not None:
64 hub.register_platform_add_device_callback(
65 async_add_presence_sensor,
66 hub.api.sensors.presence,
71 """Representation of a deCONZ air purifier fan mode entity."""
73 _name_suffix =
"Fan Mode"
74 unique_id_suffix =
"fan_mode"
77 _attr_entity_category = EntityCategory.CONFIG
79 AirPurifierFanMode.OFF.value,
80 AirPurifierFanMode.AUTO.value,
81 AirPurifierFanMode.SPEED_1.value,
82 AirPurifierFanMode.SPEED_2.value,
83 AirPurifierFanMode.SPEED_3.value,
84 AirPurifierFanMode.SPEED_4.value,
85 AirPurifierFanMode.SPEED_5.value,
92 """Return the selected entity option to represent the entity state."""
93 return self._device.fan_mode.value
96 """Change the selected option."""
97 await self.hub.api.sensors.air_purifier.set_config(
98 id=self._device.resource_id,
99 fan_mode=AirPurifierFanMode(option),
104 """Representation of a deCONZ presence device mode entity."""
106 _name_suffix =
"Device Mode"
107 unique_id_suffix =
"device_mode"
108 _update_key =
"devicemode"
110 _attr_entity_category = EntityCategory.CONFIG
112 PresenceConfigDeviceMode.LEFT_AND_RIGHT.value,
113 PresenceConfigDeviceMode.UNDIRECTED.value,
120 """Return the selected entity option to represent the entity state."""
121 if self._device.device_mode
is not None:
122 return self._device.device_mode.value
126 """Change the selected option."""
127 await self.hub.api.sensors.presence.set_config(
128 id=self._device.resource_id,
129 device_mode=PresenceConfigDeviceMode(option),
134 """Representation of a deCONZ presence sensitivity entity."""
136 _name_suffix =
"Sensitivity"
137 unique_id_suffix =
"sensitivity"
138 _update_key =
"sensitivity"
140 _attr_entity_category = EntityCategory.CONFIG
141 _attr_options =
list(SENSITIVITY_TO_DECONZ)
147 """Return the selected entity option to represent the entity state."""
148 if self._device.sensitivity
is not None:
149 return DECONZ_TO_SENSITIVITY[self._device.sensitivity]
153 """Change the selected option."""
154 await self.hub.api.sensors.presence.set_config(
155 id=self._device.resource_id,
156 sensitivity=SENSITIVITY_TO_DECONZ[option],
161 """Representation of a deCONZ presence trigger distance entity."""
163 _name_suffix =
"Trigger Distance"
164 unique_id_suffix =
"trigger_distance"
165 _update_key =
"triggerdistance"
167 _attr_entity_category = EntityCategory.CONFIG
169 PresenceConfigTriggerDistance.FAR.value,
170 PresenceConfigTriggerDistance.MEDIUM.value,
171 PresenceConfigTriggerDistance.NEAR.value,
178 """Return the selected entity option to represent the entity state."""
179 if self._device.trigger_distance
is not None:
180 return self._device.trigger_distance.value
184 """Change the selected option."""
185 await self.hub.api.sensors.presence.set_config(
186 id=self._device.resource_id,
187 trigger_distance=PresenceConfigTriggerDistance(option),
None async_select_option(self, str option)
str|None current_option(self)
None async_select_option(self, str option)
None async_select_option(self, str option)
str|None current_option(self)
str|None current_option(self)
None async_select_option(self, str option)
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)