Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 11 additions & 27 deletions homeassistant/components/opple/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from homeassistant.components.light import (
ATTR_BRIGHTNESS,
ATTR_COLOR_TEMP,
ATTR_COLOR_TEMP_KELVIN,
PLATFORM_SCHEMA as LIGHT_PLATFORM_SCHEMA,
ColorMode,
LightEntity,
Expand All @@ -20,10 +20,6 @@
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity_platform import AddEntitiesCallback
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__)

Expand Down Expand Up @@ -58,6 +54,8 @@ class OppleLight(LightEntity):

_attr_color_mode = 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):
"""Initialize an Opple light."""
Expand All @@ -67,7 +65,6 @@ def __init__(self, name, host):
self._name = name
self._is_on = None
self._brightness = None
self._color_temp = None

@property
def available(self) -> bool:
Expand All @@ -94,21 +91,6 @@ def brightness(self):
"""Return the brightness of the light."""
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:
"""Instruct the light to turn on."""
_LOGGER.debug("Turn on light %s %s", self._device.ip, kwargs)
Expand All @@ -118,9 +100,11 @@ def turn_on(self, **kwargs: Any) -> None:
if ATTR_BRIGHTNESS in kwargs and self.brightness != kwargs[ATTR_BRIGHTNESS]:
self._device.brightness = kwargs[ATTR_BRIGHTNESS]

if ATTR_COLOR_TEMP in kwargs and self.color_temp != kwargs[ATTR_COLOR_TEMP]:
color_temp = mired_to_kelvin(kwargs[ATTR_COLOR_TEMP])
self._device.color_temperature = color_temp
if (
ATTR_COLOR_TEMP_KELVIN in kwargs
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:
"""Instruct the light to turn off."""
Expand All @@ -136,7 +120,7 @@ def update(self) -> None:
prev_available == self.available
and self._is_on == self._device.power_on
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

Expand All @@ -146,7 +130,7 @@ def update(self) -> None:

self._is_on = self._device.power_on
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:
_LOGGER.debug("Update light %s success: power off", self._device.ip)
Expand All @@ -155,5 +139,5 @@ def update(self) -> None:
"Update light %s success: power on brightness %s color temperature %s",
self._device.ip,
self._brightness,
self._color_temp,
self._attr_color_temp_kelvin,
)