From a63edcf505259ed7902b228f78003871af35e07f Mon Sep 17 00:00:00 2001 From: turbokongen Date: Sat, 23 Jan 2016 11:18:11 +0100 Subject: [PATCH 1/5] Added support for Dimming with lights in Rfxtrx module --- homeassistant/components/light/rfxtrx.py | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/light/rfxtrx.py b/homeassistant/components/light/rfxtrx.py index 22bd2575242..d4c6133397c 100644 --- a/homeassistant/components/light/rfxtrx.py +++ b/homeassistant/components/light/rfxtrx.py @@ -9,7 +9,7 @@ https://home-assistant.io/components/light.rfxtrx/ import logging import homeassistant.components.rfxtrx as rfxtrx -from homeassistant.components.light import Light +from homeassistant.components.light import Light, ATTR_BRIGHTNESS from homeassistant.util import slugify from homeassistant.const import ATTR_ENTITY_ID @@ -112,6 +112,7 @@ class RfxtrxLight(Light): self._event = event self._state = datas[ATTR_STATE] self._should_fire_event = datas[ATTR_FIREEVENT] + self._brightness = 0 @property def should_poll(self): @@ -133,12 +134,27 @@ class RfxtrxLight(Light): """ True if light is on. """ return self._state + @property + def brightness(self): + """ Brightness of this light between 0..255. """ + return self._brightness + def turn_on(self, **kwargs): """ Turn the light on. """ + brightness = kwargs.get(ATTR_BRIGHTNESS) + + if brightness is None: + """ Brightness in rfxtrx is defined as level and values supported are 0-100 """ + self._brightness = 100 + else: + """ Brightness in rfxtrx is defined as level and values supported are 0-100 so we need to scale the set value (0-255)""" + self._brightness = ((brightness + 4) * 100 // 255 -1) if hasattr(self, '_event') and self._event: - self._event.device.send_on(rfxtrx.RFXOBJECT.transport) + self._event.device.send_on(rfxtrx.RFXOBJECT.transport, self._brightness) + """ Reverse earlier calculation to make dimmer slider stay at correct point in HA frontend """ + self._brightness = (self._brightness * 255 // 100) self._state = True self.update_ha_state() @@ -147,6 +163,7 @@ class RfxtrxLight(Light): if hasattr(self, '_event') and self._event: self._event.device.send_off(rfxtrx.RFXOBJECT.transport) - + + self._brightness = 0 self._state = False self.update_ha_state() From d3c6c892a8d09da01523a9696a0e678b60cdc3b9 Mon Sep 17 00:00:00 2001 From: turbokongen Date: Sat, 23 Jan 2016 11:50:09 +0100 Subject: [PATCH 2/5] Small intendation fix --- homeassistant/components/light/rfxtrx.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/light/rfxtrx.py b/homeassistant/components/light/rfxtrx.py index d4c6133397c..f5231be78ad 100644 --- a/homeassistant/components/light/rfxtrx.py +++ b/homeassistant/components/light/rfxtrx.py @@ -134,7 +134,7 @@ class RfxtrxLight(Light): """ True if light is on. """ return self._state - @property + @property def brightness(self): """ Brightness of this light between 0..255. """ return self._brightness From 43e2b58f2091c28fa48fd6d1291c2dc1575b026e Mon Sep 17 00:00:00 2001 From: turbokongen Date: Sat, 23 Jan 2016 12:00:03 +0100 Subject: [PATCH 3/5] Fixing of various test errors --- homeassistant/components/light/rfxtrx.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/homeassistant/components/light/rfxtrx.py b/homeassistant/components/light/rfxtrx.py index f5231be78ad..f886457ffd7 100644 --- a/homeassistant/components/light/rfxtrx.py +++ b/homeassistant/components/light/rfxtrx.py @@ -144,16 +144,13 @@ class RfxtrxLight(Light): brightness = kwargs.get(ATTR_BRIGHTNESS) if brightness is None: - """ Brightness in rfxtrx is defined as level and values supported are 0-100 """ self._brightness = 100 else: - """ Brightness in rfxtrx is defined as level and values supported are 0-100 so we need to scale the set value (0-255)""" - self._brightness = ((brightness + 4) * 100 // 255 -1) + self._brightness = ((brightness + 4) * 100 // 255 - 1) if hasattr(self, '_event') and self._event: self._event.device.send_on(rfxtrx.RFXOBJECT.transport, self._brightness) - """ Reverse earlier calculation to make dimmer slider stay at correct point in HA frontend """ self._brightness = (self._brightness * 255 // 100) self._state = True self.update_ha_state() From e30915eb2c5edf1ce9084fcd0fab5416b589b883 Mon Sep 17 00:00:00 2001 From: turbokongen Date: Sat, 23 Jan 2016 12:08:21 +0100 Subject: [PATCH 4/5] flake8 complaint fix --- homeassistant/components/light/rfxtrx.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/light/rfxtrx.py b/homeassistant/components/light/rfxtrx.py index f886457ffd7..fd05a37a303 100644 --- a/homeassistant/components/light/rfxtrx.py +++ b/homeassistant/components/light/rfxtrx.py @@ -160,7 +160,7 @@ class RfxtrxLight(Light): if hasattr(self, '_event') and self._event: self._event.device.send_off(rfxtrx.RFXOBJECT.transport) - + self._brightness = 0 self._state = False self.update_ha_state() From 6d527842dd0024d14afe19f5a86b315b9494d527 Mon Sep 17 00:00:00 2001 From: turbokongen Date: Sat, 23 Jan 2016 12:14:00 +0100 Subject: [PATCH 5/5] Another flake8 fix too long line --- homeassistant/components/light/rfxtrx.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/light/rfxtrx.py b/homeassistant/components/light/rfxtrx.py index fd05a37a303..64389a0fa59 100644 --- a/homeassistant/components/light/rfxtrx.py +++ b/homeassistant/components/light/rfxtrx.py @@ -149,7 +149,8 @@ class RfxtrxLight(Light): self._brightness = ((brightness + 4) * 100 // 255 - 1) if hasattr(self, '_event') and self._event: - self._event.device.send_on(rfxtrx.RFXOBJECT.transport, self._brightness) + self._event.device.send_on(rfxtrx.RFXOBJECT.transport, + self._brightness) self._brightness = (self._brightness * 255 // 100) self._state = True