Add identify and restart button entities to the LIFX integration (#75568)
This commit is contained in:
parent
db3e21df86
commit
74cfdc6c1f
8 changed files with 292 additions and 27 deletions
|
@ -6,7 +6,6 @@ from datetime import datetime, timedelta
|
|||
import math
|
||||
from typing import Any
|
||||
|
||||
from aiolifx import products
|
||||
import aiolifx_effects as aiolifx_effects_module
|
||||
import voluptuous as vol
|
||||
|
||||
|
@ -20,20 +19,18 @@ from homeassistant.components.light import (
|
|||
LightEntityFeature,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import ATTR_ENTITY_ID, ATTR_MODEL, ATTR_SW_VERSION
|
||||
from homeassistant.const import ATTR_ENTITY_ID
|
||||
from homeassistant.core import CALLBACK_TYPE, HomeAssistant
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers import entity_platform
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
import homeassistant.helpers.device_registry as dr
|
||||
from homeassistant.helpers.entity import DeviceInfo
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.event import async_track_point_in_utc_time
|
||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||
import homeassistant.util.color as color_util
|
||||
|
||||
from .const import DATA_LIFX_MANAGER, DOMAIN
|
||||
from .coordinator import LIFXUpdateCoordinator
|
||||
from .entity import LIFXEntity
|
||||
from .manager import (
|
||||
SERVICE_EFFECT_COLORLOOP,
|
||||
SERVICE_EFFECT_PULSE,
|
||||
|
@ -92,7 +89,7 @@ async def async_setup_entry(
|
|||
async_add_entities([entity])
|
||||
|
||||
|
||||
class LIFXLight(CoordinatorEntity[LIFXUpdateCoordinator], LightEntity):
|
||||
class LIFXLight(LIFXEntity, LightEntity):
|
||||
"""Representation of a LIFX light."""
|
||||
|
||||
_attr_supported_features = LightEntityFeature.TRANSITION | LightEntityFeature.EFFECT
|
||||
|
@ -105,10 +102,9 @@ class LIFXLight(CoordinatorEntity[LIFXUpdateCoordinator], LightEntity):
|
|||
) -> None:
|
||||
"""Initialize the light."""
|
||||
super().__init__(coordinator)
|
||||
bulb = coordinator.device
|
||||
self.mac_addr = bulb.mac_addr
|
||||
self.bulb = bulb
|
||||
bulb_features = lifx_features(bulb)
|
||||
|
||||
self.mac_addr = self.bulb.mac_addr
|
||||
bulb_features = lifx_features(self.bulb)
|
||||
self.manager = manager
|
||||
self.effects_conductor: aiolifx_effects_module.Conductor = (
|
||||
manager.effects_conductor
|
||||
|
@ -116,25 +112,13 @@ class LIFXLight(CoordinatorEntity[LIFXUpdateCoordinator], LightEntity):
|
|||
self.postponed_update: CALLBACK_TYPE | None = None
|
||||
self.entry = entry
|
||||
self._attr_unique_id = self.coordinator.serial_number
|
||||
self._attr_name = bulb.label
|
||||
self._attr_name = self.bulb.label
|
||||
self._attr_min_mireds = math.floor(
|
||||
color_util.color_temperature_kelvin_to_mired(bulb_features["max_kelvin"])
|
||||
)
|
||||
self._attr_max_mireds = math.ceil(
|
||||
color_util.color_temperature_kelvin_to_mired(bulb_features["min_kelvin"])
|
||||
)
|
||||
info = DeviceInfo(
|
||||
identifiers={(DOMAIN, coordinator.serial_number)},
|
||||
connections={(dr.CONNECTION_NETWORK_MAC, coordinator.mac_address)},
|
||||
manufacturer="LIFX",
|
||||
name=self.name,
|
||||
)
|
||||
_map = products.product_map
|
||||
if (model := (_map.get(bulb.product) or bulb.product)) is not None:
|
||||
info[ATTR_MODEL] = str(model)
|
||||
if (version := bulb.host_firmware_version) is not None:
|
||||
info[ATTR_SW_VERSION] = version
|
||||
self._attr_device_info = info
|
||||
if bulb_features["min_kelvin"] != bulb_features["max_kelvin"]:
|
||||
color_mode = ColorMode.COLOR_TEMP
|
||||
else:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue