Upgrade lightify to 1.0.6.1 (#11545)
This commit is contained in:
parent
8313225b40
commit
f56b3d8e9c
2 changed files with 51 additions and 61 deletions
|
@ -4,34 +4,36 @@ Support for Osram Lightify.
|
||||||
For more details about this platform, please refer to the documentation at
|
For more details about this platform, please refer to the documentation at
|
||||||
https://home-assistant.io/components/light.osramlightify/
|
https://home-assistant.io/components/light.osramlightify/
|
||||||
"""
|
"""
|
||||||
import logging
|
|
||||||
import socket
|
|
||||||
import random
|
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
import logging
|
||||||
|
import random
|
||||||
|
import socket
|
||||||
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant import util
|
from homeassistant import util
|
||||||
from homeassistant.const import CONF_HOST
|
|
||||||
from homeassistant.components.light import (
|
from homeassistant.components.light import (
|
||||||
Light, ATTR_BRIGHTNESS, ATTR_COLOR_TEMP, ATTR_EFFECT, ATTR_RGB_COLOR,
|
ATTR_BRIGHTNESS, ATTR_COLOR_TEMP, ATTR_EFFECT, ATTR_RGB_COLOR,
|
||||||
ATTR_XY_COLOR, ATTR_TRANSITION, EFFECT_RANDOM, SUPPORT_BRIGHTNESS,
|
ATTR_TRANSITION, ATTR_XY_COLOR, EFFECT_RANDOM, PLATFORM_SCHEMA,
|
||||||
SUPPORT_EFFECT, SUPPORT_XY_COLOR, SUPPORT_COLOR_TEMP, SUPPORT_RGB_COLOR,
|
SUPPORT_BRIGHTNESS, SUPPORT_COLOR_TEMP, SUPPORT_EFFECT, SUPPORT_RGB_COLOR,
|
||||||
SUPPORT_TRANSITION, PLATFORM_SCHEMA)
|
SUPPORT_TRANSITION, SUPPORT_XY_COLOR, Light)
|
||||||
from homeassistant.util.color import (
|
from homeassistant.const import CONF_HOST
|
||||||
color_temperature_mired_to_kelvin, color_temperature_kelvin_to_mired,
|
|
||||||
color_xy_brightness_to_RGB)
|
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
|
from homeassistant.util.color import (
|
||||||
|
color_temperature_kelvin_to_mired, color_temperature_mired_to_kelvin,
|
||||||
|
color_xy_brightness_to_RGB)
|
||||||
|
|
||||||
REQUIREMENTS = ['lightify==1.0.6']
|
REQUIREMENTS = ['lightify==1.0.6.1']
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
MIN_TIME_BETWEEN_SCANS = timedelta(seconds=10)
|
CONF_ALLOW_LIGHTIFY_GROUPS = 'allow_lightify_groups'
|
||||||
MIN_TIME_BETWEEN_FORCED_SCANS = timedelta(milliseconds=100)
|
|
||||||
CONF_ALLOW_LIGHTIFY_GROUPS = "allow_lightify_groups"
|
|
||||||
DEFAULT_ALLOW_LIGHTIFY_GROUPS = True
|
DEFAULT_ALLOW_LIGHTIFY_GROUPS = True
|
||||||
|
|
||||||
|
MIN_TIME_BETWEEN_FORCED_SCANS = timedelta(milliseconds=100)
|
||||||
|
MIN_TIME_BETWEEN_SCANS = timedelta(seconds=10)
|
||||||
|
|
||||||
SUPPORT_OSRAMLIGHTIFY = (SUPPORT_BRIGHTNESS | SUPPORT_COLOR_TEMP |
|
SUPPORT_OSRAMLIGHTIFY = (SUPPORT_BRIGHTNESS | SUPPORT_COLOR_TEMP |
|
||||||
SUPPORT_EFFECT | SUPPORT_RGB_COLOR |
|
SUPPORT_EFFECT | SUPPORT_RGB_COLOR |
|
||||||
SUPPORT_TRANSITION | SUPPORT_XY_COLOR)
|
SUPPORT_TRANSITION | SUPPORT_XY_COLOR)
|
||||||
|
@ -46,20 +48,19 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
"""Set up the Osram Lightify lights."""
|
"""Set up the Osram Lightify lights."""
|
||||||
import lightify
|
import lightify
|
||||||
|
|
||||||
host = config.get(CONF_HOST)
|
host = config.get(CONF_HOST)
|
||||||
add_groups = config.get(CONF_ALLOW_LIGHTIFY_GROUPS)
|
add_groups = config.get(CONF_ALLOW_LIGHTIFY_GROUPS)
|
||||||
if host:
|
|
||||||
try:
|
try:
|
||||||
bridge = lightify.Lightify(host)
|
bridge = lightify.Lightify(host)
|
||||||
except socket.error as err:
|
except socket.error as err:
|
||||||
msg = "Error connecting to bridge: {} due to: {}".format(
|
msg = "Error connecting to bridge: {} due to: {}".format(
|
||||||
host, str(err))
|
host, str(err))
|
||||||
_LOGGER.exception(msg)
|
_LOGGER.exception(msg)
|
||||||
return False
|
return
|
||||||
setup_bridge(bridge, add_devices, add_groups)
|
|
||||||
else:
|
setup_bridge(bridge, add_devices, add_groups)
|
||||||
_LOGGER.error("No host found in configuration")
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
def setup_bridge(bridge, add_devices_callback, add_groups):
|
def setup_bridge(bridge, add_devices_callback, add_groups):
|
||||||
|
@ -73,17 +74,16 @@ def setup_bridge(bridge, add_devices_callback, add_groups):
|
||||||
bridge.update_all_light_status()
|
bridge.update_all_light_status()
|
||||||
bridge.update_group_list()
|
bridge.update_group_list()
|
||||||
except TimeoutError:
|
except TimeoutError:
|
||||||
_LOGGER.error('Timeout during updating of lights.')
|
_LOGGER.error("Timeout during updating of lights")
|
||||||
except OSError:
|
except OSError:
|
||||||
_LOGGER.error('OSError during updating of lights.')
|
_LOGGER.error("OSError during updating of lights")
|
||||||
|
|
||||||
new_lights = []
|
new_lights = []
|
||||||
|
|
||||||
for (light_id, light) in bridge.lights().items():
|
for (light_id, light) in bridge.lights().items():
|
||||||
if light_id not in lights:
|
if light_id not in lights:
|
||||||
osram_light = OsramLightifyLight(light_id, light,
|
osram_light = OsramLightifyLight(
|
||||||
update_lights)
|
light_id, light, update_lights)
|
||||||
|
|
||||||
lights[light_id] = osram_light
|
lights[light_id] = osram_light
|
||||||
new_lights.append(osram_light)
|
new_lights.append(osram_light)
|
||||||
else:
|
else:
|
||||||
|
@ -92,8 +92,8 @@ def setup_bridge(bridge, add_devices_callback, add_groups):
|
||||||
if add_groups:
|
if add_groups:
|
||||||
for (group_name, group) in bridge.groups().items():
|
for (group_name, group) in bridge.groups().items():
|
||||||
if group_name not in lights:
|
if group_name not in lights:
|
||||||
osram_group = OsramLightifyGroup(group, bridge,
|
osram_group = OsramLightifyGroup(
|
||||||
update_lights)
|
group, bridge, update_lights)
|
||||||
lights[group_name] = osram_group
|
lights[group_name] = osram_group
|
||||||
new_lights.append(osram_group)
|
new_lights.append(osram_group)
|
||||||
else:
|
else:
|
||||||
|
@ -106,10 +106,10 @@ def setup_bridge(bridge, add_devices_callback, add_groups):
|
||||||
|
|
||||||
|
|
||||||
class Luminary(Light):
|
class Luminary(Light):
|
||||||
"""ABS for Lightify Lights and Groups."""
|
"""Representation of Luminary Lights and Groups."""
|
||||||
|
|
||||||
def __init__(self, luminary, update_lights):
|
def __init__(self, luminary, update_lights):
|
||||||
"""Init Luminary object."""
|
"""Initize a Luminary light."""
|
||||||
self.update_lights = update_lights
|
self.update_lights = update_lights
|
||||||
self._luminary = luminary
|
self._luminary = luminary
|
||||||
self._brightness = None
|
self._brightness = None
|
||||||
|
@ -141,7 +141,7 @@ class Luminary(Light):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_on(self):
|
def is_on(self):
|
||||||
"""Update Status to True if device is on."""
|
"""Update status to True if device is on."""
|
||||||
return self._state
|
return self._state
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -170,8 +170,7 @@ class Luminary(Light):
|
||||||
_LOGGER.debug("turn_on requested brightness for light: %s is: %s ",
|
_LOGGER.debug("turn_on requested brightness for light: %s is: %s ",
|
||||||
self._name, self._brightness)
|
self._name, self._brightness)
|
||||||
self._luminary.set_luminance(
|
self._luminary.set_luminance(
|
||||||
int(self._brightness / 2.55),
|
int(self._brightness / 2.55), transition)
|
||||||
transition)
|
|
||||||
else:
|
else:
|
||||||
self._luminary.set_onoff(1)
|
self._luminary.set_onoff(1)
|
||||||
|
|
||||||
|
@ -187,8 +186,7 @@ class Luminary(Light):
|
||||||
_LOGGER.debug("turn_on requested ATTR_XY_COLOR for light:"
|
_LOGGER.debug("turn_on requested ATTR_XY_COLOR for light:"
|
||||||
" %s is: %s,%s", self._name, x_mired, y_mired)
|
" %s is: %s,%s", self._name, x_mired, y_mired)
|
||||||
red, green, blue = color_xy_brightness_to_RGB(
|
red, green, blue = color_xy_brightness_to_RGB(
|
||||||
x_mired, y_mired, self._brightness
|
x_mired, y_mired, self._brightness)
|
||||||
)
|
|
||||||
self._luminary.set_rgb(red, green, blue, transition)
|
self._luminary.set_rgb(red, green, blue, transition)
|
||||||
|
|
||||||
if ATTR_COLOR_TEMP in kwargs:
|
if ATTR_COLOR_TEMP in kwargs:
|
||||||
|
@ -201,10 +199,9 @@ class Luminary(Light):
|
||||||
if ATTR_EFFECT in kwargs:
|
if ATTR_EFFECT in kwargs:
|
||||||
effect = kwargs.get(ATTR_EFFECT)
|
effect = kwargs.get(ATTR_EFFECT)
|
||||||
if effect == EFFECT_RANDOM:
|
if effect == EFFECT_RANDOM:
|
||||||
self._luminary.set_rgb(random.randrange(0, 255),
|
self._luminary.set_rgb(
|
||||||
random.randrange(0, 255),
|
random.randrange(0, 255), random.randrange(0, 255),
|
||||||
random.randrange(0, 255),
|
random.randrange(0, 255), transition)
|
||||||
transition)
|
|
||||||
_LOGGER.debug("turn_on requested random effect for light: "
|
_LOGGER.debug("turn_on requested random effect for light: "
|
||||||
"%s with transition %s", self._name, transition)
|
"%s with transition %s", self._name, transition)
|
||||||
|
|
||||||
|
@ -212,19 +209,16 @@ class Luminary(Light):
|
||||||
|
|
||||||
def turn_off(self, **kwargs):
|
def turn_off(self, **kwargs):
|
||||||
"""Turn the device off."""
|
"""Turn the device off."""
|
||||||
_LOGGER.debug("turn_off Attempting to turn off light: %s ",
|
_LOGGER.debug("Attempting to turn off light: %s", self._name)
|
||||||
self._name)
|
|
||||||
if ATTR_TRANSITION in kwargs:
|
if ATTR_TRANSITION in kwargs:
|
||||||
transition = int(kwargs[ATTR_TRANSITION] * 10)
|
transition = int(kwargs[ATTR_TRANSITION] * 10)
|
||||||
_LOGGER.debug("turn_off requested transition time for light:"
|
_LOGGER.debug("turn_off requested transition time for light:"
|
||||||
" %s is: %s ",
|
" %s is: %s ", self._name, transition)
|
||||||
self._name, transition)
|
|
||||||
self._luminary.set_luminance(0, transition)
|
self._luminary.set_luminance(0, transition)
|
||||||
else:
|
else:
|
||||||
transition = 0
|
transition = 0
|
||||||
_LOGGER.debug("turn_off requested transition time for light:"
|
_LOGGER.debug("turn_off requested transition time for light:"
|
||||||
" %s is: %s ",
|
" %s is: %s ", self._name, transition)
|
||||||
self._name, transition)
|
|
||||||
self._luminary.set_onoff(0)
|
self._luminary.set_onoff(0)
|
||||||
self.schedule_update_ha_state()
|
self.schedule_update_ha_state()
|
||||||
|
|
||||||
|
@ -238,12 +232,12 @@ class OsramLightifyLight(Luminary):
|
||||||
"""Representation of an Osram Lightify Light."""
|
"""Representation of an Osram Lightify Light."""
|
||||||
|
|
||||||
def __init__(self, light_id, light, update_lights):
|
def __init__(self, light_id, light, update_lights):
|
||||||
"""Initialize the light."""
|
"""Initialize the Lightify light."""
|
||||||
self._light_id = light_id
|
self._light_id = light_id
|
||||||
super().__init__(light, update_lights)
|
super().__init__(light, update_lights)
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Update status of a Light."""
|
"""Update status of a light."""
|
||||||
super().update()
|
super().update()
|
||||||
self._state = self._luminary.on()
|
self._state = self._luminary.on()
|
||||||
self._rgb = self._luminary.rgb()
|
self._rgb = self._luminary.rgb()
|
||||||
|
@ -252,8 +246,7 @@ class OsramLightifyLight(Luminary):
|
||||||
self._temperature = None
|
self._temperature = None
|
||||||
else:
|
else:
|
||||||
self._temperature = color_temperature_kelvin_to_mired(
|
self._temperature = color_temperature_kelvin_to_mired(
|
||||||
self._luminary.temp()
|
self._luminary.temp())
|
||||||
)
|
|
||||||
self._brightness = int(self._luminary.lum() * 2.55)
|
self._brightness = int(self._luminary.lum() * 2.55)
|
||||||
|
|
||||||
|
|
||||||
|
@ -261,16 +254,13 @@ class OsramLightifyGroup(Luminary):
|
||||||
"""Representation of an Osram Lightify Group."""
|
"""Representation of an Osram Lightify Group."""
|
||||||
|
|
||||||
def __init__(self, group, bridge, update_lights):
|
def __init__(self, group, bridge, update_lights):
|
||||||
"""Init light group."""
|
"""Initialize the Lightify light group."""
|
||||||
self._bridge = bridge
|
self._bridge = bridge
|
||||||
self._light_ids = []
|
self._light_ids = []
|
||||||
super().__init__(group, update_lights)
|
super().__init__(group, update_lights)
|
||||||
|
|
||||||
def _get_state(self):
|
def _get_state(self):
|
||||||
"""Get state of group.
|
"""Get state of group."""
|
||||||
|
|
||||||
The group is on, if any of the lights is on.
|
|
||||||
"""
|
|
||||||
lights = self._bridge.lights()
|
lights = self._bridge.lights()
|
||||||
return any(lights[light_id].on() for light_id in self._light_ids)
|
return any(lights[light_id].on() for light_id in self._light_ids)
|
||||||
|
|
||||||
|
|
|
@ -438,7 +438,7 @@ libsoundtouch==0.7.2
|
||||||
liffylights==0.9.4
|
liffylights==0.9.4
|
||||||
|
|
||||||
# homeassistant.components.light.osramlightify
|
# homeassistant.components.light.osramlightify
|
||||||
lightify==1.0.6
|
lightify==1.0.6.1
|
||||||
|
|
||||||
# homeassistant.components.light.limitlessled
|
# homeassistant.components.light.limitlessled
|
||||||
limitlessled==1.0.8
|
limitlessled==1.0.8
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue