-
-
Notifications
You must be signed in to change notification settings - Fork 37.7k
Add scene platform for Sunricher DALI integration #157808
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
joostlek
merged 11 commits into
home-assistant:dev
from
niracler:feat/sunricher-dali-scene
Dec 18, 2025
Merged
Changes from 6 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
a5c3559
feat(sunricher_dali): add scene platform
niracler 31443c6
feat(sunricher_dali): add scene platform
niracler d3a9379
add PARALLEL_UPDATES
niracler 8e971c9
fix(sunricher_dali): remove debug logging and improve test coverage
niracler 219901b
refactor(sunricher_dali): optimize test structure
niracler 6ab265e
Add base entity for Sunricher DALI
niracler 1f9ea82
deps: update PySrDaliGateway to 0.18.0
niracler 323384c
refactor(sunricher_dali): extract DaliDeviceEntity class
niracler 0b6d5ef
Merge branch 'dev' into feat/sunricher-dali-scene
niracler fc4ec6b
Merge remote-tracking branch 'upstream/dev' into feat/sunricher-dali-…
niracler 64fb7c5
Fix
joostlek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| """Base entity for Sunricher DALI integration.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import logging | ||
|
|
||
| from PySrDaliGateway import CallbackEventType, DaliObjectBase, Device | ||
|
Check failure on line 7 in homeassistant/components/sunricher_dali/entity.py
|
||
|
|
||
| from homeassistant.core import callback | ||
| from homeassistant.helpers.entity import Entity | ||
|
|
||
| _LOGGER = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| class DaliCenterEntity(Entity): | ||
| """Base entity for DALI Center objects (devices, scenes, etc.).""" | ||
|
|
||
| _attr_has_entity_name = True | ||
| _attr_should_poll = False | ||
|
|
||
| def __init__(self, dali_object: DaliObjectBase) -> None: | ||
| """Initialize base entity.""" | ||
| self._dali_object = dali_object | ||
| self._attr_unique_id = dali_object.unique_id | ||
| self._unavailable_logged = False | ||
| # Set initial availability from status if available (Device has it, Scene doesn't) | ||
| if isinstance(dali_object, Device): | ||
| self._attr_available = dali_object.status == "online" | ||
| else: | ||
| self._attr_available = True | ||
|
|
||
| async def async_added_to_hass(self) -> None: | ||
| """Register availability listener.""" | ||
| self.async_on_remove( | ||
| self._dali_object.register_listener( | ||
| CallbackEventType.ONLINE_STATUS, | ||
| self._handle_availability, | ||
| ) | ||
| ) | ||
|
|
||
| @callback | ||
| def _handle_availability(self, available: bool) -> None: | ||
| """Handle availability changes.""" | ||
| # Log availability transitions | ||
| if not available and not self._unavailable_logged: | ||
| _LOGGER.info("Entity %s became unavailable", self.entity_id) | ||
| self._unavailable_logged = True | ||
| elif available and self._unavailable_logged: | ||
| _LOGGER.info("Entity %s is back online", self.entity_id) | ||
| self._unavailable_logged = False | ||
|
|
||
| self._attr_available = available | ||
| self.schedule_update_ha_state() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| """Support for DALI Center Scene entities.""" | ||
|
|
||
| import logging | ||
| from typing import Any | ||
|
|
||
| from propcache.api import cached_property | ||
| from PySrDaliGateway import Scene | ||
|
|
||
| from homeassistant.components.scene import Scene as SceneEntity | ||
| from homeassistant.core import HomeAssistant | ||
| from homeassistant.helpers import entity_registry as er | ||
| from homeassistant.helpers.device_registry import DeviceInfo | ||
| from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback | ||
|
|
||
| from .const import DOMAIN | ||
| from .entity import DaliCenterEntity | ||
| from .types import DaliCenterConfigEntry | ||
|
|
||
| _LOGGER = logging.getLogger(__name__) | ||
|
|
||
| PARALLEL_UPDATES = 1 | ||
|
|
||
|
|
||
| async def async_setup_entry( | ||
| hass: HomeAssistant, | ||
| entry: DaliCenterConfigEntry, | ||
| async_add_entities: AddConfigEntryEntitiesCallback, | ||
| ) -> None: | ||
| """Set up DALI Center scene entities from config entry.""" | ||
| async_add_entities(DaliCenterScene(scene) for scene in entry.runtime_data.scenes) | ||
|
|
||
|
|
||
| class DaliCenterScene(DaliCenterEntity, SceneEntity): | ||
| """Representation of a DALI Center Scene.""" | ||
|
|
||
| def __init__(self, scene: Scene) -> None: | ||
| """Initialize the DALI scene.""" | ||
| super().__init__(scene) | ||
| self._scene = scene | ||
| self._attr_name = scene.name | ||
| self._attr_device_info = DeviceInfo( | ||
| identifiers={(DOMAIN, scene.gw_sn)}, | ||
| ) | ||
|
|
||
| @cached_property | ||
| def extra_state_attributes(self) -> dict[str, list[str]]: | ||
| """Return the scene state attributes.""" | ||
| ent_reg = er.async_get(self.hass) | ||
| return { | ||
| "entity_id": [ | ||
| entity_id | ||
| for device in self._scene.devices | ||
| if ( | ||
| entity_id := ent_reg.async_get_entity_id( | ||
| "light", DOMAIN, device["unique_id"] | ||
| ) | ||
| ) | ||
| ] | ||
| } | ||
|
|
||
| async def async_activate(self, **kwargs: Any) -> None: | ||
| """Activate the DALI scene.""" | ||
| _LOGGER.debug("Activating scene: %s", self._attr_name) | ||
| await self.hass.async_add_executor_job(self._scene.activate) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.