Code cleanup: Separate fibaro scene logic (#91895)
* Code cleanup fibaro scene * Remove duplicated code * Fixes
This commit is contained in:
parent
11accd8ba7
commit
83f206a6fe
4 changed files with 138 additions and 29 deletions
|
@ -11,8 +11,9 @@ from homeassistant.const import Platform
|
|||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity import DeviceInfo
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.util import slugify
|
||||
|
||||
from . import FIBARO_DEVICES, FibaroDevice
|
||||
from . import FIBARO_DEVICES, FibaroController
|
||||
from .const import DOMAIN
|
||||
|
||||
|
||||
|
@ -33,18 +34,30 @@ async def async_setup_entry(
|
|||
)
|
||||
|
||||
|
||||
class FibaroScene(FibaroDevice, Scene):
|
||||
class FibaroScene(Scene):
|
||||
"""Representation of a Fibaro scene entity."""
|
||||
|
||||
def __init__(self, fibaro_device: SceneModel) -> None:
|
||||
def __init__(self, fibaro_scene: SceneModel) -> None:
|
||||
"""Initialize the Fibaro scene."""
|
||||
super().__init__(fibaro_device)
|
||||
self._fibaro_scene = fibaro_scene
|
||||
|
||||
controller: FibaroController = fibaro_scene.fibaro_controller
|
||||
room_name = controller.get_room_name(fibaro_scene.room_id)
|
||||
if not room_name:
|
||||
room_name = "Unknown"
|
||||
|
||||
self._attr_name = f"{room_name} {fibaro_scene.name}"
|
||||
self._attr_unique_id = (
|
||||
f"{slugify(controller.hub_serial)}.scene.{fibaro_scene.fibaro_id}"
|
||||
)
|
||||
self._attr_extra_state_attributes = {"fibaro_id": fibaro_scene.fibaro_id}
|
||||
# propagate hidden attribute set in fibaro home center to HA
|
||||
self._attr_entity_registry_visible_default = fibaro_scene.visible
|
||||
# All scenes are shown on hub device
|
||||
self._attr_device_info = DeviceInfo(
|
||||
identifiers={(DOMAIN, self.controller.hub_serial)}
|
||||
identifiers={(DOMAIN, controller.hub_serial)}
|
||||
)
|
||||
|
||||
def activate(self, **kwargs: Any) -> None:
|
||||
"""Activate the scene."""
|
||||
self.fibaro_device.start()
|
||||
self._fibaro_scene.start()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue