Refactoring test instance type

This commit is contained in:
badele 2015-10-07 19:15:50 +02:00
parent 496e4cf784
commit 46f5ef54a1
2 changed files with 53 additions and 49 deletions

View File

@ -53,10 +53,11 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
def light_update(event):
""" Callback for sensor updates from the RFXtrx gateway. """
if isinstance(event.device, rfxtrxmod.LightingDevice):
entity_id = slugify(event.device.id_string.lower())
if not isinstance(event.device, rfxtrxmod.LightingDevice):
return
# Add entity if not exist and the automatic_add is True
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:
@ -81,6 +82,7 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
else:
rfxtrx.RFX_DEVICES[entity_id].turn_off()
# Subscribe to main rfxtrx events
if light_update not in rfxtrx.RECEIVED_EVT_SUBSCRIBERS:
rfxtrx.RECEIVED_EVT_SUBSCRIBERS.append(light_update)

View File

@ -55,9 +55,10 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
def switch_update(event):
""" Callback for sensor updates from the RFXtrx gateway. """
if isinstance(event.device, LightingDevice):
entity_id = slugify(event.device.id_string.lower())
return
# Add entity if not exist and the automatic_add is True
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:
@ -82,6 +83,7 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
else:
rfxtrx.RFX_DEVICES[entity_id].turn_off()
# Subscribe to main rfxtrx events
if switch_update not in rfxtrx.RECEIVED_EVT_SUBSCRIBERS:
rfxtrx.RECEIVED_EVT_SUBSCRIBERS.append(switch_update)