1 """Support for bond buttons."""
3 from __future__
import annotations
5 from dataclasses
import dataclass
7 from bond_async
import Action
13 from .
import BondConfigEntry
14 from .entity
import BondEntity
15 from .models
import BondData
16 from .utils
import BondDevice
24 @dataclass(frozen=True, kw_only=True)
26 """Class to describe a Bond Button entity."""
30 name: str |
None =
None
31 mutually_exclusive: Action |
None
38 translation_key=
"stop_actions",
39 mutually_exclusive=
None,
44 BUTTONS: tuple[BondButtonEntityDescription, ...] = (
46 key=Action.TOGGLE_POWER,
48 translation_key=
"toggle_power",
49 mutually_exclusive=Action.TURN_ON,
53 key=Action.TOGGLE_LIGHT,
55 translation_key=
"toggle_light",
56 mutually_exclusive=Action.TURN_LIGHT_ON,
60 key=Action.INCREASE_BRIGHTNESS,
61 name=
"Increase Brightness",
62 translation_key=
"increase_brightness",
63 mutually_exclusive=Action.SET_BRIGHTNESS,
67 key=Action.DECREASE_BRIGHTNESS,
68 name=
"Decrease Brightness",
69 translation_key=
"decrease_brightness",
70 mutually_exclusive=Action.SET_BRIGHTNESS,
74 key=Action.TOGGLE_UP_LIGHT,
75 name=
"Toggle Up Light",
76 translation_key=
"toggle_up_light",
77 mutually_exclusive=Action.TURN_UP_LIGHT_ON,
81 key=Action.TOGGLE_DOWN_LIGHT,
82 name=
"Toggle Down Light",
83 translation_key=
"toggle_down_light",
84 mutually_exclusive=Action.TURN_DOWN_LIGHT_ON,
88 key=Action.START_DIMMER,
90 translation_key=
"start_dimmer",
91 mutually_exclusive=Action.SET_BRIGHTNESS,
95 key=Action.START_UP_LIGHT_DIMMER,
96 name=
"Start Up Light Dimmer",
97 translation_key=
"start_up_light_dimmer",
98 mutually_exclusive=Action.SET_UP_LIGHT_BRIGHTNESS,
102 key=Action.START_DOWN_LIGHT_DIMMER,
103 name=
"Start Down Light Dimmer",
104 translation_key=
"start_down_light_dimmer",
105 mutually_exclusive=Action.SET_DOWN_LIGHT_BRIGHTNESS,
109 key=Action.START_INCREASING_BRIGHTNESS,
110 name=
"Start Increasing Brightness",
111 translation_key=
"start_increasing_brightness",
112 mutually_exclusive=Action.SET_BRIGHTNESS,
116 key=Action.START_DECREASING_BRIGHTNESS,
117 name=
"Start Decreasing Brightness",
118 translation_key=
"start_decreasing_brightness",
119 mutually_exclusive=Action.SET_BRIGHTNESS,
123 key=Action.INCREASE_UP_LIGHT_BRIGHTNESS,
124 name=
"Increase Up Light Brightness",
125 translation_key=
"increase_up_light_brightness",
126 mutually_exclusive=Action.SET_UP_LIGHT_BRIGHTNESS,
130 key=Action.DECREASE_UP_LIGHT_BRIGHTNESS,
131 name=
"Decrease Up Light Brightness",
132 translation_key=
"decrease_up_light_brightness",
133 mutually_exclusive=Action.SET_UP_LIGHT_BRIGHTNESS,
137 key=Action.INCREASE_DOWN_LIGHT_BRIGHTNESS,
138 name=
"Increase Down Light Brightness",
139 translation_key=
"increase_down_light_brightness",
140 mutually_exclusive=Action.SET_DOWN_LIGHT_BRIGHTNESS,
144 key=Action.DECREASE_DOWN_LIGHT_BRIGHTNESS,
145 name=
"Decrease Down Light Brightness",
146 translation_key=
"decrease_down_light_brightness",
147 mutually_exclusive=Action.SET_DOWN_LIGHT_BRIGHTNESS,
151 key=Action.CYCLE_UP_LIGHT_BRIGHTNESS,
152 name=
"Cycle Up Light Brightness",
153 translation_key=
"cycle_up_light_brightness",
154 mutually_exclusive=Action.SET_UP_LIGHT_BRIGHTNESS,
158 key=Action.CYCLE_DOWN_LIGHT_BRIGHTNESS,
159 name=
"Cycle Down Light Brightness",
160 translation_key=
"cycle_down_light_brightness",
161 mutually_exclusive=Action.SET_DOWN_LIGHT_BRIGHTNESS,
165 key=Action.CYCLE_BRIGHTNESS,
166 name=
"Cycle Brightness",
167 translation_key=
"cycle_brightness",
168 mutually_exclusive=Action.SET_BRIGHTNESS,
172 key=Action.INCREASE_SPEED,
173 name=
"Increase Speed",
174 translation_key=
"increase_speed",
175 mutually_exclusive=Action.SET_SPEED,
179 key=Action.DECREASE_SPEED,
180 name=
"Decrease Speed",
181 translation_key=
"decrease_speed",
182 mutually_exclusive=Action.SET_SPEED,
186 key=Action.TOGGLE_DIRECTION,
187 name=
"Toggle Direction",
188 translation_key=
"toggle_direction",
189 mutually_exclusive=Action.SET_DIRECTION,
193 key=Action.INCREASE_TEMPERATURE,
194 name=
"Increase Temperature",
195 translation_key=
"increase_temperature",
196 mutually_exclusive=
None,
200 key=Action.DECREASE_TEMPERATURE,
201 name=
"Decrease Temperature",
202 translation_key=
"decrease_temperature",
203 mutually_exclusive=
None,
207 key=Action.INCREASE_FLAME,
208 name=
"Increase Flame",
209 translation_key=
"increase_flame",
210 mutually_exclusive=
None,
214 key=Action.DECREASE_FLAME,
215 name=
"Decrease Flame",
216 translation_key=
"decrease_flame",
217 mutually_exclusive=
None,
221 key=Action.TOGGLE_OPEN,
223 mutually_exclusive=Action.OPEN,
227 key=Action.INCREASE_POSITION,
228 name=
"Increase Position",
229 translation_key=
"increase_position",
230 mutually_exclusive=Action.SET_POSITION,
234 key=Action.DECREASE_POSITION,
235 name=
"Decrease Position",
236 translation_key=
"decrease_position",
237 mutually_exclusive=Action.SET_POSITION,
241 key=Action.OPEN_NEXT,
243 translation_key=
"open_next",
244 mutually_exclusive=
None,
248 key=Action.CLOSE_NEXT,
250 translation_key=
"close_next",
251 mutually_exclusive=
None,
259 entry: BondConfigEntry,
260 async_add_entities: AddEntitiesCallback,
262 """Set up Bond button devices."""
263 data = entry.runtime_data
264 entities: list[BondButtonEntity] = []
266 for device
in data.hub.devices:
269 for description
in BUTTONS
270 if device.has_action(description.key)
272 description.mutually_exclusive
is None
273 or not device.has_action(description.mutually_exclusive)
276 if device_entities
and device.has_action(STOP_BUTTON.key):
281 entities.extend(device_entities)
287 """Bond Button Device."""
289 entity_description: BondButtonEntityDescription
295 description: BondButtonEntityDescription,
297 """Init Bond button."""
299 super().
__init__(data, device, description.name, description.key.lower())
302 """Press the button."""
304 key = description.key
305 if argument := description.argument:
306 action = Action(key, argument)
312 """Apply the state."""