From 8d48272cbdbe5e7a30d496823d6a2b092bdede05 Mon Sep 17 00:00:00 2001 From: Jesse Hills Date: Fri, 16 Feb 2018 18:57:58 +1300 Subject: [PATCH] Add effects to iGlo Lights (#12365) * Add effects to iGlo Lights Simplify state variables to library * Fix lint issues --- homeassistant/components/light/iglo.py | 48 +++++++++++++++----------- requirements_all.txt | 2 +- 2 files changed, 28 insertions(+), 22 deletions(-) diff --git a/homeassistant/components/light/iglo.py b/homeassistant/components/light/iglo.py index ba78546cf77..e39b5dbf540 100644 --- a/homeassistant/components/light/iglo.py +++ b/homeassistant/components/light/iglo.py @@ -10,13 +10,14 @@ import math import voluptuous as vol from homeassistant.components.light import ( - ATTR_BRIGHTNESS, ATTR_COLOR_TEMP, ATTR_RGB_COLOR, PLATFORM_SCHEMA, - SUPPORT_BRIGHTNESS, SUPPORT_COLOR_TEMP, SUPPORT_RGB_COLOR, Light) + ATTR_BRIGHTNESS, ATTR_COLOR_TEMP, ATTR_EFFECT, ATTR_RGB_COLOR, + SUPPORT_BRIGHTNESS, SUPPORT_COLOR_TEMP, SUPPORT_RGB_COLOR, SUPPORT_EFFECT, + PLATFORM_SCHEMA, Light) from homeassistant.const import CONF_HOST, CONF_NAME, CONF_PORT import homeassistant.helpers.config_validation as cv import homeassistant.util.color as color_util -REQUIREMENTS = ['iglo==1.1.3'] +REQUIREMENTS = ['iglo==1.2.5'] _LOGGER = logging.getLogger(__name__) @@ -46,10 +47,6 @@ class IGloLamp(Light): from iglo import Lamp self._name = name self._lamp = Lamp(0, host, port) - self._on = True - self._brightness = 255 - self._rgb = (0, 0, 0) - self._color_temp = 0 @property def name(self): @@ -59,12 +56,13 @@ class IGloLamp(Light): @property def brightness(self): """Return the brightness of this light between 0..255.""" - return int((self._brightness / 200.0) * 255) + return int((self._lamp.state['brightness'] / 200.0) * 255) @property def color_temp(self): """Return the color temperature.""" - return color_util.color_temperature_kelvin_to_mired(self._color_temp) + return color_util.color_temperature_kelvin_to_mired( + self._lamp.state['white']) @property def min_mireds(self): @@ -81,21 +79,32 @@ class IGloLamp(Light): @property def rgb_color(self): """Return the RGB value.""" - return self._rgb + return self._lamp.state['rgb'] + + @property + def effect(self): + """Return the current effect.""" + return self._lamp.state['effect'] + + @property + def effect_list(self): + """Return the list of supported effects.""" + return self._lamp.effect_list @property def supported_features(self): """Flag supported features.""" - return SUPPORT_BRIGHTNESS | SUPPORT_COLOR_TEMP | SUPPORT_RGB_COLOR + return (SUPPORT_BRIGHTNESS | SUPPORT_COLOR_TEMP | + SUPPORT_RGB_COLOR | SUPPORT_EFFECT) @property def is_on(self): """Return true if light is on.""" - return self._on + return self._lamp.state['on'] def turn_on(self, **kwargs): """Turn the light on.""" - if not self._on: + if not self.is_on: self._lamp.switch(True) if ATTR_BRIGHTNESS in kwargs: brightness = int((kwargs[ATTR_BRIGHTNESS] / 255.0) * 200.0) @@ -113,14 +122,11 @@ class IGloLamp(Light): self._lamp.white(kelvin) return + if ATTR_EFFECT in kwargs: + effect = kwargs[ATTR_EFFECT] + self._lamp.effect(effect) + return + def turn_off(self, **kwargs): """Turn the light off.""" self._lamp.switch(False) - - def update(self): - """Update light status.""" - state = self._lamp.state() - self._on = state['on'] - self._brightness = state['brightness'] - self._rgb = state['rgb'] - self._color_temp = state['white'] diff --git a/requirements_all.txt b/requirements_all.txt index fad3434f712..a77021d2297 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -394,7 +394,7 @@ https://github.com/wokar/pylgnetcast/archive/v0.2.0.zip#pylgnetcast==0.2.0 # i2csense==0.0.4 # homeassistant.components.light.iglo -iglo==1.1.3 +iglo==1.2.5 # homeassistant.components.ihc ihcsdk==2.1.1