mirror of
https://github.com/home-assistant/core.git
synced 2025-07-13 16:27:08 +00:00
Added support for transitions for nanoleaf light (#22192)
* Added transition support for nanoleaf * Formatting for comments * Inline comment instead of additional line * Set color_temp before starting transition
This commit is contained in:
parent
906f0113ad
commit
b6ac964df3
@ -10,8 +10,9 @@ import voluptuous as vol
|
|||||||
|
|
||||||
from homeassistant.components.light import (
|
from homeassistant.components.light import (
|
||||||
ATTR_BRIGHTNESS, ATTR_COLOR_TEMP, ATTR_EFFECT, ATTR_HS_COLOR,
|
ATTR_BRIGHTNESS, ATTR_COLOR_TEMP, ATTR_EFFECT, ATTR_HS_COLOR,
|
||||||
PLATFORM_SCHEMA, SUPPORT_BRIGHTNESS, SUPPORT_COLOR, SUPPORT_COLOR_TEMP,
|
ATTR_TRANSITION, PLATFORM_SCHEMA, SUPPORT_BRIGHTNESS,
|
||||||
SUPPORT_EFFECT, Light)
|
SUPPORT_COLOR, SUPPORT_COLOR_TEMP, SUPPORT_EFFECT,
|
||||||
|
SUPPORT_TRANSITION, Light)
|
||||||
from homeassistant.const import CONF_HOST, CONF_NAME, CONF_TOKEN
|
from homeassistant.const import CONF_HOST, CONF_NAME, CONF_TOKEN
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.util import color as color_util
|
from homeassistant.util import color as color_util
|
||||||
@ -32,7 +33,7 @@ CONFIG_FILE = '.nanoleaf.conf'
|
|||||||
ICON = 'mdi:triangle-outline'
|
ICON = 'mdi:triangle-outline'
|
||||||
|
|
||||||
SUPPORT_NANOLEAF = (SUPPORT_BRIGHTNESS | SUPPORT_COLOR_TEMP | SUPPORT_EFFECT |
|
SUPPORT_NANOLEAF = (SUPPORT_BRIGHTNESS | SUPPORT_COLOR_TEMP | SUPPORT_EFFECT |
|
||||||
SUPPORT_COLOR)
|
SUPPORT_COLOR | SUPPORT_TRANSITION)
|
||||||
|
|
||||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||||
vol.Required(CONF_HOST): cv.string,
|
vol.Required(CONF_HOST): cv.string,
|
||||||
@ -171,27 +172,40 @@ class NanoleafLight(Light):
|
|||||||
|
|
||||||
def turn_on(self, **kwargs):
|
def turn_on(self, **kwargs):
|
||||||
"""Instruct the light to turn on."""
|
"""Instruct the light to turn on."""
|
||||||
self._light.on = True
|
|
||||||
brightness = kwargs.get(ATTR_BRIGHTNESS)
|
brightness = kwargs.get(ATTR_BRIGHTNESS)
|
||||||
hs_color = kwargs.get(ATTR_HS_COLOR)
|
hs_color = kwargs.get(ATTR_HS_COLOR)
|
||||||
color_temp_mired = kwargs.get(ATTR_COLOR_TEMP)
|
color_temp_mired = kwargs.get(ATTR_COLOR_TEMP)
|
||||||
effect = kwargs.get(ATTR_EFFECT)
|
effect = kwargs.get(ATTR_EFFECT)
|
||||||
|
transition = kwargs.get(ATTR_TRANSITION)
|
||||||
|
|
||||||
if hs_color:
|
if hs_color:
|
||||||
hue, saturation = hs_color
|
hue, saturation = hs_color
|
||||||
self._light.hue = int(hue)
|
self._light.hue = int(hue)
|
||||||
self._light.saturation = int(saturation)
|
self._light.saturation = int(saturation)
|
||||||
|
|
||||||
if color_temp_mired:
|
if color_temp_mired:
|
||||||
self._light.color_temperature = mired_to_kelvin(color_temp_mired)
|
self._light.color_temperature = mired_to_kelvin(color_temp_mired)
|
||||||
if brightness:
|
|
||||||
self._light.brightness = int(brightness / 2.55)
|
if transition:
|
||||||
|
if brightness: # tune to the required brightness in n seconds
|
||||||
|
self._light.brightness_transition(
|
||||||
|
int(brightness / 2.55), int(transition))
|
||||||
|
else: # If brightness is not specified, assume full brightness
|
||||||
|
self._light.brightness_transition(100, int(transition))
|
||||||
|
else: # If no transition is occurring, turn on the light
|
||||||
|
self._light.on = True
|
||||||
|
if brightness:
|
||||||
|
self._light.brightness = int(brightness / 2.55)
|
||||||
|
|
||||||
if effect:
|
if effect:
|
||||||
self._light.effect = effect
|
self._light.effect = effect
|
||||||
|
|
||||||
def turn_off(self, **kwargs):
|
def turn_off(self, **kwargs):
|
||||||
"""Instruct the light to turn off."""
|
"""Instruct the light to turn off."""
|
||||||
self._light.on = False
|
transition = kwargs.get(ATTR_TRANSITION)
|
||||||
|
if transition:
|
||||||
|
self._light.brightness_transition(0, int(transition))
|
||||||
|
else:
|
||||||
|
self._light.on = False
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Fetch new state data for this light."""
|
"""Fetch new state data for this light."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user