diff --git a/homeassistant/components/fibaro/__init__.py b/homeassistant/components/fibaro/__init__.py index 0272c620b99..29fc2c5b774 100644 --- a/homeassistant/components/fibaro/__init__.py +++ b/homeassistant/components/fibaro/__init__.py @@ -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.""" diff --git a/homeassistant/components/fibaro/event.py b/homeassistant/components/fibaro/event.py index 33e4161087c..020a478db95 100644 --- a/homeassistant/components/fibaro/event.py +++ b/homeassistant/components/fibaro/event.py @@ -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)