feat: sACN-Einstellungen und -Status als Entitaeten
Die Firmware kann seit dieser Woche sACN/E1.31. Einstellen liess sich das nur per REST - jetzt steht es in Home Assistant: Schalter fuer den Empfang, Zahlen fuer Universe und Startslot, Auswahlen fuer das Verhalten nach dem Timeout und die Slotbelegung, dazu zwei Diagnose-Binaersensoren. Die sACN-Einstellungen liegen hinter system/settings, nicht in device/state - der Koordinator liest sie deshalb jetzt mit, eine dritte Anfrage je Zyklus. Der Schreibweg liest die Einstellungen danach frisch zurueck statt den gesetzten Wert anzunehmen: die Lampe validiert selbst (die Startslot-Grenze haengt an der Slotbelegung), und eine Entitaet, die das Gewuenschte statt des Gespeicherten zeigt, luegt in genau dem Moment, in dem es darauf ankommt. Aeltere Firmware antwortet ohne den sacn-Block. Die Entitaeten entstehen trotzdem und melden sich als nicht verfuegbar - so werden sie nach einem Update der Lampe beim naechsten Poll von selbst lebendig, ohne Neuladen. Die Obergrenze des Startslots kommt aus dem "slots"-Feld der Lampe, nicht aus einer festen 512: sie haengt an Board UND Slotbelegung, und eine feste Grenze wuerde Werte anbieten, die die Lampe dann ablehnt. Der Multicast-Sensor ist ab Werk deaktiviert wie die uebrigen Diagnosewerte. Er meldet im Normalbetrieb schlicht "beigetreten" - aber eine falsche Gruppenadresse hat zwei Abende gekostet, und genau dort waere sie aufgefallen. test_update.py misst seine Zusage jetzt um den Rescan herum statt nach dem Install: dort pollt der Koordinator ohnehin wieder und liest seitdem auch die Einstellungen mit.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
"""Power-on behaviour of a ninlight lamp."""
|
||||
"""Select settings of a ninlight lamp: power-on behaviour and sACN."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
@@ -8,12 +8,15 @@ from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||
|
||||
from .coordinator import NinlightConfigEntry, NinlightCoordinator
|
||||
from .entity import NinlightEntity
|
||||
from .entity import NinlightEntity, NinlightSacnEntity
|
||||
|
||||
PARALLEL_UPDATES = 0
|
||||
|
||||
# POB_NAMES in the firmware's nl_api.c
|
||||
POWER_ON_OPTIONS = ["last", "on", "off"]
|
||||
# The two sACN settings the firmware takes as strings, same spelling as its API.
|
||||
ON_TIMEOUT_OPTIONS = ["release", "hold"]
|
||||
LAYOUT_OPTIONS = ["dimmer", "rgb"]
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
@@ -21,7 +24,13 @@ async def async_setup_entry(
|
||||
entry: NinlightConfigEntry,
|
||||
async_add_entities: AddConfigEntryEntitiesCallback,
|
||||
) -> None:
|
||||
async_add_entities([NinlightPowerOnSelect(entry.runtime_data)])
|
||||
async_add_entities(
|
||||
[
|
||||
NinlightPowerOnSelect(entry.runtime_data),
|
||||
NinlightSacnOnTimeoutSelect(entry.runtime_data),
|
||||
NinlightSacnLayoutSelect(entry.runtime_data),
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
class NinlightPowerOnSelect(NinlightEntity, SelectEntity):
|
||||
@@ -41,3 +50,41 @@ class NinlightPowerOnSelect(NinlightEntity, SelectEntity):
|
||||
|
||||
async def async_select_option(self, option: str) -> None:
|
||||
await self.coordinator.async_set_state(power_on_behaviour=option)
|
||||
|
||||
|
||||
class NinlightSacnOnTimeoutSelect(NinlightSacnEntity, SelectEntity):
|
||||
"""What the lamp does 2.5 s after the last sACN packet."""
|
||||
|
||||
_attr_entity_category = EntityCategory.CONFIG
|
||||
_attr_translation_key = "sacn_on_timeout"
|
||||
_attr_options = ON_TIMEOUT_OPTIONS
|
||||
|
||||
def __init__(self, coordinator: NinlightCoordinator) -> None:
|
||||
super().__init__(coordinator, "sacn_on_timeout")
|
||||
|
||||
@property
|
||||
def current_option(self) -> str | None:
|
||||
value = self.sacn.get("on_timeout")
|
||||
return value if value in ON_TIMEOUT_OPTIONS else None
|
||||
|
||||
async def async_select_option(self, option: str) -> None:
|
||||
await self.coordinator.async_set_sacn(on_timeout=option)
|
||||
|
||||
|
||||
class NinlightSacnLayoutSelect(NinlightSacnEntity, SelectEntity):
|
||||
"""Which slots the lamp reads: with a master dimmer, or plain R,G,B."""
|
||||
|
||||
_attr_entity_category = EntityCategory.CONFIG
|
||||
_attr_translation_key = "sacn_layout"
|
||||
_attr_options = LAYOUT_OPTIONS
|
||||
|
||||
def __init__(self, coordinator: NinlightCoordinator) -> None:
|
||||
super().__init__(coordinator, "sacn_layout")
|
||||
|
||||
@property
|
||||
def current_option(self) -> str | None:
|
||||
value = self.sacn.get("layout")
|
||||
return value if value in LAYOUT_OPTIONS else None
|
||||
|
||||
async def async_select_option(self, option: str) -> None:
|
||||
await self.coordinator.async_set_sacn(layout=option)
|
||||
|
||||
Reference in New Issue
Block a user