1 """Support for deCONZ buttons."""
3 from __future__
import annotations
5 from dataclasses
import dataclass
7 from pydeconz.models.event
import EventType
8 from pydeconz.models.scene
import Scene
as PydeconzScene
9 from pydeconz.models.sensor.presence
import Presence
12 DOMAIN
as BUTTON_DOMAIN,
15 ButtonEntityDescription,
22 from .entity
import DeconzDevice, DeconzSceneMixin
23 from .hub
import DeconzHub
26 @dataclass(frozen=True, kw_only=True)
28 """Class describing deCONZ button entities."""
34 ENTITY_DESCRIPTIONS = {
39 suffix=
"Store Current Scene",
40 icon=
"mdi:inbox-arrow-down",
41 entity_category=EntityCategory.CONFIG,
49 config_entry: ConfigEntry,
50 async_add_entities: AddEntitiesCallback,
52 """Set up the deCONZ button entity."""
53 hub = DeconzHub.get_hub(hass, config_entry)
54 hub.entities[BUTTON_DOMAIN] = set()
57 def async_add_scene(_: EventType, scene_id: str) ->
None:
58 """Add scene button from deCONZ."""
59 scene = hub.api.scenes[scene_id]
62 for description
in ENTITY_DESCRIPTIONS.get(PydeconzScene, [])
65 hub.register_platform_add_device_callback(
71 def async_add_presence_sensor(_: EventType, sensor_id: str) ->
None:
72 """Add presence sensor reset button from deCONZ."""
73 sensor = hub.api.sensors.presence[sensor_id]
74 if sensor.presence_event
is not None:
77 hub.register_platform_add_device_callback(
78 async_add_presence_sensor,
79 hub.api.sensors.presence,
84 """Representation of a deCONZ button entity."""
90 device: PydeconzScene,
92 description: DeconzButtonDescription,
94 """Initialize deCONZ number entity."""
95 self.entity_description: DeconzButtonDescription = description
101 """Store light states into scene."""
102 async_button_fn = getattr(
104 self.entity_description.button_fn,
106 await async_button_fn(self._device.group_id, self._device.id)
109 """Return a unique identifier for this scene."""
110 return f
"{super().get_device_identifier()}-{self.entity_description.key}"
114 """Representation of a deCONZ presence reset button entity."""
116 _name_suffix =
"Reset Presence"
117 unique_id_suffix =
"reset_presence"
119 _attr_entity_category = EntityCategory.CONFIG
120 _attr_device_class = ButtonDeviceClass.RESTART
125 """Store reset presence state."""
126 await self.hub.api.sensors.presence.set_config(
127 id=self._device.resource_id,