mirror of
https://github.com/home-assistant/core.git
synced 2025-05-05 22:49:17 +00:00
Address late review from add fibaro event platform (#101718)
This commit is contained in:
parent
1944b2952c
commit
deffa50142
@ -194,8 +194,8 @@ class FibaroController:
|
|||||||
|
|
||||||
def register(self, device_id: int, callback: Any) -> None:
|
def register(self, device_id: int, callback: Any) -> None:
|
||||||
"""Register device with a callback for updates."""
|
"""Register device with a callback for updates."""
|
||||||
self._callbacks.setdefault(device_id, [])
|
device_callbacks = self._callbacks.setdefault(device_id, [])
|
||||||
self._callbacks[device_id].append(callback)
|
device_callbacks.append(callback)
|
||||||
|
|
||||||
def register_event(
|
def register_event(
|
||||||
self, device_id: int, callback: Callable[[FibaroEvent], None]
|
self, device_id: int, callback: Callable[[FibaroEvent], None]
|
||||||
@ -204,8 +204,8 @@ class FibaroController:
|
|||||||
|
|
||||||
The callback receives one parameter with the event.
|
The callback receives one parameter with the event.
|
||||||
"""
|
"""
|
||||||
self._event_callbacks.setdefault(device_id, [])
|
device_callbacks = self._event_callbacks.setdefault(device_id, [])
|
||||||
self._event_callbacks[device_id].append(callback)
|
device_callbacks.append(callback)
|
||||||
|
|
||||||
def get_children(self, device_id: int) -> list[DeviceModel]:
|
def get_children(self, device_id: int) -> list[DeviceModel]:
|
||||||
"""Get a list of child devices."""
|
"""Get a list of child devices."""
|
||||||
|
@ -11,7 +11,7 @@ from homeassistant.components.event import (
|
|||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import Platform
|
from homeassistant.const import Platform
|
||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from . import FibaroController, FibaroDevice
|
from . import FibaroController, FibaroDevice
|
||||||
@ -41,16 +41,17 @@ class FibaroEventEntity(FibaroDevice, EventEntity):
|
|||||||
def __init__(self, fibaro_device: DeviceModel, scene_event: SceneEvent) -> None:
|
def __init__(self, fibaro_device: DeviceModel, scene_event: SceneEvent) -> None:
|
||||||
"""Initialize the Fibaro device."""
|
"""Initialize the Fibaro device."""
|
||||||
super().__init__(fibaro_device)
|
super().__init__(fibaro_device)
|
||||||
self.entity_id = ENTITY_ID_FORMAT.format(
|
|
||||||
f"{self.ha_id}_button_{scene_event.key_id}"
|
|
||||||
)
|
|
||||||
|
|
||||||
self._button = scene_event.key_id
|
key_id = scene_event.key_id
|
||||||
|
|
||||||
self._attr_name = f"{fibaro_device.friendly_name} Button {scene_event.key_id}"
|
self.entity_id = ENTITY_ID_FORMAT.format(f"{self.ha_id}_button_{key_id}")
|
||||||
|
|
||||||
|
self._button = key_id
|
||||||
|
|
||||||
|
self._attr_name = f"{fibaro_device.friendly_name} Button {key_id}"
|
||||||
self._attr_device_class = EventDeviceClass.BUTTON
|
self._attr_device_class = EventDeviceClass.BUTTON
|
||||||
self._attr_event_types = scene_event.key_event_types
|
self._attr_event_types = scene_event.key_event_types
|
||||||
self._attr_unique_id = f"{fibaro_device.unique_id_str}.{scene_event.key_id}"
|
self._attr_unique_id = f"{fibaro_device.unique_id_str}.{key_id}"
|
||||||
|
|
||||||
async def async_added_to_hass(self) -> None:
|
async def async_added_to_hass(self) -> None:
|
||||||
"""Call when entity is added to hass."""
|
"""Call when entity is added to hass."""
|
||||||
@ -61,7 +62,6 @@ class FibaroEventEntity(FibaroDevice, EventEntity):
|
|||||||
self.fibaro_device.fibaro_id, self._event_callback
|
self.fibaro_device.fibaro_id, self._event_callback
|
||||||
)
|
)
|
||||||
|
|
||||||
@callback
|
|
||||||
def _event_callback(self, event: FibaroEvent) -> None:
|
def _event_callback(self, event: FibaroEvent) -> None:
|
||||||
if event.key_id == self._button:
|
if event.key_id == self._button:
|
||||||
self._trigger_event(event.key_event_type)
|
self._trigger_event(event.key_event_type)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user