Skip to content
Open
Changes from all 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
34 changes: 25 additions & 9 deletions DoHome_HassAssistant_Component/custom_components/dohome/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@
ATTR_BRIGHTNESS,
ATTR_COLOR_TEMP,
ATTR_EFFECT,
ATTR_HS_COLOR,
ATTR_RGBWW_COLOR,
PLATFORM_SCHEMA,
SUPPORT_BRIGHTNESS,
SUPPORT_COLOR,
LightEntity,
ColorMode
)

from . import (DOHOME_GATEWAY, DoHomeDevice)
Expand All @@ -43,7 +44,7 @@ def __init__(self, hass, device):

self._device = device
self._state = False
self._rgb = (255, 255, 255)
self._rgb = (255, 255, 255, 255, 255)
self._brightness = 100
self._socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

Expand All @@ -55,9 +56,9 @@ def brightness(self):
return self._brightness

@property
def hs_color(self):
def rgbww_color(self):
"""Return the color property."""
return color_util.color_RGB_to_hs(*self._rgb)
return self._rgb

@property
def is_on(self):
Expand All @@ -69,10 +70,24 @@ def supported_features(self):
"""Return the supported features."""
return SUPPORT_BRIGHTNESS | SUPPORT_COLOR

@property
def supported_color_modes(self):
"""Return the supported color modes."""
return [ColorMode.RGBWW]

@property
def color_mode(self):
"""Return the supported color modes."""
return ColorMode.RGBWW

@property
def unique_id(self):
return self._device["name"]

def turn_on(self, **kwargs):
"""Turn the light on."""
if ATTR_HS_COLOR in kwargs:
self._rgb = color_util.color_hs_to_RGB(*kwargs[ATTR_HS_COLOR])
if ATTR_RGBWW_COLOR in kwargs:
self._rgb = kwargs[ATTR_RGBWW_COLOR]

if ATTR_BRIGHTNESS in kwargs:
self._brightness = int(100 * kwargs[ATTR_BRIGHTNESS] / 255)
Expand All @@ -83,8 +98,9 @@ def turn_on(self, **kwargs):
"r":int(50 * self._rgb[0] / 255)*self._brightness,
"g":int(50 * self._rgb[1] / 255)*self._brightness,
"b":int(50 * self._rgb[2] / 255)*self._brightness,
"w":0,
"m":0}
"w":int(50 * self._rgb[3] / 255)*self._brightness,
"m":int(50 * self._rgb[4] / 255)*self._brightness
}
op = json.dumps(data)
self._send_cmd(self._device,'cmd=ctrl&devices={[' + self._device["sid"] + ']}&op=' + op + '}', 6)

Expand Down Expand Up @@ -123,4 +139,4 @@ def _send_cmd(self, device, cmd, rtn_cmd):
return resp
else:
_LOGGER.debug("Non matching response. device %s, but got %s", device["sid"], dic["dev"][8:12])
return None
return None