class IGloLamp(Light): """Representation of an iGlo light.""" def __init__(self, name, host, port): """Initialize the light.""" from iglo import Lamp self._name = name self._lamp = Lamp(0, host, port) @property def name(self): """Return the name of the light.""" return self._name @property def brightness(self): """Return the brightness of this light between 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._lamp.state()['white']) @property def min_mireds(self): """Return the coldest color_temp that this light supports.""" return math.ceil(color_util.color_temperature_kelvin_to_mired( self._lamp.max_kelvin)) @property def max_mireds(self): """Return the warmest color_temp that this light supports.""" return math.ceil(color_util.color_temperature_kelvin_to_mired( self._lamp.min_kelvin)) @property def hs_color(self): """Return the hs value.""" return color_util.color_RGB_to_hsv(*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_COLOR | SUPPORT_EFFECT) @property def is_on(self): """Return true if light is on.""" return self._lamp.state()['on'] def turn_on(self, **kwargs): """Turn the light on.""" if not self.is_on: self._lamp.switch(True) if ATTR_BRIGHTNESS in kwargs: brightness = int((kwargs[ATTR_BRIGHTNESS] / 255.0) * 200.0) self._lamp.brightness(brightness) return if ATTR_HS_COLOR in kwargs: rgb = color_util.color_hs_to_RGB(*kwargs[ATTR_HS_COLOR]) self._lamp.rgb(*rgb) return if ATTR_COLOR_TEMP in kwargs: kelvin = int(color_util.color_temperature_mired_to_kelvin( kwargs[ATTR_COLOR_TEMP])) 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)
class IGloLamp(Light): """Representation of an iGlo light.""" def __init__(self, name, host, port): """Initialize the 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): """Return the name of the light.""" return self._name @property def brightness(self): """Return the brightness of this light between 0..255.""" return int((self._brightness / 200.0) * 255) @property def color_temp(self): """Return the color temperature.""" return color_util.color_temperature_kelvin_to_mired(self._color_temp) @property def min_mireds(self): """Return the coldest color_temp that this light supports.""" return math.ceil(color_util.color_temperature_kelvin_to_mired( self._lamp.max_kelvin)) @property def max_mireds(self): """Return the warmest color_temp that this light supports.""" return math.ceil(color_util.color_temperature_kelvin_to_mired( self._lamp.min_kelvin)) @property def rgb_color(self): """Return the RGB value.""" return self._rgb @property def supported_features(self): """Flag supported features.""" return SUPPORT_BRIGHTNESS | SUPPORT_COLOR_TEMP | SUPPORT_RGB_COLOR @property def is_on(self): """Return true if light is on.""" return self._on def turn_on(self, **kwargs): """Turn the light on.""" if not self._on: self._lamp.switch(True) if ATTR_BRIGHTNESS in kwargs: brightness = int((kwargs[ATTR_BRIGHTNESS] / 255.0) * 200.0) self._lamp.brightness(brightness) return if ATTR_RGB_COLOR in kwargs: rgb = kwargs[ATTR_RGB_COLOR] self._lamp.rgb(*rgb) return if ATTR_COLOR_TEMP in kwargs: kelvin = int(color_util.color_temperature_mired_to_kelvin( kwargs[ATTR_COLOR_TEMP])) self._lamp.white(kelvin) 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']
class IGloLamp(Light): """Representation of an iGlo light.""" def __init__(self, name, host, port): """Initialize the light.""" from iglo import Lamp self._name = name self._lamp = Lamp(0, host, port) @property def name(self): """Return the name of the light.""" return self._name @property def brightness(self): """Return the brightness of this light between 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._lamp.state()['white']) @property def min_mireds(self): """Return the coldest color_temp that this light supports.""" return math.ceil( color_util.color_temperature_kelvin_to_mired( self._lamp.max_kelvin)) @property def max_mireds(self): """Return the warmest color_temp that this light supports.""" return math.ceil( color_util.color_temperature_kelvin_to_mired( self._lamp.min_kelvin)) @property def hs_color(self): """Return the hs value.""" return color_util.color_RGB_to_hs(*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_COLOR | SUPPORT_EFFECT) @property def is_on(self): """Return true if light is on.""" return self._lamp.state()['on'] def turn_on(self, **kwargs): """Turn the light on.""" if not self.is_on: self._lamp.switch(True) if ATTR_BRIGHTNESS in kwargs: brightness = int((kwargs[ATTR_BRIGHTNESS] / 255.0) * 200.0) self._lamp.brightness(brightness) return if ATTR_HS_COLOR in kwargs: rgb = color_util.color_hs_to_RGB(*kwargs[ATTR_HS_COLOR]) self._lamp.rgb(*rgb) return if ATTR_COLOR_TEMP in kwargs: kelvin = int( color_util.color_temperature_mired_to_kelvin( kwargs[ATTR_COLOR_TEMP])) 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)
class IGloLamp(LightEntity): """Representation of an iGlo light.""" _attr_supported_color_modes = {ColorMode.COLOR_TEMP, ColorMode.HS} _attr_supported_features = LightEntityFeature.EFFECT def __init__(self, name, host, port): """Initialize the light.""" self._name = name self._lamp = Lamp(0, host, port) @property def name(self): """Return the name of the light.""" return self._name @property def brightness(self): """Return the brightness of this light between 0..255.""" return int((self._lamp.state()["brightness"] / 200.0) * 255) @property def color_mode(self) -> ColorMode: """Return the color mode of the light.""" if self._lamp.state()["mode"] == MODE_WHITE: return ColorMode.COLOR_TEMP # The iglo library reports MODE_WHITE when an effect is active, this is not # supported by Home Assistant, just report ColorMode.HS return ColorMode.HS @property def color_temp(self): """Return the color temperature.""" return color_util.color_temperature_kelvin_to_mired( self._lamp.state()["white"]) @property def min_mireds(self): """Return the coldest color_temp that this light supports.""" return math.ceil( color_util.color_temperature_kelvin_to_mired( self._lamp.max_kelvin)) @property def max_mireds(self): """Return the warmest color_temp that this light supports.""" return math.ceil( color_util.color_temperature_kelvin_to_mired( self._lamp.min_kelvin)) @property def hs_color(self): """Return the hs value.""" return color_util.color_RGB_to_hs(*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 is_on(self): """Return true if light is on.""" return self._lamp.state()["on"] def turn_on(self, **kwargs): """Turn the light on.""" if not self.is_on: self._lamp.switch(True) if ATTR_BRIGHTNESS in kwargs: brightness = int((kwargs[ATTR_BRIGHTNESS] / 255.0) * 200.0) self._lamp.brightness(brightness) return if ATTR_HS_COLOR in kwargs: rgb = color_util.color_hs_to_RGB(*kwargs[ATTR_HS_COLOR]) self._lamp.rgb(*rgb) return if ATTR_COLOR_TEMP in kwargs: kelvin = int( color_util.color_temperature_mired_to_kelvin( kwargs[ATTR_COLOR_TEMP])) 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)