Skip to content

Commit

Permalink
Convert rgb to hsb for Wink Osram light
Browse files Browse the repository at this point in the history
  • Loading branch information
William Scanlon committed Sep 11, 2016
1 parent 11396a2 commit 58c0990
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 13 deletions.
2 changes: 1 addition & 1 deletion homeassistant/components/binary_sensor/wink.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from homeassistant.helpers.entity import Entity
from homeassistant.loader import get_component

REQUIREMENTS = ['python-wink==0.7.13', 'pubnub==3.8.2']
REQUIREMENTS = ['python-wink==0.7.14', 'pubnub==3.8.2']

# These are the available sensors mapped to binary_sensor class
SENSOR_TYPES = {
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/cover/wink.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from homeassistant.components.wink import WinkDevice
from homeassistant.const import CONF_ACCESS_TOKEN

REQUIREMENTS = ['python-wink==0.7.13', 'pubnub==3.8.2']
REQUIREMENTS = ['python-wink==0.7.14', 'pubnub==3.8.2']


def setup_platform(hass, config, add_devices, discovery_info=None):
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/garage_door/wink.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from homeassistant.components.wink import WinkDevice
from homeassistant.const import CONF_ACCESS_TOKEN

REQUIREMENTS = ['python-wink==0.7.13', 'pubnub==3.8.2']
REQUIREMENTS = ['python-wink==0.7.14', 'pubnub==3.8.2']


def setup_platform(hass, config, add_devices, discovery_info=None):
Expand Down
29 changes: 25 additions & 4 deletions homeassistant/components/light/wink.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
https://home-assistant.io/components/light.wink/
"""
import logging
import colorsys

from homeassistant.components.light import ATTR_BRIGHTNESS, ATTR_COLOR_TEMP, \
ATTR_RGB_COLOR, SUPPORT_BRIGHTNESS, SUPPORT_COLOR_TEMP, \
Expand All @@ -15,7 +16,7 @@
from homeassistant.util.color import \
color_temperature_mired_to_kelvin as mired_to_kelvin

REQUIREMENTS = ['python-wink==0.7.13', 'pubnub==3.8.2']
REQUIREMENTS = ['python-wink==0.7.14', 'pubnub==3.8.2']

SUPPORT_WINK = SUPPORT_BRIGHTNESS | SUPPORT_COLOR_TEMP | SUPPORT_RGB_COLOR

Expand Down Expand Up @@ -56,6 +57,21 @@ def brightness(self):
"""Return the brightness of the light."""
return int(self.wink.brightness() * 255)

@property
def rgb_color(self):
"""Current bulb color in RGB."""
if not self.wink.supports_hue_saturation():
return None
else:
hue = self.wink.color_hue()
saturation = self.wink.color_saturation()
value = int(self.wink.brightness() * 255)
rgb = colorsys.hsv_to_rgb(hue, saturation, value)
r_value = int(round(rgb[0]))
g_value = int(round(rgb[1]))
b_value = int(round(rgb[2]))
return r_value, g_value, b_value

@property
def xy_color(self):
"""Current bulb color in CIE 1931 (XY) color space."""
Expand Down Expand Up @@ -87,9 +103,14 @@ def turn_on(self, **kwargs):
}

if rgb_color:
xyb = color_util.color_RGB_to_xy(*rgb_color)
state_kwargs['color_xy'] = xyb[0], xyb[1]
state_kwargs['brightness'] = xyb[2]
if self.wink.supports_xy_color():
xyb = color_util.color_RGB_to_xy(*rgb_color)
state_kwargs['color_xy'] = xyb[0], xyb[1]
state_kwargs['brightness'] = xyb[2]
elif self.wink.supports_hue_saturation():
hsv = colorsys.rgb_to_hsv(rgb_color[0],
rgb_color[1], rgb_color[2])
state_kwargs['color_hue_saturation'] = hsv[0], hsv[1]

if color_temp_mired:
state_kwargs['color_kelvin'] = mired_to_kelvin(color_temp_mired)
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/lock/wink.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from homeassistant.components.wink import WinkDevice
from homeassistant.const import CONF_ACCESS_TOKEN

REQUIREMENTS = ['python-wink==0.7.13', 'pubnub==3.8.2']
REQUIREMENTS = ['python-wink==0.7.14', 'pubnub==3.8.2']


def setup_platform(hass, config, add_devices, discovery_info=None):
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/rollershutter/wink.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from homeassistant.components.wink import WinkDevice
from homeassistant.const import CONF_ACCESS_TOKEN

REQUIREMENTS = ['python-wink==0.7.13', 'pubnub==3.8.2']
REQUIREMENTS = ['python-wink==0.7.14', 'pubnub==3.8.2']


def setup_platform(hass, config, add_devices, discovery_info=None):
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/sensor/wink.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from homeassistant.components.wink import WinkDevice
from homeassistant.loader import get_component

REQUIREMENTS = ['python-wink==0.7.13', 'pubnub==3.8.2']
REQUIREMENTS = ['python-wink==0.7.14', 'pubnub==3.8.2']

SENSOR_TYPES = ['temperature', 'humidity']

Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/switch/wink.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from homeassistant.const import CONF_ACCESS_TOKEN
from homeassistant.helpers.entity import ToggleEntity

REQUIREMENTS = ['python-wink==0.7.13', 'pubnub==3.8.2']
REQUIREMENTS = ['python-wink==0.7.14', 'pubnub==3.8.2']


def setup_platform(hass, config, add_devices, discovery_info=None):
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/wink.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from homeassistant.helpers.entity import Entity
import homeassistant.helpers.config_validation as cv

REQUIREMENTS = ['python-wink==0.7.13', 'pubnub==3.8.2']
REQUIREMENTS = ['python-wink==0.7.14', 'pubnub==3.8.2']

_LOGGER = logging.getLogger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ python-twitch==1.3.0
# homeassistant.components.rollershutter.wink
# homeassistant.components.sensor.wink
# homeassistant.components.switch.wink
python-wink==0.7.13
python-wink==0.7.14

# homeassistant.components.keyboard
pyuserinput==0.1.11
Expand Down

0 comments on commit 58c0990

Please sign in to comment.