Migrate iglo light to color_mode (#69278)
This commit is contained in:
parent
2e84cdb16f
commit
c3a2eedf0b
1 changed files with 15 additions and 8 deletions
|
@ -4,6 +4,7 @@ from __future__ import annotations
|
||||||
import math
|
import math
|
||||||
|
|
||||||
from iglo import Lamp
|
from iglo import Lamp
|
||||||
|
from iglo.lamp import MODE_WHITE
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components.light import (
|
from homeassistant.components.light import (
|
||||||
|
@ -11,10 +12,9 @@ from homeassistant.components.light import (
|
||||||
ATTR_COLOR_TEMP,
|
ATTR_COLOR_TEMP,
|
||||||
ATTR_EFFECT,
|
ATTR_EFFECT,
|
||||||
ATTR_HS_COLOR,
|
ATTR_HS_COLOR,
|
||||||
|
COLOR_MODE_COLOR_TEMP,
|
||||||
|
COLOR_MODE_HS,
|
||||||
PLATFORM_SCHEMA,
|
PLATFORM_SCHEMA,
|
||||||
SUPPORT_BRIGHTNESS,
|
|
||||||
SUPPORT_COLOR,
|
|
||||||
SUPPORT_COLOR_TEMP,
|
|
||||||
SUPPORT_EFFECT,
|
SUPPORT_EFFECT,
|
||||||
LightEntity,
|
LightEntity,
|
||||||
)
|
)
|
||||||
|
@ -53,6 +53,9 @@ def setup_platform(
|
||||||
class IGloLamp(LightEntity):
|
class IGloLamp(LightEntity):
|
||||||
"""Representation of an iGlo light."""
|
"""Representation of an iGlo light."""
|
||||||
|
|
||||||
|
_attr_supported_color_modes = {COLOR_MODE_COLOR_TEMP, COLOR_MODE_HS}
|
||||||
|
_attr_supported_features = SUPPORT_EFFECT
|
||||||
|
|
||||||
def __init__(self, name, host, port):
|
def __init__(self, name, host, port):
|
||||||
"""Initialize the light."""
|
"""Initialize the light."""
|
||||||
|
|
||||||
|
@ -69,6 +72,15 @@ class IGloLamp(LightEntity):
|
||||||
"""Return the brightness of this light between 0..255."""
|
"""Return the brightness of this light between 0..255."""
|
||||||
return int((self._lamp.state()["brightness"] / 200.0) * 255)
|
return int((self._lamp.state()["brightness"] / 200.0) * 255)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def color_mode(self) -> str | None:
|
||||||
|
"""Return the color mode of the light."""
|
||||||
|
if self._lamp.state()["mode"] == MODE_WHITE:
|
||||||
|
return COLOR_MODE_COLOR_TEMP
|
||||||
|
# The iglo library reports MODE_WHITE when an effect is active, this is not
|
||||||
|
# supported by Home Assistant, just report COLOR_MODE_HS
|
||||||
|
return COLOR_MODE_HS
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def color_temp(self):
|
def color_temp(self):
|
||||||
"""Return the color temperature."""
|
"""Return the color temperature."""
|
||||||
|
@ -103,11 +115,6 @@ class IGloLamp(LightEntity):
|
||||||
"""Return the list of supported effects."""
|
"""Return the list of supported effects."""
|
||||||
return self._lamp.effect_list()
|
return self._lamp.effect_list()
|
||||||
|
|
||||||
@property
|
|
||||||
def supported_features(self):
|
|
||||||
"""Flag supported features."""
|
|
||||||
return SUPPORT_BRIGHTNESS | SUPPORT_COLOR_TEMP | SUPPORT_COLOR | SUPPORT_EFFECT
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_on(self):
|
def is_on(self):
|
||||||
"""Return true if light is on."""
|
"""Return true if light is on."""
|
||||||
|
|
Loading…
Add table
Reference in a new issue