mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 18:27:09 +00:00
Add signal repetition to rfxtrx
This commit is contained in:
parent
eacfac6fa8
commit
0010cadd39
@ -19,6 +19,7 @@ from homeassistant.components.rfxtrx import (
|
||||
|
||||
|
||||
DEPENDENCIES = ['rfxtrx']
|
||||
SIGNAL_REPETITIONS = 1
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
@ -29,6 +30,7 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
||||
|
||||
lights = []
|
||||
devices = config.get('devices', None)
|
||||
signal_repetitions = config.get('signal_repetitions', SIGNAL_REPETITIONS)
|
||||
|
||||
if devices:
|
||||
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])
|
||||
new_light = RfxtrxLight(
|
||||
entity_info[ATTR_NAME], rfxobject, datas
|
||||
entity_info[ATTR_NAME], rfxobject, datas, signal_repetitions
|
||||
)
|
||||
rfxtrx.RFX_DEVICES[entity_id] = 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)
|
||||
entity_name = "%s : %s" % (entity_id, pkt_id)
|
||||
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
|
||||
add_devices_callback([new_light])
|
||||
|
||||
@ -120,11 +123,12 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
||||
|
||||
class RfxtrxLight(Light):
|
||||
""" Provides a RFXtrx light. """
|
||||
def __init__(self, name, event, datas):
|
||||
def __init__(self, name, event, datas, signal_repetitions):
|
||||
self._name = name
|
||||
self._event = event
|
||||
self._state = datas[ATTR_STATE]
|
||||
self._should_fire_event = datas[ATTR_FIREEVENT]
|
||||
self.signal_repetitions = signal_repetitions
|
||||
self._brightness = 0
|
||||
|
||||
@property
|
||||
@ -160,11 +164,13 @@ class RfxtrxLight(Light):
|
||||
|
||||
if brightness is None:
|
||||
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:
|
||||
self._brightness = ((brightness + 4) * 100 // 255 - 1)
|
||||
self._event.device.send_dim(rfxtrx.RFXOBJECT.transport,
|
||||
self._brightness)
|
||||
for _ in range(self.signal_repetitions):
|
||||
self._event.device.send_dim(rfxtrx.RFXOBJECT.transport,
|
||||
self._brightness)
|
||||
|
||||
self._brightness = (self._brightness * 255 // 100)
|
||||
self._state = True
|
||||
@ -173,7 +179,10 @@ class RfxtrxLight(Light):
|
||||
def turn_off(self, **kwargs):
|
||||
""" 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._brightness = 0
|
||||
|
@ -19,6 +19,7 @@ from homeassistant.components.rfxtrx import (
|
||||
|
||||
|
||||
DEPENDENCIES = ['rfxtrx']
|
||||
SIGNAL_REPETITIONS = 1
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
@ -30,6 +31,7 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
||||
# Add switch from config file
|
||||
switchs = []
|
||||
devices = config.get('devices')
|
||||
signal_repetitions = config.get('signal_repetitions', SIGNAL_REPETITIONS)
|
||||
if devices:
|
||||
for entity_id, entity_info in devices.items():
|
||||
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])
|
||||
newswitch = RfxtrxSwitch(
|
||||
entity_info[ATTR_NAME], rfxobject, datas)
|
||||
entity_info[ATTR_NAME], rfxobject, datas, signal_repetitions)
|
||||
rfxtrx.RFX_DEVICES[entity_id] = 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)
|
||||
entity_name = "%s : %s" % (entity_id, pkt_id)
|
||||
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
|
||||
add_devices_callback([new_switch])
|
||||
|
||||
@ -106,11 +109,12 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
||||
|
||||
class RfxtrxSwitch(SwitchDevice):
|
||||
""" Provides a RFXtrx switch. """
|
||||
def __init__(self, name, event, datas):
|
||||
def __init__(self, name, event, datas, signal_repetitions):
|
||||
self._name = name
|
||||
self._event = event
|
||||
self._state = datas[ATTR_STATE]
|
||||
self._should_fire_event = datas[ATTR_FIREEVENT]
|
||||
self.signal_repetitions = signal_repetitions
|
||||
|
||||
@property
|
||||
def should_poll(self):
|
||||
@ -134,7 +138,10 @@ class RfxtrxSwitch(SwitchDevice):
|
||||
|
||||
def turn_on(self, **kwargs):
|
||||
""" 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._state = True
|
||||
@ -142,7 +149,10 @@ class RfxtrxSwitch(SwitchDevice):
|
||||
|
||||
def turn_off(self, **kwargs):
|
||||
""" 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._state = False
|
||||
|
Loading…
x
Reference in New Issue
Block a user