Add signal repetition to rfxtrx

This commit is contained in:
Daniel 2016-02-15 19:41:40 +01:00
parent eacfac6fa8
commit 0010cadd39
2 changed files with 31 additions and 12 deletions

View File

@ -19,6 +19,7 @@ from homeassistant.components.rfxtrx import (
DEPENDENCIES = ['rfxtrx'] DEPENDENCIES = ['rfxtrx']
SIGNAL_REPETITIONS = 1
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -29,6 +30,7 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
lights = [] lights = []
devices = config.get('devices', None) devices = config.get('devices', None)
signal_repetitions = config.get('signal_repetitions', SIGNAL_REPETITIONS)
if devices: if devices:
for entity_id, entity_info in devices.items(): for entity_id, entity_info in devices.items():
@ -41,7 +43,7 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
rfxobject = rfxtrx.get_rfx_object(entity_info[ATTR_PACKETID]) rfxobject = rfxtrx.get_rfx_object(entity_info[ATTR_PACKETID])
new_light = RfxtrxLight( new_light = RfxtrxLight(
entity_info[ATTR_NAME], rfxobject, datas entity_info[ATTR_NAME], rfxobject, datas, signal_repetitions
) )
rfxtrx.RFX_DEVICES[entity_id] = new_light rfxtrx.RFX_DEVICES[entity_id] = new_light
lights.append(new_light) lights.append(new_light)
@ -70,7 +72,8 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
pkt_id = "".join("{0:02x}".format(x) for x in event.data) pkt_id = "".join("{0:02x}".format(x) for x in event.data)
entity_name = "%s : %s" % (entity_id, pkt_id) entity_name = "%s : %s" % (entity_id, pkt_id)
datas = {ATTR_STATE: False, ATTR_FIREEVENT: False} datas = {ATTR_STATE: False, ATTR_FIREEVENT: False}
new_light = RfxtrxLight(entity_name, event, datas) signal_repetitions = config.get('signal_repetitions', SIGNAL_REPETITIONS)
new_light = RfxtrxLight(entity_name, event, datas, signal_repetitions)
rfxtrx.RFX_DEVICES[entity_id] = new_light rfxtrx.RFX_DEVICES[entity_id] = new_light
add_devices_callback([new_light]) add_devices_callback([new_light])
@ -120,11 +123,12 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
class RfxtrxLight(Light): class RfxtrxLight(Light):
""" Provides a RFXtrx light. """ """ Provides a RFXtrx light. """
def __init__(self, name, event, datas): def __init__(self, name, event, datas, signal_repetitions):
self._name = name self._name = name
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.signal_repetitions = signal_repetitions
self._brightness = 0 self._brightness = 0
@property @property
@ -160,9 +164,11 @@ class RfxtrxLight(Light):
if brightness is None: if brightness is None:
self._brightness = 100 self._brightness = 100
self._event.device.send_on(rfxtrx.RFXOBJECT.transport) for _ in range(self.signal_repetitions):
self._eventent.device.send_on(rfxtrx.RFXOBJECT.transport)
else: else:
self._brightness = ((brightness + 4) * 100 // 255 - 1) self._brightness = ((brightness + 4) * 100 // 255 - 1)
for _ in range(self.signal_repetitions):
self._event.device.send_dim(rfxtrx.RFXOBJECT.transport, self._event.device.send_dim(rfxtrx.RFXOBJECT.transport,
self._brightness) self._brightness)
@ -173,7 +179,10 @@ class RfxtrxLight(Light):
def turn_off(self, **kwargs): def turn_off(self, **kwargs):
""" Turn the light off. """ """ Turn the light off. """
if hasattr(self, '_event') and self._event: if not self._event:
return
for _ in range(self.signal_repetitions):
self._event.device.send_off(rfxtrx.RFXOBJECT.transport) self._event.device.send_off(rfxtrx.RFXOBJECT.transport)
self._brightness = 0 self._brightness = 0

View File

@ -19,6 +19,7 @@ from homeassistant.components.rfxtrx import (
DEPENDENCIES = ['rfxtrx'] DEPENDENCIES = ['rfxtrx']
SIGNAL_REPETITIONS = 1
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -30,6 +31,7 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
# Add switch from config file # Add switch from config file
switchs = [] switchs = []
devices = config.get('devices') devices = config.get('devices')
signal_repetitions = config.get('signal_repetitions', SIGNAL_REPETITIONS)
if devices: if devices:
for entity_id, entity_info in devices.items(): for entity_id, entity_info in devices.items():
if entity_id not in rfxtrx.RFX_DEVICES: if entity_id not in rfxtrx.RFX_DEVICES:
@ -41,7 +43,7 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
rfxobject = rfxtrx.get_rfx_object(entity_info[ATTR_PACKETID]) rfxobject = rfxtrx.get_rfx_object(entity_info[ATTR_PACKETID])
newswitch = RfxtrxSwitch( newswitch = RfxtrxSwitch(
entity_info[ATTR_NAME], rfxobject, datas) entity_info[ATTR_NAME], rfxobject, datas, signal_repetitions)
rfxtrx.RFX_DEVICES[entity_id] = newswitch rfxtrx.RFX_DEVICES[entity_id] = newswitch
switchs.append(newswitch) switchs.append(newswitch)
@ -69,7 +71,8 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
pkt_id = "".join("{0:02x}".format(x) for x in event.data) pkt_id = "".join("{0:02x}".format(x) for x in event.data)
entity_name = "%s : %s" % (entity_id, pkt_id) entity_name = "%s : %s" % (entity_id, pkt_id)
datas = {ATTR_STATE: False, ATTR_FIREEVENT: False} datas = {ATTR_STATE: False, ATTR_FIREEVENT: False}
new_switch = RfxtrxSwitch(entity_name, event, datas) signal_repetitions = config.get('signal_repetitions', SIGNAL_REPETITIONS)
new_switch = RfxtrxSwitch(entity_name, event, datas, signal_repetitions)
rfxtrx.RFX_DEVICES[entity_id] = new_switch rfxtrx.RFX_DEVICES[entity_id] = new_switch
add_devices_callback([new_switch]) add_devices_callback([new_switch])
@ -106,11 +109,12 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
class RfxtrxSwitch(SwitchDevice): class RfxtrxSwitch(SwitchDevice):
""" Provides a RFXtrx switch. """ """ Provides a RFXtrx switch. """
def __init__(self, name, event, datas): def __init__(self, name, event, datas, signal_repetitions):
self._name = name self._name = name
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.signal_repetitions = signal_repetitions
@property @property
def should_poll(self): def should_poll(self):
@ -134,7 +138,10 @@ class RfxtrxSwitch(SwitchDevice):
def turn_on(self, **kwargs): def turn_on(self, **kwargs):
""" Turn the device on. """ """ Turn the device on. """
if self._event: if not self._event:
return
for _ in range(self.signal_repetitions):
self._event.device.send_on(rfxtrx.RFXOBJECT.transport) self._event.device.send_on(rfxtrx.RFXOBJECT.transport)
self._state = True self._state = True
@ -142,7 +149,10 @@ class RfxtrxSwitch(SwitchDevice):
def turn_off(self, **kwargs): def turn_off(self, **kwargs):
""" Turn the device off. """ """ Turn the device off. """
if self._event: if not self._event:
return
for _ in range(self.signal_repetitions):
self._event.device.send_off(rfxtrx.RFXOBJECT.transport) self._event.device.send_off(rfxtrx.RFXOBJECT.transport)
self._state = False self._state = False