Address late review from add fibaro event platform (#101718)

This commit is contained in:
rappenze 2023-10-10 06:07:29 +02:00 committed by GitHub
parent 1944b2952c
commit deffa50142
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 12 deletions

View File

@ -194,8 +194,8 @@ class FibaroController:
def register(self, device_id: int, callback: Any) -> None:
"""Register device with a callback for updates."""
self._callbacks.setdefault(device_id, [])
self._callbacks[device_id].append(callback)
device_callbacks = self._callbacks.setdefault(device_id, [])
device_callbacks.append(callback)
def register_event(
self, device_id: int, callback: Callable[[FibaroEvent], None]
@ -204,8 +204,8 @@ class FibaroController:
The callback receives one parameter with the event.
"""
self._event_callbacks.setdefault(device_id, [])
self._event_callbacks[device_id].append(callback)
device_callbacks = self._event_callbacks.setdefault(device_id, [])
device_callbacks.append(callback)
def get_children(self, device_id: int) -> list[DeviceModel]:
"""Get a list of child devices."""

View File

@ -11,7 +11,7 @@ from homeassistant.components.event import (
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant, callback
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from . import FibaroController, FibaroDevice
@ -41,16 +41,17 @@ class FibaroEventEntity(FibaroDevice, EventEntity):
def __init__(self, fibaro_device: DeviceModel, scene_event: SceneEvent) -> None:
"""Initialize the 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_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:
"""Call when entity is added to hass."""
@ -61,7 +62,6 @@ class FibaroEventEntity(FibaroDevice, EventEntity):
self.fibaro_device.fibaro_id, self._event_callback
)
@callback
def _event_callback(self, event: FibaroEvent) -> None:
if event.key_id == self._button:
self._trigger_event(event.key_event_type)