mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 10:17:09 +00:00
Added support for Dimming with lights in Rfxtrx module
This commit is contained in:
parent
0042e7725d
commit
a63edcf505
@ -9,7 +9,7 @@ https://home-assistant.io/components/light.rfxtrx/
|
|||||||
import logging
|
import logging
|
||||||
import homeassistant.components.rfxtrx as rfxtrx
|
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.util import slugify
|
||||||
|
|
||||||
from homeassistant.const import ATTR_ENTITY_ID
|
from homeassistant.const import ATTR_ENTITY_ID
|
||||||
@ -112,6 +112,7 @@ class RfxtrxLight(Light):
|
|||||||
self._event = event
|
self._event = event
|
||||||
self._state = datas[ATTR_STATE]
|
self._state = datas[ATTR_STATE]
|
||||||
self._should_fire_event = datas[ATTR_FIREEVENT]
|
self._should_fire_event = datas[ATTR_FIREEVENT]
|
||||||
|
self._brightness = 0
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def should_poll(self):
|
def should_poll(self):
|
||||||
@ -133,12 +134,27 @@ class RfxtrxLight(Light):
|
|||||||
""" True if light is on. """
|
""" True if light is on. """
|
||||||
return self._state
|
return self._state
|
||||||
|
|
||||||
|
@property
|
||||||
|
def brightness(self):
|
||||||
|
""" Brightness of this light between 0..255. """
|
||||||
|
return self._brightness
|
||||||
|
|
||||||
def turn_on(self, **kwargs):
|
def turn_on(self, **kwargs):
|
||||||
""" Turn the light on. """
|
""" 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:
|
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._state = True
|
||||||
self.update_ha_state()
|
self.update_ha_state()
|
||||||
|
|
||||||
@ -147,6 +163,7 @@ class RfxtrxLight(Light):
|
|||||||
|
|
||||||
if hasattr(self, '_event') and self._event:
|
if hasattr(self, '_event') and self._event:
|
||||||
self._event.device.send_off(rfxtrx.RFXOBJECT.transport)
|
self._event.device.send_off(rfxtrx.RFXOBJECT.transport)
|
||||||
|
|
||||||
|
self._brightness = 0
|
||||||
self._state = False
|
self._state = False
|
||||||
self.update_ha_state()
|
self.update_ha_state()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user