From cc47e39006bcacf1bb1d3e6c227d0586aa0ad079 Mon Sep 17 00:00:00 2001 From: badele Date: Tue, 29 Sep 2015 22:47:22 +0200 Subject: [PATCH] Add send capability --- homeassistant/components/light/rfxtrx.py | 23 +++++++++++++++++------ homeassistant/components/rfxtrx.py | 5 +++-- homeassistant/components/switch/rfxtrx.py | 21 +++++++++++++++------ 3 files changed, 35 insertions(+), 14 deletions(-) diff --git a/homeassistant/components/light/rfxtrx.py b/homeassistant/components/light/rfxtrx.py index ad3fbb03d4a..190aae55da6 100644 --- a/homeassistant/components/light/rfxtrx.py +++ b/homeassistant/components/light/rfxtrx.py @@ -42,10 +42,10 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None): # Add light from config file lights = [] devices = config.get('devices') - for entity_id, entity_name in devices.items(): + for entity_id, entity_info in devices.items(): if entity_id not in rfxtrx.RFX_DEVICES: - _LOGGER.info("Add %s rfxtrx.light", entity_name) - new_light = RfxtrxLight(entity_name, False) + _LOGGER.info("Add %s rfxtrx.light", entity_info['name']) + new_light = RfxtrxLight(entity_info['name'], None, False) rfxtrx.RFX_DEVICES[entity_id] = new_light lights.append(new_light) @@ -60,8 +60,12 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None): if entity_id not in rfxtrx.RFX_DEVICES: automatic_add = config.get('automatic_add', False) if automatic_add: - _LOGGER.info("Automatic add %s rfxtrx.light", entity_id) - new_light = RfxtrxLight(entity_id, False) + _LOGGER.info("Automatic add %s rfxtrx.light (class: %s subtype: %s)", + entity_id, + event.device.__class__.__name__, + event.device.subtype + ) + new_light = RfxtrxLight(entity_id, event, False) rfxtrx.RFX_DEVICES[entity_id] = new_light add_devices_callback([new_light]) @@ -80,8 +84,9 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None): class RfxtrxLight(Light): """ Provides a demo switch. """ - def __init__(self, name, state): + def __init__(self, name, event, state): self._name = name + self._event = event self._state = state @property @@ -101,10 +106,16 @@ class RfxtrxLight(Light): def turn_on(self, **kwargs): """ Turn the device on. """ + + self._event.device.send_on(rfxtrx.RFXOBJECT.transport) + self._state = True self.update_ha_state() def turn_off(self, **kwargs): """ Turn the device off. """ + + self._event.device.send_off(rfxtrx.RFXOBJECT.transport) + self._state = False self.update_ha_state() diff --git a/homeassistant/components/rfxtrx.py b/homeassistant/components/rfxtrx.py index d72a9fe02ec..afd74c907d1 100644 --- a/homeassistant/components/rfxtrx.py +++ b/homeassistant/components/rfxtrx.py @@ -15,7 +15,7 @@ CONF_DEVICE = 'device' RECEIVED_EVT_SUBSCRIBERS = [] RFX_DEVICES = {} _LOGGER = logging.getLogger(__name__) - +RFXOBJECT = None def setup(hass, config): """ Setup the Rfxtrx component. """ @@ -34,7 +34,8 @@ def setup(hass, config): return False # Init the rfxtrx module + global RFXOBJECT device = config[DOMAIN][CONF_DEVICE] - rfxtrxmod.Core(device, handle_receive) + RFXOBJECT = rfxtrxmod.Core(device, handle_receive) return True diff --git a/homeassistant/components/switch/rfxtrx.py b/homeassistant/components/switch/rfxtrx.py index b64d0d9bf7a..cdc7f64f360 100644 --- a/homeassistant/components/switch/rfxtrx.py +++ b/homeassistant/components/switch/rfxtrx.py @@ -42,10 +42,10 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None): # Add switch from config file switchs = [] devices = config.get('devices') - for entity_id, entity_name in devices.items(): + for entity_id, entity_info in devices.items(): if entity_id not in rfxtrx.RFX_DEVICES: - _LOGGER.info("Add %s rfxtrx.switch", entity_name) - new_switch = RfxtrxSwitch(entity_name, False) + _LOGGER.info("Add %s rfxtrx.switch", entity_info['name']) + new_switch = RfxtrxSwitch(entity_info['name'], None, False) rfxtrx.RFX_DEVICES[entity_id] = new_switch switchs.append(new_switch) @@ -60,8 +60,12 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None): if entity_id not in rfxtrx.RFX_DEVICES: automatic_add = config.get('automatic_add', False) if automatic_add: - _LOGGER.info("Automatic add %s rfxtrx.switch", entity_id) - new_switch = RfxtrxSwitch(entity_id, False) + _LOGGER.info("Automatic add %s rfxtrx.switch (class: %s subtype: %s)", + entity_id, + event.device.__class__.__name__, + event.device.subtype + ) + new_switch = RfxtrxSwitch(entity_id, event, False) rfxtrx.RFX_DEVICES[entity_id] = new_switch add_devices_callback([new_switch]) @@ -80,8 +84,9 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None): class RfxtrxSwitch(SwitchDevice): """ Provides a demo switch. """ - def __init__(self, name, state): + def __init__(self, name, event, state): self._name = name + self._event = event self._state = state @property @@ -101,10 +106,14 @@ class RfxtrxSwitch(SwitchDevice): def turn_on(self, **kwargs): """ Turn the device on. """ + self._event.device.send_on(rfxtrx.RFXOBJECT.transport) + self._state = True self.update_ha_state() def turn_off(self, **kwargs): """ Turn the device off. """ + self._event.device.send_off(rfxtrx.RFXOBJECT.transport) + self._state = False self.update_ha_state()