From 46f5ef54a19c0a02fef7ddd02bfad26aa3701b74 Mon Sep 17 00:00:00 2001 From: badele Date: Wed, 7 Oct 2015 19:15:50 +0200 Subject: [PATCH] Refactoring test instance type --- homeassistant/components/light/rfxtrx.py | 52 ++++++++++++----------- homeassistant/components/switch/rfxtrx.py | 50 +++++++++++----------- 2 files changed, 53 insertions(+), 49 deletions(-) diff --git a/homeassistant/components/light/rfxtrx.py b/homeassistant/components/light/rfxtrx.py index ceb6fe97f8c..58ba3759f94 100644 --- a/homeassistant/components/light/rfxtrx.py +++ b/homeassistant/components/light/rfxtrx.py @@ -53,34 +53,36 @@ 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 - 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]) + # 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: + _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 (previous automatic added) - if entity_id in rfxtrx.RFX_DEVICES: - if event.values['Command'] == 'On'\ - or event.values['Command'] == 'Off': - if event.values['Command'] == 'On': - rfxtrx.RFX_DEVICES[entity_id].turn_on() - else: - rfxtrx.RFX_DEVICES[entity_id].turn_off() + # Check if entity exists (previous automatic added) + if entity_id in rfxtrx.RFX_DEVICES: + if event.values['Command'] == 'On'\ + or event.values['Command'] == 'Off': + if event.values['Command'] == 'On': + rfxtrx.RFX_DEVICES[entity_id].turn_on() + 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) diff --git a/homeassistant/components/switch/rfxtrx.py b/homeassistant/components/switch/rfxtrx.py index 29120c7d93c..d97759d4e86 100644 --- a/homeassistant/components/switch/rfxtrx.py +++ b/homeassistant/components/switch/rfxtrx.py @@ -55,33 +55,35 @@ 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 - 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]) + # 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: + _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 (previous automatic added) - if entity_id in rfxtrx.RFX_DEVICES: - if event.values['Command'] == 'On'\ - or event.values['Command'] == 'Off': - if event.values['Command'] == 'On': - rfxtrx.RFX_DEVICES[entity_id].turn_on() - else: - rfxtrx.RFX_DEVICES[entity_id].turn_off() + # Check if entity exists (previous automatic added) + if entity_id in rfxtrx.RFX_DEVICES: + if event.values['Command'] == 'On'\ + or event.values['Command'] == 'Off': + if event.values['Command'] == 'On': + rfxtrx.RFX_DEVICES[entity_id].turn_on() + 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)