mirror of
https://github.com/home-assistant/core.git
synced 2025-07-28 15:47:12 +00:00
Migrate opple lights to use Kelvin (#132697)
This commit is contained in:
parent
8d72443fd6
commit
ac791bdd20
@ -10,7 +10,7 @@ import voluptuous as vol
|
|||||||
|
|
||||||
from homeassistant.components.light import (
|
from homeassistant.components.light import (
|
||||||
ATTR_BRIGHTNESS,
|
ATTR_BRIGHTNESS,
|
||||||
ATTR_COLOR_TEMP,
|
ATTR_COLOR_TEMP_KELVIN,
|
||||||
PLATFORM_SCHEMA as LIGHT_PLATFORM_SCHEMA,
|
PLATFORM_SCHEMA as LIGHT_PLATFORM_SCHEMA,
|
||||||
ColorMode,
|
ColorMode,
|
||||||
LightEntity,
|
LightEntity,
|
||||||
@ -20,10 +20,6 @@ from homeassistant.core import HomeAssistant
|
|||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||||
from homeassistant.util.color import (
|
|
||||||
color_temperature_kelvin_to_mired as kelvin_to_mired,
|
|
||||||
color_temperature_mired_to_kelvin as mired_to_kelvin,
|
|
||||||
)
|
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -58,6 +54,8 @@ class OppleLight(LightEntity):
|
|||||||
|
|
||||||
_attr_color_mode = ColorMode.COLOR_TEMP
|
_attr_color_mode = ColorMode.COLOR_TEMP
|
||||||
_attr_supported_color_modes = {ColorMode.COLOR_TEMP}
|
_attr_supported_color_modes = {ColorMode.COLOR_TEMP}
|
||||||
|
_attr_min_color_temp_kelvin = 3000 # 333 Mireds
|
||||||
|
_attr_max_color_temp_kelvin = 5700 # 175 Mireds
|
||||||
|
|
||||||
def __init__(self, name, host):
|
def __init__(self, name, host):
|
||||||
"""Initialize an Opple light."""
|
"""Initialize an Opple light."""
|
||||||
@ -67,7 +65,6 @@ class OppleLight(LightEntity):
|
|||||||
self._name = name
|
self._name = name
|
||||||
self._is_on = None
|
self._is_on = None
|
||||||
self._brightness = None
|
self._brightness = None
|
||||||
self._color_temp = None
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def available(self) -> bool:
|
def available(self) -> bool:
|
||||||
@ -94,21 +91,6 @@ class OppleLight(LightEntity):
|
|||||||
"""Return the brightness of the light."""
|
"""Return the brightness of the light."""
|
||||||
return self._brightness
|
return self._brightness
|
||||||
|
|
||||||
@property
|
|
||||||
def color_temp(self):
|
|
||||||
"""Return the color temperature of this light."""
|
|
||||||
return kelvin_to_mired(self._color_temp)
|
|
||||||
|
|
||||||
@property
|
|
||||||
def min_mireds(self):
|
|
||||||
"""Return minimum supported color temperature."""
|
|
||||||
return 175
|
|
||||||
|
|
||||||
@property
|
|
||||||
def max_mireds(self):
|
|
||||||
"""Return maximum supported color temperature."""
|
|
||||||
return 333
|
|
||||||
|
|
||||||
def turn_on(self, **kwargs: Any) -> None:
|
def turn_on(self, **kwargs: Any) -> None:
|
||||||
"""Instruct the light to turn on."""
|
"""Instruct the light to turn on."""
|
||||||
_LOGGER.debug("Turn on light %s %s", self._device.ip, kwargs)
|
_LOGGER.debug("Turn on light %s %s", self._device.ip, kwargs)
|
||||||
@ -118,9 +100,11 @@ class OppleLight(LightEntity):
|
|||||||
if ATTR_BRIGHTNESS in kwargs and self.brightness != kwargs[ATTR_BRIGHTNESS]:
|
if ATTR_BRIGHTNESS in kwargs and self.brightness != kwargs[ATTR_BRIGHTNESS]:
|
||||||
self._device.brightness = kwargs[ATTR_BRIGHTNESS]
|
self._device.brightness = kwargs[ATTR_BRIGHTNESS]
|
||||||
|
|
||||||
if ATTR_COLOR_TEMP in kwargs and self.color_temp != kwargs[ATTR_COLOR_TEMP]:
|
if (
|
||||||
color_temp = mired_to_kelvin(kwargs[ATTR_COLOR_TEMP])
|
ATTR_COLOR_TEMP_KELVIN in kwargs
|
||||||
self._device.color_temperature = color_temp
|
and self.color_temp_kelvin != kwargs[ATTR_COLOR_TEMP_KELVIN]
|
||||||
|
):
|
||||||
|
self._device.color_temperature = kwargs[ATTR_COLOR_TEMP_KELVIN]
|
||||||
|
|
||||||
def turn_off(self, **kwargs: Any) -> None:
|
def turn_off(self, **kwargs: Any) -> None:
|
||||||
"""Instruct the light to turn off."""
|
"""Instruct the light to turn off."""
|
||||||
@ -136,7 +120,7 @@ class OppleLight(LightEntity):
|
|||||||
prev_available == self.available
|
prev_available == self.available
|
||||||
and self._is_on == self._device.power_on
|
and self._is_on == self._device.power_on
|
||||||
and self._brightness == self._device.brightness
|
and self._brightness == self._device.brightness
|
||||||
and self._color_temp == self._device.color_temperature
|
and self._attr_color_temp_kelvin == self._device.color_temperature
|
||||||
):
|
):
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -146,7 +130,7 @@ class OppleLight(LightEntity):
|
|||||||
|
|
||||||
self._is_on = self._device.power_on
|
self._is_on = self._device.power_on
|
||||||
self._brightness = self._device.brightness
|
self._brightness = self._device.brightness
|
||||||
self._color_temp = self._device.color_temperature
|
self._attr_color_temp_kelvin = self._device.color_temperature
|
||||||
|
|
||||||
if not self.is_on:
|
if not self.is_on:
|
||||||
_LOGGER.debug("Update light %s success: power off", self._device.ip)
|
_LOGGER.debug("Update light %s success: power off", self._device.ip)
|
||||||
@ -155,5 +139,5 @@ class OppleLight(LightEntity):
|
|||||||
"Update light %s success: power on brightness %s color temperature %s",
|
"Update light %s success: power on brightness %s color temperature %s",
|
||||||
self._device.ip,
|
self._device.ip,
|
||||||
self._brightness,
|
self._brightness,
|
||||||
self._color_temp,
|
self._attr_color_temp_kelvin,
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user