feat: Einstellungen, Neustart, Diagnose-Sensoren und Diagnose-Download
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
"""Fade and transition settings of a ninlight lamp."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from dataclasses import dataclass
|
||||
|
||||
from homeassistant.components.number import (
|
||||
NumberDeviceClass,
|
||||
NumberEntity,
|
||||
NumberEntityDescription,
|
||||
NumberMode,
|
||||
)
|
||||
from homeassistant.const import EntityCategory, UnitOfTime
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||
|
||||
from .coordinator import NinlightConfigEntry, NinlightCoordinator
|
||||
from .entity import NinlightEntity
|
||||
|
||||
PARALLEL_UPDATES = 0
|
||||
|
||||
|
||||
@dataclass(frozen=True, kw_only=True)
|
||||
class NinlightNumberDescription(NumberEntityDescription):
|
||||
"""A millisecond setting stored under `key` in the lamp state."""
|
||||
|
||||
entity_category: EntityCategory = EntityCategory.CONFIG
|
||||
device_class: NumberDeviceClass = NumberDeviceClass.DURATION
|
||||
native_unit_of_measurement: str = UnitOfTime.MILLISECONDS
|
||||
native_min_value: float = 0
|
||||
native_step: float = 50
|
||||
mode: NumberMode = NumberMode.BOX
|
||||
|
||||
|
||||
NUMBERS = (
|
||||
NinlightNumberDescription(key="fade_in", translation_key="fade_in", native_max_value=10_000),
|
||||
NinlightNumberDescription(key="fade_out", translation_key="fade_out", native_max_value=10_000),
|
||||
NinlightNumberDescription(
|
||||
key="transition_default", translation_key="transition_default", native_max_value=60_000
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
entry: NinlightConfigEntry,
|
||||
async_add_entities: AddConfigEntryEntitiesCallback,
|
||||
) -> None:
|
||||
async_add_entities(NinlightNumber(entry.runtime_data, description) for description in NUMBERS)
|
||||
|
||||
|
||||
class NinlightNumber(NinlightEntity, NumberEntity):
|
||||
"""One millisecond setting."""
|
||||
|
||||
entity_description: NinlightNumberDescription
|
||||
|
||||
def __init__(
|
||||
self, coordinator: NinlightCoordinator, description: NinlightNumberDescription
|
||||
) -> None:
|
||||
super().__init__(coordinator, description.key)
|
||||
self.entity_description = description
|
||||
|
||||
@property
|
||||
def native_value(self) -> int | None:
|
||||
value = self.coordinator.data.state.get(self.entity_description.key)
|
||||
return int(value) if value is not None else None
|
||||
|
||||
async def async_set_native_value(self, value: float) -> None:
|
||||
await self.coordinator.async_set_state(**{self.entity_description.key: int(value)})
|
||||
Reference in New Issue
Block a user