diff --git a/homeassistant/components/light/rfxtrx.py b/homeassistant/components/light/rfxtrx.py index 58ba3759f94..f76d9f7ed5b 100644 --- a/homeassistant/components/light/rfxtrx.py +++ b/homeassistant/components/light/rfxtrx.py @@ -31,7 +31,6 @@ from homeassistant.util import slugify DEPENDENCIES = ['rfxtrx'] -DOMAIN = "rfxtrx" _LOGGER = logging.getLogger(__name__) @@ -60,20 +59,22 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None): entity_id = slugify(event.device.id_string.lower()) 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 (Class: %s Sub: %s)", - entity_id, - event.device.__class__.__name__, - event.device.subtype - ) - pkt_id = "".join("{0:02x}".format(x) for x in event.data) - entity_name = "%s : %s" % (entity_id, pkt_id) - new_light = RfxtrxLight(entity_name, event, False) - rfxtrx.RFX_DEVICES[entity_id] = new_light - add_devices_callback([new_light]) + if not automatic_add: + return - # Check if entity exists (previous automatic added) + _LOGGER.info( + "Automatic add %s rfxtrx.light (Class: %s Sub: %s)", + entity_id, + event.device.__class__.__name__, + event.device.subtype + ) + pkt_id = "".join("{0:02x}".format(x) for x in event.data) + entity_name = "%s : %s" % (entity_id, pkt_id) + new_light = RfxtrxLight(entity_name, event, False) + rfxtrx.RFX_DEVICES[entity_id] = new_light + add_devices_callback([new_light]) + + # Check if entity exists or previously added automatically if entity_id in rfxtrx.RFX_DEVICES: if event.values['Command'] == 'On'\ or event.values['Command'] == 'Off': @@ -112,7 +113,7 @@ class RfxtrxLight(Light): def turn_on(self, **kwargs): """ Turn the device on. """ - if self._event: + if hasattr(self, '_event') and self._event: self._event.device.send_on(rfxtrx.RFXOBJECT.transport) self._state = True @@ -121,7 +122,7 @@ class RfxtrxLight(Light): def turn_off(self, **kwargs): """ Turn the device off. """ - if self._event: + if hasattr(self, '_event') and self._event: self._event.device.send_off(rfxtrx.RFXOBJECT.transport) self._state = False diff --git a/homeassistant/components/rfxtrx.py b/homeassistant/components/rfxtrx.py index f2b962c7ba9..79378b85e78 100644 --- a/homeassistant/components/rfxtrx.py +++ b/homeassistant/components/rfxtrx.py @@ -20,7 +20,8 @@ import logging from homeassistant.util import slugify DEPENDENCIES = [] -REQUIREMENTS = ['https://github.com/Danielhiversen/pyRFXtrx/archive/0.2.zip#RFXtrx==0.2'] +REQUIREMENTS = ['https://github.com/Danielhiversen/pyRFXtrx/archive/0.2.zip' + + '#RFXtrx==0.2'] DOMAIN = "rfxtrx" CONF_DEVICE = 'device' @@ -59,11 +60,15 @@ def setup(hass, config): # Init the rfxtrx module global RFXOBJECT + if CONF_DEVICE not in config[DOMAIN]: + _LOGGER.exception( + "can found device parameter in %s YAML configuration section", + DOMAIN + ) + return False + device = config[DOMAIN][CONF_DEVICE] - try: - debug = config[DOMAIN][CONF_DEBUG] - except KeyError: - debug = False + debug = config[DOMAIN].get(CONF_DEBUG, False) RFXOBJECT = rfxtrxmod.Core(device, handle_receive, debug=debug) diff --git a/homeassistant/components/switch/rfxtrx.py b/homeassistant/components/switch/rfxtrx.py index d97759d4e86..98963beb769 100644 --- a/homeassistant/components/switch/rfxtrx.py +++ b/homeassistant/components/switch/rfxtrx.py @@ -31,7 +31,6 @@ from homeassistant.util import slugify DEPENDENCIES = ['rfxtrx'] -DOMAIN = "rfxtrx" _LOGGER = logging.getLogger(__name__) @@ -61,20 +60,22 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None): entity_id = slugify(event.device.id_string.lower()) 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 (Class: %s Sub: %s)", - entity_id, - event.device.__class__.__name__, - event.device.subtype - ) - pkt_id = "".join("{0:02x}".format(x) for x in event.data) - entity_name = "%s : %s" % (entity_id, pkt_id) - new_switch = RfxtrxSwitch(entity_name, event, False) - rfxtrx.RFX_DEVICES[entity_id] = new_switch - add_devices_callback([new_switch]) + if not automatic_add: + return - # Check if entity exists (previous automatic added) + _LOGGER.info( + "Automatic add %s rfxtrx.switch (Class: %s Sub: %s)", + entity_id, + event.device.__class__.__name__, + event.device.subtype + ) + pkt_id = "".join("{0:02x}".format(x) for x in event.data) + entity_name = "%s : %s" % (entity_id, pkt_id) + new_switch = RfxtrxSwitch(entity_name, event, False) + rfxtrx.RFX_DEVICES[entity_id] = new_switch + add_devices_callback([new_switch]) + + # Check if entity exists or previously added automatically if entity_id in rfxtrx.RFX_DEVICES: if event.values['Command'] == 'On'\ or event.values['Command'] == 'Off':