From 291910d74e3975d5ba2b50a2d88ec9eb35061471 Mon Sep 17 00:00:00 2001 From: Tim Date: Mon, 18 Jan 2016 18:10:32 +0000 Subject: [PATCH 01/27] Add LIFX bulb support --- homeassistant/components/light/lifx.py | 648 +++++++++++++++++++++++++ 1 file changed, 648 insertions(+) create mode 100644 homeassistant/components/light/lifx.py diff --git a/homeassistant/components/light/lifx.py b/homeassistant/components/light/lifx.py new file mode 100644 index 00000000000..911262b75c9 --- /dev/null +++ b/homeassistant/components/light/lifx.py @@ -0,0 +1,648 @@ +""" +homeassistant.components.light.lifx +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LiFX platform that implements lights + +Configuration: + +light: + # platform name + platform: lifx + # optional server address + # only needed if using more than one network interface + # (omit if you are unsure) + server: 192.168.1.3 + # optional broadcast address, set to reach all LiFX bulbs + # (omit if you are unsure) + broadcast: 192.168.1.255 + +""" +# pylint: disable=missing-docstring + +import logging +import threading +import time +import queue +import socket +import io +import struct +import ipaddress +import colorsys + +from struct import pack +from enum import IntEnum +from homeassistant.helpers.event import track_time_change +from homeassistant.components.light import \ + (Light, ATTR_BRIGHTNESS, ATTR_RGB_COLOR, ATTR_COLOR_TEMP) + +_LOGGER = logging.getLogger(__name__) + +DEPENDENCIES = [] +REQUIREMENTS = [] + +CONF_SERVER = "server" # server address configuration item +CONF_BROADCAST = "broadcast" # broadcast address configuration item +RETRIES = 10 # number of packet send retries +DELAY = 0.05 # delay between retries +UDP_PORT = 56700 # udp port for listening socket +UDP_IP = "0.0.0.0" # address for listening socket +MAX_ACK_AGE = 1 # maximum ACK age in seconds +BUFFERSIZE = 1024 # socket buffer size +SHORT_MAX = 65535 # short int maximum +BYTE_MAX = 255 # byte maximum +SEQUENCE_BASE = 1 # packet sequence base +SEQUENCE_COUNT = 255 # packet sequence count + +HUE_MIN = 0 +HUE_MAX = 360 +SATURATION_MIN = 0 +SATURATION_MAX = 255 +BRIGHTNESS_MIN = 0 +BRIGHTNESS_MAX = 65535 +TEMP_MIN = 2500 +TEMP_MAX = 9000 +TEMP_MIN_HASS = 154 +TEMP_MAX_HASS = 500 + + +class PayloadType(IntEnum): + """ LIFX message payload types. """ + GETSERVICE = 2 + STATESERVICE = 3 + GETHOSTINFO = 12 + STATEHOSTINFO = 13 + GETHOSTFIRMWARE = 14 + STATEHOSTFIRMWARE = 15 + GETWIFIINFO = 16 + STATEWIFIINFO = 17 + GETWIFIFIRMWARE = 18 + STATEWIFIFIRMWARE = 19 + GETPOWER1 = 20 + SETPOWER1 = 21 + STATEPOWER1 = 22 + GETLABEL = 23 + SETLABEL = 24 + STATELABEL = 25 + GETVERSION = 32 + STATEVERSION = 33 + GETINFO = 34 + STATEINFO = 35 + ACKNOWLEDGEMENT = 45 + GETLOCATION = 48 + STATELOCATION = 50 + GETGROUP = 51 + STATEGROUP = 53 + ECHOREQUEST = 58 + ECHORESPONSE = 59 + GET = 101 + SETCOLOR = 102 + STATE = 107 + GETPOWER2 = 116 + SETPOWER2 = 117 + STATEPOWER2 = 118 + + +class Power(IntEnum): + """ LIFX power settings. """ + BULB_ON = 65535 + BULB_OFF = 0 + + +def gen_header(sequence, payloadtype): + """ Create LIFX packet header. """ + protocol = bytearray.fromhex("00 34") + source = bytearray.fromhex("42 52 4b 52") + target = bytearray.fromhex("00 00 00 00 00 00 00 00") + reserved1 = bytearray.fromhex("00 00 00 00 00 00") + sequence = pack("B", 3) + reserved2 = bytearray.fromhex("00 00 00 00 00 00 00 00") + packet_type = pack(" Date: Mon, 18 Jan 2016 18:27:46 +0000 Subject: [PATCH 02/27] Remove use of warn() --- homeassistant/components/light/lifx.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/light/lifx.py b/homeassistant/components/light/lifx.py index 911262b75c9..5e43d50eabf 100644 --- a/homeassistant/components/light/lifx.py +++ b/homeassistant/components/light/lifx.py @@ -523,7 +523,7 @@ class LIFXLight(Light): break if not ack: - _LOGGER.warn("Packet %d not ACK'd", seq) + _LOGGER.warning("Packet %d not ACK'd", seq) # pylint: disable=broad-except except Exception as exc: From 3d23cd10fc96a504e13167b399c886138e67ea8f Mon Sep 17 00:00:00 2001 From: Tim Date: Mon, 18 Jan 2016 18:30:09 +0000 Subject: [PATCH 03/27] Attempt to fix ungrouped-imports pylint error --- homeassistant/components/light/lifx.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/homeassistant/components/light/lifx.py b/homeassistant/components/light/lifx.py index 5e43d50eabf..c516b273d58 100644 --- a/homeassistant/components/light/lifx.py +++ b/homeassistant/components/light/lifx.py @@ -25,10 +25,9 @@ import time import queue import socket import io -import struct import ipaddress import colorsys - +import struct from struct import pack from enum import IntEnum from homeassistant.helpers.event import track_time_change From 17f5a466d9df082ab7b7cb0ab2eed114b4fdbe4e Mon Sep 17 00:00:00 2001 From: Tim Date: Sat, 23 Jan 2016 22:14:57 +0000 Subject: [PATCH 04/27] Separate LIFX code and HA component --- homeassistant/components/light/lifx.py | 568 ++++--------------------- 1 file changed, 73 insertions(+), 495 deletions(-) diff --git a/homeassistant/components/light/lifx.py b/homeassistant/components/light/lifx.py index c516b273d58..4db691781b0 100644 --- a/homeassistant/components/light/lifx.py +++ b/homeassistant/components/light/lifx.py @@ -1,7 +1,8 @@ + """ homeassistant.components.light.lifx ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -LiFX platform that implements lights +LIFX platform that implements lights Configuration: @@ -12,525 +13,129 @@ light: # only needed if using more than one network interface # (omit if you are unsure) server: 192.168.1.3 - # optional broadcast address, set to reach all LiFX bulbs + # optional broadcast address, set to reach all LIFX bulbs # (omit if you are unsure) broadcast: 192.168.1.255 """ # pylint: disable=missing-docstring +import liffylights import logging -import threading -import time -import queue -import socket -import io -import ipaddress import colorsys -import struct -from struct import pack -from enum import IntEnum from homeassistant.helpers.event import track_time_change from homeassistant.components.light import \ (Light, ATTR_BRIGHTNESS, ATTR_RGB_COLOR, ATTR_COLOR_TEMP) _LOGGER = logging.getLogger(__name__) +REQUIREMENTS = ['liffylights==0.1'] DEPENDENCIES = [] -REQUIREMENTS = [] CONF_SERVER = "server" # server address configuration item CONF_BROADCAST = "broadcast" # broadcast address configuration item -RETRIES = 10 # number of packet send retries -DELAY = 0.05 # delay between retries -UDP_PORT = 56700 # udp port for listening socket -UDP_IP = "0.0.0.0" # address for listening socket -MAX_ACK_AGE = 1 # maximum ACK age in seconds -BUFFERSIZE = 1024 # socket buffer size SHORT_MAX = 65535 # short int maximum BYTE_MAX = 255 # byte maximum -SEQUENCE_BASE = 1 # packet sequence base -SEQUENCE_COUNT = 255 # packet sequence count +TEMP_MIN = 2500 # lifx minimum temperature +TEMP_MAX = 9000 # lifx maximum temperature +TEMP_MIN_HASS = 154 # home assistant minimum temperature +TEMP_MAX_HASS = 500 # home assistant maximum temperature -HUE_MIN = 0 -HUE_MAX = 360 -SATURATION_MIN = 0 -SATURATION_MAX = 255 -BRIGHTNESS_MIN = 0 -BRIGHTNESS_MAX = 65535 -TEMP_MIN = 2500 -TEMP_MAX = 9000 -TEMP_MIN_HASS = 154 -TEMP_MAX_HASS = 500 +class lifx_api(): + def __init__(self, add_devices_callback, + server_addr=None, broadcast_addr=None): + self._devices = [] -class PayloadType(IntEnum): - """ LIFX message payload types. """ - GETSERVICE = 2 - STATESERVICE = 3 - GETHOSTINFO = 12 - STATEHOSTINFO = 13 - GETHOSTFIRMWARE = 14 - STATEHOSTFIRMWARE = 15 - GETWIFIINFO = 16 - STATEWIFIINFO = 17 - GETWIFIFIRMWARE = 18 - STATEWIFIFIRMWARE = 19 - GETPOWER1 = 20 - SETPOWER1 = 21 - STATEPOWER1 = 22 - GETLABEL = 23 - SETLABEL = 24 - STATELABEL = 25 - GETVERSION = 32 - STATEVERSION = 33 - GETINFO = 34 - STATEINFO = 35 - ACKNOWLEDGEMENT = 45 - GETLOCATION = 48 - STATELOCATION = 50 - GETGROUP = 51 - STATEGROUP = 53 - ECHOREQUEST = 58 - ECHORESPONSE = 59 - GET = 101 - SETCOLOR = 102 - STATE = 107 - GETPOWER2 = 116 - SETPOWER2 = 117 - STATEPOWER2 = 118 + self._add_devices_callback = add_devices_callback + self._liffylights = liffylights(self.on_device, + self.on_power, + self.on_color, + server_addr, + broadcast_addr) -class Power(IntEnum): - """ LIFX power settings. """ - BULB_ON = 65535 - BULB_OFF = 0 + def find_bulb(self, ipaddr): + bulb = None + for device in self._devices: + if device.ipaddr == ipaddr: + bulb = device + break + return bulb + def on_device(self, ipaddr, name, power, hue, sat, bri, kel): + bulb = self.find_bulb(ipaddr) -def gen_header(sequence, payloadtype): - """ Create LIFX packet header. """ - protocol = bytearray.fromhex("00 34") - source = bytearray.fromhex("42 52 4b 52") - target = bytearray.fromhex("00 00 00 00 00 00 00 00") - reserved1 = bytearray.fromhex("00 00 00 00 00 00") - sequence = pack("B", 3) - reserved2 = bytearray.fromhex("00 00 00 00 00 00 00 00") - packet_type = pack(" Date: Sat, 23 Jan 2016 22:23:46 +0000 Subject: [PATCH 05/27] Bump version liffylights --- homeassistant/components/light/lifx.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/light/lifx.py b/homeassistant/components/light/lifx.py index 4db691781b0..bb8d2e348fc 100644 --- a/homeassistant/components/light/lifx.py +++ b/homeassistant/components/light/lifx.py @@ -29,7 +29,7 @@ from homeassistant.components.light import \ _LOGGER = logging.getLogger(__name__) -REQUIREMENTS = ['liffylights==0.1'] +REQUIREMENTS = ['liffylights==0.3'] DEPENDENCIES = [] CONF_SERVER = "server" # server address configuration item From 711f2da496f33ac93b4c54c42e41c47304f18feb Mon Sep 17 00:00:00 2001 From: Tim Date: Sun, 24 Jan 2016 00:43:50 +0000 Subject: [PATCH 06/27] Update liffylights version --- homeassistant/components/light/lifx.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/light/lifx.py b/homeassistant/components/light/lifx.py index bb8d2e348fc..5c1ca44968d 100644 --- a/homeassistant/components/light/lifx.py +++ b/homeassistant/components/light/lifx.py @@ -20,7 +20,7 @@ light: """ # pylint: disable=missing-docstring -import liffylights +from liffylights import liffylights import logging import colorsys from homeassistant.helpers.event import track_time_change @@ -29,7 +29,7 @@ from homeassistant.components.light import \ _LOGGER = logging.getLogger(__name__) -REQUIREMENTS = ['liffylights==0.3'] +REQUIREMENTS = ['liffylights==0.4'] DEPENDENCIES = [] CONF_SERVER = "server" # server address configuration item From 99286391e18f0fead7a01f195842ffd61f4c96ca Mon Sep 17 00:00:00 2001 From: Tim Date: Sun, 24 Jan 2016 01:00:02 +0000 Subject: [PATCH 07/27] Fixes for lint --- homeassistant/components/light/lifx.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/homeassistant/components/light/lifx.py b/homeassistant/components/light/lifx.py index 5c1ca44968d..09c0c829dad 100644 --- a/homeassistant/components/light/lifx.py +++ b/homeassistant/components/light/lifx.py @@ -42,7 +42,7 @@ TEMP_MIN_HASS = 154 # home assistant minimum temperature TEMP_MAX_HASS = 500 # home assistant maximum temperature -class lifx_api(): +class LIFX(): def __init__(self, add_devices_callback, server_addr=None, broadcast_addr=None): self._devices = [] @@ -63,6 +63,7 @@ class lifx_api(): break return bulb + # pylint: disable=too-many-arguments def on_device(self, ipaddr, name, power, hue, sat, bri, kel): bulb = self.find_bulb(ipaddr) @@ -72,6 +73,7 @@ class lifx_api(): self._devices.append(bulb) self._add_devices_callback([bulb]) + # pylint: disable=too-many-arguments def on_color(self, ipaddr, hue, sat, bri, kel): bulb = self.find_bulb(ipaddr) @@ -86,15 +88,13 @@ class lifx_api(): bulb.set_power(power) bulb.update_ha_state() + # pylint: disable=unused-argument def poll(self, now): self.probe() def probe(self, address=None): self._liffylights.probe(address) - def state(self, power): - return "on" if power else "off" - # pylint: disable=unused-argument def setup_platform(hass, config, add_devices_callback, discovery_info=None): @@ -102,7 +102,7 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None): server_addr = config.get(CONF_SERVER, None) broadcast_addr = config.get(CONF_BROADCAST, None) - lifx_library = lifx_api(add_devices_callback, server_addr, broadcast_addr) + lifx_library = LIFX(add_devices_callback, server_addr, broadcast_addr) # register our poll service track_time_change(hass, lifx_library.poll, second=10) @@ -125,9 +125,9 @@ def convert_rgb_to_hsv(rgb): class LIFXLight(Light): """ Provides LIFX light. """ # pylint: disable=too-many-arguments - def __init__(self, liffylights, ipaddr, name, power, hue, + def __init__(self, liffy, ipaddr, name, power, hue, saturation, brightness, kelvin): - self._liffylights = liffylights + self._liffylights = liffy self._ip = ipaddr self.set_name(name) self.set_power(power) From 6d2bca0fd108535f03fb70dfb8486b10535f627d Mon Sep 17 00:00:00 2001 From: Tim Date: Sun, 24 Jan 2016 01:13:51 +0000 Subject: [PATCH 08/27] Import 3rd party library inside method --- homeassistant/components/light/lifx.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/light/lifx.py b/homeassistant/components/light/lifx.py index 09c0c829dad..afe2196b0e0 100644 --- a/homeassistant/components/light/lifx.py +++ b/homeassistant/components/light/lifx.py @@ -20,7 +20,6 @@ light: """ # pylint: disable=missing-docstring -from liffylights import liffylights import logging import colorsys from homeassistant.helpers.event import track_time_change @@ -45,6 +44,8 @@ TEMP_MAX_HASS = 500 # home assistant maximum temperature class LIFX(): def __init__(self, add_devices_callback, server_addr=None, broadcast_addr=None): + from liffylights import liffylights + self._devices = [] self._add_devices_callback = add_devices_callback From 6cb6cbfefd83927ffee1be8f3dc3a09a84637aca Mon Sep 17 00:00:00 2001 From: Tim Date: Sun, 24 Jan 2016 01:18:18 +0000 Subject: [PATCH 09/27] Update requirements --- requirements_all.txt | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/requirements_all.txt b/requirements_all.txt index b6d0af08ee0..d48e0190425 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -51,6 +51,9 @@ blinkstick==1.1.7 # homeassistant.components.light.hue phue==0.8 +# homeassistant.components.light.lifx +liffylights==0.4 + # homeassistant.components.light.limitlessled limitlessled==1.0.0 @@ -95,9 +98,6 @@ paho-mqtt==1.1 # homeassistant.components.mysensors https://github.com/theolind/pymysensors/archive/005bff4c5ca7a56acd30e816bc3bcdb5cb2d46fd.zip#pymysensors==0.4 -# homeassistant.components.nest -python-nest==2.6.0 - # homeassistant.components.notify.free_mobile freesms==0.1.0 @@ -195,6 +195,9 @@ heatmiserV3==0.9.1 # homeassistant.components.thermostat.honeywell evohomeclient==0.2.4 +# homeassistant.components.thermostat.nest +python-nest==2.6.0 + # homeassistant.components.thermostat.proliphix proliphix==0.1.0 From 706bbeae16345696572d874e45924e38ad42f720 Mon Sep 17 00:00:00 2001 From: Tim Date: Sun, 24 Jan 2016 02:17:52 +0000 Subject: [PATCH 10/27] Add to .coveragerc --- .coveragerc | 1 + 1 file changed, 1 insertion(+) diff --git a/.coveragerc b/.coveragerc index 57c3d89d647..64b9e985454 100644 --- a/.coveragerc +++ b/.coveragerc @@ -74,6 +74,7 @@ omit = homeassistant/components/light/blinksticklight.py homeassistant/components/light/hue.py homeassistant/components/light/hyperion.py + homeassistant/components/light/lifx.py homeassistant/components/light/limitlessled.py homeassistant/components/media_player/cast.py homeassistant/components/media_player/denon.py From 9f6a1c75fa1d4e05671e778a95704b73a92480a9 Mon Sep 17 00:00:00 2001 From: Tim Date: Sun, 24 Jan 2016 10:01:23 +0000 Subject: [PATCH 11/27] Fix wrongly generated requirements --- requirements_all.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/requirements_all.txt b/requirements_all.txt index d48e0190425..5473f9536cb 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -101,6 +101,9 @@ https://github.com/theolind/pymysensors/archive/005bff4c5ca7a56acd30e816bc3bcdb5 # homeassistant.components.notify.free_mobile freesms==0.1.0 +# homeassistant.components.nest +python-nest==2.6.0 + # homeassistant.components.notify.pushbullet pushbullet.py==0.9.0 @@ -195,9 +198,6 @@ heatmiserV3==0.9.1 # homeassistant.components.thermostat.honeywell evohomeclient==0.2.4 -# homeassistant.components.thermostat.nest -python-nest==2.6.0 - # homeassistant.components.thermostat.proliphix proliphix==0.1.0 From 2411d1f2c849cae1e56a7174b5f8f07c7290263c Mon Sep 17 00:00:00 2001 From: Tim Date: Sun, 24 Jan 2016 10:07:56 +0000 Subject: [PATCH 12/27] Fix wrongly generated requirements --- requirements_all.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/requirements_all.txt b/requirements_all.txt index 5473f9536cb..c7e9369cbf1 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -98,12 +98,12 @@ paho-mqtt==1.1 # homeassistant.components.mysensors https://github.com/theolind/pymysensors/archive/005bff4c5ca7a56acd30e816bc3bcdb5cb2d46fd.zip#pymysensors==0.4 -# homeassistant.components.notify.free_mobile -freesms==0.1.0 - # homeassistant.components.nest python-nest==2.6.0 +# homeassistant.components.notify.free_mobile +freesms==0.1.0 + # homeassistant.components.notify.pushbullet pushbullet.py==0.9.0 From d94db5388c42c70bb9e404fcf3595da839b80af7 Mon Sep 17 00:00:00 2001 From: Tim Date: Mon, 25 Jan 2016 03:32:55 +0000 Subject: [PATCH 13/27] Add preliminary support for transition time --- homeassistant/components/light/lifx.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/light/lifx.py b/homeassistant/components/light/lifx.py index afe2196b0e0..8ff99403e05 100644 --- a/homeassistant/components/light/lifx.py +++ b/homeassistant/components/light/lifx.py @@ -24,7 +24,7 @@ import logging import colorsys from homeassistant.helpers.event import track_time_change from homeassistant.components.light import \ - (Light, ATTR_BRIGHTNESS, ATTR_RGB_COLOR, ATTR_COLOR_TEMP) + (Light, ATTR_BRIGHTNESS, ATTR_RGB_COLOR, ATTR_COLOR_TEMP, ATTR_TRANSITION) _LOGGER = logging.getLogger(__name__) @@ -172,6 +172,11 @@ class LIFXLight(Light): def turn_on(self, **kwargs): """ Turn the device on. """ + if ATTR_TRANSITION in kwargs: + fade = kwargs[ATTR_TRANSITION] * 1000 + else: + fade = 0 + if ATTR_BRIGHTNESS in kwargs: brightness = kwargs[ATTR_BRIGHTNESS] * (BYTE_MAX + 1) else: @@ -192,15 +197,21 @@ class LIFXLight(Light): else: kelvin = self._kel + _LOGGER.info("%s %d %d %d %d %d", self._ip, hue, saturation, brightness, kelvin, fade) if self._power == 0: - self._liffylights.set_power(self._ip, 65535) + self._liffylights.set_power(self._ip, 65535, 0) self._liffylights.set_color(self._ip, hue, saturation, - brightness, kelvin) + brightness, kelvin, fade) def turn_off(self, **kwargs): """ Turn the device off. """ - self._liffylights.set_power(self._ip, 0) + if ATTR_TRANSITION in kwargs: + fade = kwargs[ATTR_TRANSITION] * 1000 + else: + fade = 0 + + self._liffylights.set_power(self._ip, 0, fade) def set_name(self, name): """ Set name. """ From 74e844655641d6ad64a1e3440890af1339d5a07a Mon Sep 17 00:00:00 2001 From: Tim Date: Mon, 25 Jan 2016 03:34:24 +0000 Subject: [PATCH 14/27] Bump version of liffylights --- homeassistant/components/light/lifx.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/light/lifx.py b/homeassistant/components/light/lifx.py index 8ff99403e05..9c33ab3c8e4 100644 --- a/homeassistant/components/light/lifx.py +++ b/homeassistant/components/light/lifx.py @@ -28,7 +28,7 @@ from homeassistant.components.light import \ _LOGGER = logging.getLogger(__name__) -REQUIREMENTS = ['liffylights==0.4'] +REQUIREMENTS = ['liffylights==0.5'] DEPENDENCIES = [] CONF_SERVER = "server" # server address configuration item From 50561ffe974d0c4034193d5e3baecb31d4eb86c5 Mon Sep 17 00:00:00 2001 From: Tim Date: Mon, 25 Jan 2016 03:39:13 +0000 Subject: [PATCH 15/27] Fix long line --- homeassistant/components/light/lifx.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/light/lifx.py b/homeassistant/components/light/lifx.py index 9c33ab3c8e4..64bdb946cf1 100644 --- a/homeassistant/components/light/lifx.py +++ b/homeassistant/components/light/lifx.py @@ -197,7 +197,8 @@ class LIFXLight(Light): else: kelvin = self._kel - _LOGGER.info("%s %d %d %d %d %d", self._ip, hue, saturation, brightness, kelvin, fade) + _LOGGER.debug("%s %d %d %d %d %d", + self._ip, hue, saturation, brightness, kelvin, fade) if self._power == 0: self._liffylights.set_power(self._ip, 65535, 0) From 069dafa3a51c769aadc26017091edceb350e4c47 Mon Sep 17 00:00:00 2001 From: Tim Date: Mon, 25 Jan 2016 07:38:37 +0000 Subject: [PATCH 16/27] Update requirements_all --- requirements_all.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements_all.txt b/requirements_all.txt index c7e9369cbf1..3706c5c58ea 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -52,7 +52,7 @@ blinkstick==1.1.7 phue==0.8 # homeassistant.components.light.lifx -liffylights==0.4 +liffylights==0.5 # homeassistant.components.light.limitlessled limitlessled==1.0.0 From 5a926913d3da29e8911fbea03fe57be020525e03 Mon Sep 17 00:00:00 2001 From: Tim Date: Mon, 25 Jan 2016 10:00:15 +0000 Subject: [PATCH 17/27] Update to v0.6 of liffylights --- homeassistant/components/light/lifx.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/light/lifx.py b/homeassistant/components/light/lifx.py index 64bdb946cf1..b2907c84e4e 100644 --- a/homeassistant/components/light/lifx.py +++ b/homeassistant/components/light/lifx.py @@ -28,7 +28,7 @@ from homeassistant.components.light import \ _LOGGER = logging.getLogger(__name__) -REQUIREMENTS = ['liffylights==0.5'] +REQUIREMENTS = ['liffylights==0.6'] DEPENDENCIES = [] CONF_SERVER = "server" # server address configuration item From 4089a7a0d3283ed9367c6d2f9c1718c924ea9066 Mon Sep 17 00:00:00 2001 From: Tim Date: Mon, 25 Jan 2016 10:02:03 +0000 Subject: [PATCH 18/27] Update requirements_all --- requirements_all.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements_all.txt b/requirements_all.txt index 3706c5c58ea..c3eaf038da5 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -52,7 +52,7 @@ blinkstick==1.1.7 phue==0.8 # homeassistant.components.light.lifx -liffylights==0.5 +liffylights==0.6 # homeassistant.components.light.limitlessled limitlessled==1.0.0 From d10a5cf5e962d86cd122d2a92602fe036f17cd48 Mon Sep 17 00:00:00 2001 From: Tim Date: Mon, 25 Jan 2016 11:54:41 +0000 Subject: [PATCH 19/27] Update to v0.8.3 of liffylights --- homeassistant/components/light/lifx.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/light/lifx.py b/homeassistant/components/light/lifx.py index b2907c84e4e..31106699ac8 100644 --- a/homeassistant/components/light/lifx.py +++ b/homeassistant/components/light/lifx.py @@ -28,7 +28,7 @@ from homeassistant.components.light import \ _LOGGER = logging.getLogger(__name__) -REQUIREMENTS = ['liffylights==0.6'] +REQUIREMENTS = ['liffylights==0.8.3'] DEPENDENCIES = [] CONF_SERVER = "server" # server address configuration item @@ -44,13 +44,13 @@ TEMP_MAX_HASS = 500 # home assistant maximum temperature class LIFX(): def __init__(self, add_devices_callback, server_addr=None, broadcast_addr=None): - from liffylights import liffylights + from liffylights import LiffyLights self._devices = [] self._add_devices_callback = add_devices_callback - self._liffylights = liffylights(self.on_device, + self._liffylights = LiffyLights(self.on_device, self.on_power, self.on_color, server_addr, From 32cfa6998c3166d6f6d5efc2c2598d5d84c533e3 Mon Sep 17 00:00:00 2001 From: Tim Date: Mon, 25 Jan 2016 12:13:24 +0000 Subject: [PATCH 20/27] Update requirements_all --- requirements_all.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements_all.txt b/requirements_all.txt index c3eaf038da5..45ff0c78e00 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -52,7 +52,7 @@ blinkstick==1.1.7 phue==0.8 # homeassistant.components.light.lifx -liffylights==0.6 +liffylights==0.8.3 # homeassistant.components.light.limitlessled limitlessled==1.0.0 From 8009542b3e85cc6aff18a45e7d9da6995f2a0123 Mon Sep 17 00:00:00 2001 From: Tim Date: Mon, 25 Jan 2016 13:30:52 +0000 Subject: [PATCH 21/27] Add extra debugging Add duration to power on --- homeassistant/components/light/lifx.py | 50 +++++++++++++++++++++----- 1 file changed, 41 insertions(+), 9 deletions(-) diff --git a/homeassistant/components/light/lifx.py b/homeassistant/components/light/lifx.py index 31106699ac8..200baf26e05 100644 --- a/homeassistant/components/light/lifx.py +++ b/homeassistant/components/light/lifx.py @@ -128,6 +128,9 @@ class LIFXLight(Light): # pylint: disable=too-many-arguments def __init__(self, liffy, ipaddr, name, power, hue, saturation, brightness, kelvin): + _LOGGER.debug("LIFXLight: %s %s", + ipaddr, name) + self._liffylights = liffy self._ip = ipaddr self.set_name(name) @@ -152,22 +155,38 @@ class LIFXLight(Light): @property def rgb_color(self): """ Returns RGB value. """ + _LOGGER.debug("rgb_color: [%d %d %d]", + self._rgb[0], self._rgb[1], self._rgb[2]) + return self._rgb @property def brightness(self): """ Returns brightness of this light between 0..255. """ - return int(self._bri / (BYTE_MAX + 1)) + brightness = int(self._bri / (BYTE_MAX + 1)) + + _LOGGER.debug("color_temp: %d", + brightness) + + return brightness @property def color_temp(self): """ Returns color temperature. """ - return int(TEMP_MIN_HASS + (TEMP_MAX_HASS - TEMP_MIN_HASS) * - (self._kel - TEMP_MIN) / (TEMP_MAX - TEMP_MIN)) + temperature = int(TEMP_MIN_HASS + (TEMP_MAX_HASS - TEMP_MIN_HASS) * + (self._kel - TEMP_MIN) / (TEMP_MAX - TEMP_MIN)) + + _LOGGER.debug("color_temp: %d", + temperature) + + return temperature @property def is_on(self): """ True if device is on. """ + _LOGGER.debug("is_on: %d", + self._power) + return self._power != 0 def turn_on(self, **kwargs): @@ -197,10 +216,12 @@ class LIFXLight(Light): else: kelvin = self._kel - _LOGGER.debug("%s %d %d %d %d %d", - self._ip, hue, saturation, brightness, kelvin, fade) + _LOGGER.debug("turn_on: %s (%d) %d %d %d %d %d", + self._ip, self._power, + hue, saturation, brightness, kelvin, fade) + if self._power == 0: - self._liffylights.set_power(self._ip, 65535, 0) + self._liffylights.set_power(self._ip, 65535, fade) self._liffylights.set_color(self._ip, hue, saturation, brightness, kelvin, fade) @@ -212,6 +233,9 @@ class LIFXLight(Light): else: fade = 0 + _LOGGER.debug("turn_off: %s %d", + self._ip, fade) + self._liffylights.set_power(self._ip, 0, fade) def set_name(self, name): @@ -220,6 +244,9 @@ class LIFXLight(Light): def set_power(self, power): """ Set power state value. """ + _LOGGER.debug("set_power: %d", + power) + self._power = (power != 0) def set_color(self, hue, sat, bri, kel): @@ -233,6 +260,11 @@ class LIFXLight(Light): sat / SHORT_MAX, bri / SHORT_MAX) - self._rgb = [int(red * BYTE_MAX), - int(green * BYTE_MAX), - int(blue * BYTE_MAX)] + red = int(red * BYTE_MAX) + green = int(green * BYTE_MAX) + blue = int(blue * BYTE_MAX) + + _LOGGER.debug("set_color: %d %d %d %d [%d %d %d]", + hue, sat, bri, kel, red, green, blue) + + self._rgb = [red, green, blue] From 11120a8743748313bfde97ef15b18b354607f489 Mon Sep 17 00:00:00 2001 From: Tim Date: Mon, 25 Jan 2016 15:19:50 +0000 Subject: [PATCH 22/27] Fix liffylights import --- homeassistant/components/light/lifx.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/homeassistant/components/light/lifx.py b/homeassistant/components/light/lifx.py index 200baf26e05..fcfd5a853d2 100644 --- a/homeassistant/components/light/lifx.py +++ b/homeassistant/components/light/lifx.py @@ -28,7 +28,7 @@ from homeassistant.components.light import \ _LOGGER = logging.getLogger(__name__) -REQUIREMENTS = ['liffylights==0.8.3'] +REQUIREMENTS = ['liffylights==0.8.7'] DEPENDENCIES = [] CONF_SERVER = "server" # server address configuration item @@ -44,17 +44,18 @@ TEMP_MAX_HASS = 500 # home assistant maximum temperature class LIFX(): def __init__(self, add_devices_callback, server_addr=None, broadcast_addr=None): - from liffylights import LiffyLights + import liffylights self._devices = [] self._add_devices_callback = add_devices_callback - self._liffylights = LiffyLights(self.on_device, - self.on_power, - self.on_color, - server_addr, - broadcast_addr) + self._liffylights = liffylights.LiffyLights( + self.on_device, + self.on_power, + self.on_color, + server_addr, + broadcast_addr) def find_bulb(self, ipaddr): bulb = None From 97f042525270dcfc8e279b5aa39e576cd03b08db Mon Sep 17 00:00:00 2001 From: Tim Date: Mon, 25 Jan 2016 15:20:23 +0000 Subject: [PATCH 23/27] Update requirements_all --- requirements_all.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements_all.txt b/requirements_all.txt index 45ff0c78e00..8d1057606fe 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -52,7 +52,7 @@ blinkstick==1.1.7 phue==0.8 # homeassistant.components.light.lifx -liffylights==0.8.3 +liffylights==0.8.7 # homeassistant.components.light.limitlessled limitlessled==1.0.0 From 784fea2d561f67855f163be2a40e66beac0c59d1 Mon Sep 17 00:00:00 2001 From: Tim Date: Mon, 25 Jan 2016 19:08:48 +0000 Subject: [PATCH 24/27] Update for new liffylights version --- homeassistant/components/light/lifx.py | 2 +- requirements_all.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/light/lifx.py b/homeassistant/components/light/lifx.py index fcfd5a853d2..5f32e5a51b4 100644 --- a/homeassistant/components/light/lifx.py +++ b/homeassistant/components/light/lifx.py @@ -28,7 +28,7 @@ from homeassistant.components.light import \ _LOGGER = logging.getLogger(__name__) -REQUIREMENTS = ['liffylights==0.8.7'] +REQUIREMENTS = ['liffylights==0.8.8'] DEPENDENCIES = [] CONF_SERVER = "server" # server address configuration item diff --git a/requirements_all.txt b/requirements_all.txt index 8d1057606fe..c700e9c1eb5 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -52,7 +52,7 @@ blinkstick==1.1.7 phue==0.8 # homeassistant.components.light.lifx -liffylights==0.8.7 +liffylights==0.8.8 # homeassistant.components.light.limitlessled limitlessled==1.0.0 From bb7f92330dc18810194e1f804116f744e3cb03f8 Mon Sep 17 00:00:00 2001 From: Tim Date: Mon, 25 Jan 2016 20:53:21 +0000 Subject: [PATCH 25/27] Update liffylights version --- homeassistant/components/light/lifx.py | 2 +- requirements_all.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/light/lifx.py b/homeassistant/components/light/lifx.py index 5f32e5a51b4..eb97c99ced7 100644 --- a/homeassistant/components/light/lifx.py +++ b/homeassistant/components/light/lifx.py @@ -28,7 +28,7 @@ from homeassistant.components.light import \ _LOGGER = logging.getLogger(__name__) -REQUIREMENTS = ['liffylights==0.8.8'] +REQUIREMENTS = ['liffylights==0.9.0'] DEPENDENCIES = [] CONF_SERVER = "server" # server address configuration item diff --git a/requirements_all.txt b/requirements_all.txt index c700e9c1eb5..d38b7044ddd 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -52,7 +52,7 @@ blinkstick==1.1.7 phue==0.8 # homeassistant.components.light.lifx -liffylights==0.8.8 +liffylights==0.9.0 # homeassistant.components.light.limitlessled limitlessled==1.0.0 From 1397f9e588903b14000a7483400c387ab9c9d0da Mon Sep 17 00:00:00 2001 From: Tim Date: Mon, 25 Jan 2016 20:58:10 +0000 Subject: [PATCH 26/27] Fix logging typo --- homeassistant/components/light/lifx.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/light/lifx.py b/homeassistant/components/light/lifx.py index eb97c99ced7..36370242924 100644 --- a/homeassistant/components/light/lifx.py +++ b/homeassistant/components/light/lifx.py @@ -166,7 +166,7 @@ class LIFXLight(Light): """ Returns brightness of this light between 0..255. """ brightness = int(self._bri / (BYTE_MAX + 1)) - _LOGGER.debug("color_temp: %d", + _LOGGER.debug("brightness: %d", brightness) return brightness From b1ba792715d5fc15957430ea0272f2cfca0e3a01 Mon Sep 17 00:00:00 2001 From: Tim Date: Mon, 25 Jan 2016 21:19:27 +0000 Subject: [PATCH 27/27] Brightness from HA overrides brightness from HSV conversion --- homeassistant/components/light/lifx.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/homeassistant/components/light/lifx.py b/homeassistant/components/light/lifx.py index 36370242924..bc8b752f788 100644 --- a/homeassistant/components/light/lifx.py +++ b/homeassistant/components/light/lifx.py @@ -197,11 +197,6 @@ class LIFXLight(Light): else: fade = 0 - if ATTR_BRIGHTNESS in kwargs: - brightness = kwargs[ATTR_BRIGHTNESS] * (BYTE_MAX + 1) - else: - brightness = self._bri - if ATTR_RGB_COLOR in kwargs: hue, saturation, brightness = \ convert_rgb_to_hsv(kwargs[ATTR_RGB_COLOR]) @@ -210,6 +205,11 @@ class LIFXLight(Light): saturation = self._sat brightness = self._bri + if ATTR_BRIGHTNESS in kwargs: + brightness = kwargs[ATTR_BRIGHTNESS] * (BYTE_MAX + 1) + else: + brightness = self._bri + if ATTR_COLOR_TEMP in kwargs: kelvin = int(((TEMP_MAX - TEMP_MIN) * (kwargs[ATTR_COLOR_TEMP] - TEMP_MIN_HASS) /