Refactoring the rfxtrx components

This commit is contained in:
badele 2015-10-07 19:57:40 +02:00
parent 46f5ef54a1
commit a5dae78155
3 changed files with 42 additions and 35 deletions

View File

@ -31,7 +31,6 @@ from homeassistant.util import slugify
DEPENDENCIES = ['rfxtrx']
DOMAIN = "rfxtrx"
_LOGGER = logging.getLogger(__name__)
@ -60,7 +59,9 @@ 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:
if not automatic_add:
return
_LOGGER.info(
"Automatic add %s rfxtrx.light (Class: %s Sub: %s)",
entity_id,
@ -73,7 +74,7 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
rfxtrx.RFX_DEVICES[entity_id] = new_light
add_devices_callback([new_light])
# Check if entity exists (previous automatic added)
# 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

View File

@ -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)

View File

@ -31,7 +31,6 @@ from homeassistant.util import slugify
DEPENDENCIES = ['rfxtrx']
DOMAIN = "rfxtrx"
_LOGGER = logging.getLogger(__name__)
@ -61,7 +60,9 @@ 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:
if not automatic_add:
return
_LOGGER.info(
"Automatic add %s rfxtrx.switch (Class: %s Sub: %s)",
entity_id,
@ -74,7 +75,7 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
rfxtrx.RFX_DEVICES[entity_id] = new_switch
add_devices_callback([new_switch])
# Check if entity exists (previous automatic added)
# 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':