From 0c47434aad46ee4a313f846968b2ad429f97f19b Mon Sep 17 00:00:00 2001 From: Thomas Friedel Date: Wed, 23 Nov 2016 07:10:45 +0100 Subject: [PATCH] Change Osram to use Github lightify dep (#4256) * used MindrustUK's version ( https://github.com/MindrustUK/python-lightify/commits/master/osramlightify.py ) from Oct 2, 2016 and changed the REQUIRMENTS line to use the fixed lightify component with thread safety fixes * reformatted long lines * updated osramlightify requirements in requirements_all.txt * ran script gen_requirements_all.py * rerun requirements gen script on linux * fixed some inspection warnings * zip file points to a specific commit * no requests to lights in properties, instead instance variables are update in update method * regenerated requirements_all.txt * removed call to update from is_on() property --- .../components/light/osramlightify.py | 108 +++++++++++++----- requirements_all.txt | 6 +- 2 files changed, 80 insertions(+), 34 deletions(-) diff --git a/homeassistant/components/light/osramlightify.py b/homeassistant/components/light/osramlightify.py index cdcaef8eb50..55d96236f2d 100644 --- a/homeassistant/components/light/osramlightify.py +++ b/homeassistant/components/light/osramlightify.py @@ -19,7 +19,8 @@ from homeassistant.components.light import ( SUPPORT_COLOR_TEMP, SUPPORT_RGB_COLOR, SUPPORT_TRANSITION, PLATFORM_SCHEMA) import homeassistant.helpers.config_validation as cv -REQUIREMENTS = ['lightify==1.0.3'] +REQUIREMENTS = ['https://github.com/tfriedel/python-lightify/archive/' + 'd6eadcf311e6e21746182d1480e97b350dda2b3e.zip#lightify==1.0.4'] _LOGGER = logging.getLogger(__name__) @@ -92,37 +93,43 @@ class OsramLightifyLight(Light): self._light = light self._light_id = light_id self.update_lights = update_lights + self._brightness = 0 + self._rgb = (0, 0, 0) + self._name = "" + self._temperature = TEMP_MIN + self._state = False + self.update() @property def name(self): """Return the name of the device if any.""" - return self._light.name() + return self._name @property def rgb_color(self): """Last RGB color value set.""" - return self._light.rgb() + _LOGGER.debug("rgb_color light state for light: %s is: %s %s %s ", + self._name, self._rgb[0], self._rgb[1], self._rgb[2]) + return self._rgb @property def color_temp(self): """Return the color temperature.""" - o_temp = self._light.temp() - temperature = int(TEMP_MIN_HASS + (TEMP_MAX_HASS - TEMP_MIN_HASS) * - (o_temp - TEMP_MIN) / (TEMP_MAX - TEMP_MIN)) - return temperature + return self._temperature @property def brightness(self): """Brightness of this light between 0..255.""" - return int(self._light.lum() * 2.55) + _LOGGER.debug("brightness for light %s is: %s", + self._name, self._brightness) + return self._brightness @property def is_on(self): """Update Status to True if device is on.""" - self.update_lights() _LOGGER.debug("is_on light state for light: %s is: %s", - self._light.name(), self._light.on()) - return self._light.on() + self._name, self._state) + return self._state @property def supported_features(self): @@ -131,47 +138,86 @@ class OsramLightifyLight(Light): def turn_on(self, **kwargs): """Turn the device on.""" - brightness = 100 - if self.brightness: - brightness = int(self.brightness / 2.55) + _LOGGER.debug("turn_on Attempting to turn on light: %s ", + self._name) + + self._light.set_onoff(1) + self._state = self._light.on() if ATTR_TRANSITION in kwargs: - fade = kwargs[ATTR_TRANSITION] * 10 + transition = kwargs[ATTR_TRANSITION] * 10 + _LOGGER.debug("turn_on requested transition time for light:" + " %s is: %s ", + self._name, transition) else: - fade = 0 + transition = 0 + _LOGGER.debug("turn_on requested transition time for light:" + " %s is: %s ", + self._name, transition) if ATTR_RGB_COLOR in kwargs: red, green, blue = kwargs[ATTR_RGB_COLOR] - self._light.set_rgb(red, green, blue, fade) - - if ATTR_BRIGHTNESS in kwargs: - brightness = int(kwargs[ATTR_BRIGHTNESS] / 2.55) + _LOGGER.debug("turn_on requested ATTR_RGB_COLOR for light:" + " %s is: %s %s %s ", + self._name, red, green, blue) + self._light.set_rgb(red, green, blue, transition) if ATTR_COLOR_TEMP in kwargs: color_t = kwargs[ATTR_COLOR_TEMP] kelvin = int(((TEMP_MAX - TEMP_MIN) * (color_t - TEMP_MIN_HASS) / (TEMP_MAX_HASS - TEMP_MIN_HASS)) + TEMP_MIN) - self._light.set_temperature(kelvin, fade) + _LOGGER.debug("turn_on requested set_temperature for light:" + " %s: %s ", self._name, kelvin) + self._light.set_temperature(kelvin, transition) - effect = kwargs.get(ATTR_EFFECT) - if effect == EFFECT_RANDOM: - self._light.set_rgb(random.randrange(0, 255), - random.randrange(0, 255), - random.randrange(0, 255), - fade) + if ATTR_BRIGHTNESS in kwargs: + self._brightness = kwargs[ATTR_BRIGHTNESS] + _LOGGER.debug("turn_on requested brightness for light: %s is: %s ", + self._name, self._brightness) + self._brightness = self._light.set_luminance( + int(self._brightness / 2.55), + transition) + + if ATTR_EFFECT in kwargs: + effect = kwargs.get(ATTR_EFFECT) + if effect == EFFECT_RANDOM: + self._light.set_rgb(random.randrange(0, 255), + random.randrange(0, 255), + random.randrange(0, 255), + transition) + _LOGGER.debug("turn_on requested random effect for light:" + " %s with transition %s ", + self._name, transition) - self._light.set_luminance(brightness, fade) self.update_ha_state() def turn_off(self, **kwargs): """Turn the device off.""" + _LOGGER.debug("turn_off Attempting to turn off light: %s ", + self._name) if ATTR_TRANSITION in kwargs: - fade = kwargs[ATTR_TRANSITION] * 10 + transition = kwargs[ATTR_TRANSITION] * 10 + _LOGGER.debug("turn_off requested transition time for light:" + " %s is: %s ", + self._name, transition) + self._light.set_luminance(0, transition) else: - fade = 0 - self._light.set_luminance(0, fade) + transition = 0 + _LOGGER.debug("turn_off requested transition time for light:" + " %s is: %s ", + self._name, transition) + self._light.set_onoff(0) + self._state = self._light.on() + self.update_ha_state() def update(self): """Synchronize state with bridge.""" self.update_lights(no_throttle=True) + self._brightness = int(self._light.lum() * 2.55) + self._name = self._light.name() + self._rgb = self._light.rgb() + o_temp = self._light.temp() + self._temperature = int(TEMP_MIN_HASS + (TEMP_MAX_HASS - TEMP_MIN_HASS) + * (o_temp - TEMP_MIN) / (TEMP_MAX - TEMP_MIN)) + self._state = self._light.on() diff --git a/requirements_all.txt b/requirements_all.txt index 80572e80016..d948e1958c2 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -226,6 +226,9 @@ https://github.com/robbiet480/pygtfs/archive/00546724e4bbcb3053110d844ca44e22462 # homeassistant.components.scene.hunterdouglas_powerview https://github.com/sander76/powerviewApi/archive/246e782d60d5c0addcc98d7899a0186f9d5640b0.zip#powerviewApi==0.3.15 +# homeassistant.components.light.osramlightify +https://github.com/tfriedel/python-lightify/archive/d6eadcf311e6e21746182d1480e97b350dda2b3e.zip#lightify==1.0.4 + # homeassistant.components.mysensors https://github.com/theolind/pymysensors/archive/0b705119389be58332f17753c53167f551254b6c.zip#pymysensors==0.8 @@ -258,9 +261,6 @@ libnacl==1.5.0 # homeassistant.components.light.lifx liffylights==0.9.4 -# homeassistant.components.light.osramlightify -lightify==1.0.3 - # homeassistant.components.light.limitlessled limitlessled==1.0.2