Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for "setRGB" command for light entity. #75

Merged
merged 18 commits into from
Jun 22, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion custom_components/tahoma/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,18 @@
CORE_OCCUPANCY_STATE = "core:OccupancyState"
CORE_SMOKE_STATE = "core:SmokeState"
CORE_TEMPERATURE_STATE = "core:TemperatureState"
CORE_LUMINANCE_STATE = "core:LuminanceState"
CORE_RELATIVE_HUMIDITY_STATE = "core:RelativeHumidityState"
CORE_MEMORIZED_1_POSITION_STATE = "core:Memorized1PositionState"
CORE_PEDESTRIAN_POSITION_STATE = "core:PedestrianPositionState"
CORE_ELECTRIC_POWER_CONSUMPTION_STATE = "core:ElectricPowerConsumptionState"
CORE_CO2_CONCENTRATION_STATE = "core:CO2ConcentrationState"

# Light core states
CORE_LUMINANCE_STATE = "core:LuminanceState"
CORE_RED_COLOR_INTENSITY_STATE = "core:RedColorIntensityState"
CORE_GREEN_COLOR_INTENSITY_STATE = "core:GreenColorIntensityState"
CORE_BLUE_COLOR_INTENSITY_STATE = "core:BlueColorIntensityState"

IO_PRIORITY_LOCK_LEVEL_STATE = "io:PriorityLockLevelState"
IO_PRIORITY_LOCK_ORIGINATOR_STATE = "io:PriorityLockOriginatorState"

Expand Down
39 changes: 37 additions & 2 deletions custom_components/tahoma/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,22 @@
from homeassistant.components.light import (
ATTR_BRIGHTNESS,
ATTR_EFFECT,
ATTR_RGB_COLOR,
iMicknl marked this conversation as resolved.
Show resolved Hide resolved
SUPPORT_BRIGHTNESS,
SUPPORT_COLOR,
SUPPORT_EFFECT,
LightEntity,
)
from homeassistant.const import STATE_OFF, STATE_ON

from .const import DOMAIN, TAHOMA_TYPES
import homeassistant.util.color as color_util

from .const import (
CORE_BLUE_COLOR_INTENSITY_STATE,
CORE_GREEN_COLOR_INTENSITY_STATE,
CORE_RED_COLOR_INTENSITY_STATE,
DOMAIN,
TAHOMA_TYPES,
)
from .tahoma_device import TahomaDevice

_LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -45,6 +54,7 @@ def __init__(self, tahoma_device, controller):
self._effect = None
self._brightness = None
self._state = None
self._rgb = []

@property
def brightness(self) -> int:
Expand All @@ -56,6 +66,13 @@ def is_on(self) -> bool:
"""Return true if light is on."""
return self._state

@property
def hs_color(self):
"""Return the hue and saturation color value [float, float]."""
if self.supported_features & SUPPORT_COLOR:
iMicknl marked this conversation as resolved.
Show resolved Hide resolved
return color_util.color_RGB_to_hs(*self._rgb)
return None

@property
def supported_features(self) -> int:
"""Flag supported features."""
Expand All @@ -68,13 +85,22 @@ def supported_features(self) -> int:
if "wink" in self.tahoma_device.command_definitions:
supported_features |= SUPPORT_EFFECT

if "setRGB" in self.tahoma_device.command_definitions:
supported_features |= SUPPORT_COLOR

return supported_features

def turn_on(self, **kwargs) -> None:
"""Turn the light on."""
self._state = True
self._skip_update = True

_LOGGER.debug(f"light.turn_on kwargs: {kwargs}")

if ATTR_RGB_COLOR in kwargs:
self._rgb = [int(float(c)) for c in kwargs[ATTR_RGB_COLOR]]
iMicknl marked this conversation as resolved.
Show resolved Hide resolved
self.apply_action("setRGB", *self._rgb)

if ATTR_BRIGHTNESS in kwargs:
self._brightness = int(float(kwargs[ATTR_BRIGHTNESS]) / 255 * 100)
self.apply_action("setIntensity", self._brightness)
Expand Down Expand Up @@ -116,6 +142,8 @@ def update(self):

self.controller.get_states([self.tahoma_device])

_LOGGER.debug(f"light states:\n{self.tahoma_device.active_states}")

if "core:LightIntensityState" in self.tahoma_device.active_states:
self._brightness = self.tahoma_device.active_states.get(
"core:LightIntensityState"
Expand All @@ -125,3 +153,10 @@ def update(self):
self._state = True
else:
self._state = False

if CORE_RED_COLOR_INTENSITY_STATE in self.tahoma_device.active_states:
self._rgb = [
iMicknl marked this conversation as resolved.
Show resolved Hide resolved
self.tahoma_device.active_states.get(CORE_RED_COLOR_INTENSITY_STATE),
self.tahoma_device.active_states.get(CORE_GREEN_COLOR_INTENSITY_STATE),
self.tahoma_device.active_states.get(CORE_BLUE_COLOR_INTENSITY_STATE),
]