1 """Support for Lutron events."""
3 from enum
import StrEnum
5 from pylutron
import Button, Keypad, Lutron, LutronEvent
14 from .
import ATTR_ACTION, ATTR_FULL_ID, ATTR_UUID, DOMAIN, LutronData
15 from .entity
import LutronKeypad
19 """Lutron event types."""
21 SINGLE_PRESS =
"single_press"
26 LEGACY_EVENT_TYPES: dict[LutronEventType, str] = {
27 LutronEventType.SINGLE_PRESS:
"single",
28 LutronEventType.PRESS:
"pressed",
29 LutronEventType.RELEASE:
"released",
35 config_entry: ConfigEntry,
36 async_add_entities: AddEntitiesCallback,
38 """Set up the Lutron event platform."""
39 entry_data: LutronData = hass.data[DOMAIN][config_entry.entry_id]
43 for area_name, keypad, button
in entry_data.buttons
48 """Representation of a Lutron keypad button."""
50 _attr_translation_key =
"button"
59 """Initialize the button."""
60 super().
__init__(area_name, button, controller, keypad)
61 if (name := button.name) ==
"Unknown Button":
62 name += f
" {button.number}"
65 button.button_type
is not None and "RaiseLower" in button.button_type
76 """Register callbacks."""
82 self, button: Button, _context:
None, event: LutronEvent, _params: dict
84 """Handle received event."""
85 action: LutronEventType |
None =
None
87 if event == Button.Event.PRESSED:
88 action = LutronEventType.PRESS
90 action = LutronEventType.RELEASE
91 elif event == Button.Event.PRESSED:
92 action = LutronEventType.SINGLE_PRESS
97 ATTR_ACTION: LEGACY_EVENT_TYPES[action],
99 ATTR_UUID: button.uuid,
101 self.
hasshass.bus.fire(
"lutron_event", data)
None _trigger_event(self, str event_type, dict[str, Any]|None event_attributes=None)
None handle_event(self, Button button, None _context, LutronEvent event, dict _params)
None async_added_to_hass(self)
None __init__(self, str area_name, Keypad keypad, Button button, Lutron controller)
None async_on_remove(self, CALLBACK_TYPE func)
None schedule_update_ha_state(self, bool force_refresh=False)
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)
Callable[[], None] subscribe(HomeAssistant hass, str topic, MessageCallbackType msg_callback, int qos=DEFAULT_QOS, str encoding="utf-8")