diff --git a/homeassistant/components/light/vera.py b/homeassistant/components/light/vera.py index d1e55a768c5..ae63777cb8d 100644 --- a/homeassistant/components/light/vera.py +++ b/homeassistant/components/light/vera.py @@ -70,36 +70,38 @@ _LOGGER = logging.getLogger(__name__) # pylint: disable=unused-argument def setup_platform(hass, config, add_devices_callback, discovery_info=None): """ Find and return Vera lights. """ + + base_url = config.get('vera_controller_url') + if not base_url: + _LOGGER.error( + "The required parameter 'vera_controller_url'" + " was not found in config" + ) + return False + + device_data = config.get('device_data', None) + + controller = veraApi.VeraController(base_url) + devices = [] try: - base_url = config.get('vera_controller_url') - if not base_url: - _LOGGER.error( - "The required parameter 'vera_controller_url'" - " was not found in config" - ) - return False - - device_data = config.get('device_data', None) - - controller = veraApi.VeraController(base_url) devices = controller.get_devices('Switch') - - lights = [] - for device in devices: - extra_data = get_extra_device_data(device_data, device.deviceId) - exclude = False - if extra_data: - exclude = extra_data.get('exclude', False) - - if exclude is not True: - lights.append(VeraLight(device, extra_data)) - - add_devices_callback(lights) # pylint: disable=broad-except except Exception as inst: _LOGGER.error("Could not find Vera lights: %s", inst) return False + lights = [] + for device in devices: + extra_data = get_extra_device_data(device_data, device.deviceId) + exclude = False + if extra_data: + exclude = extra_data.get('exclude', False) + + if exclude is not True: + lights.append(VeraLight(device, extra_data)) + + add_devices_callback(lights) + def get_extra_device_data(device_data, device_id): """ Gets the additional configuration data by Vera device Id """ diff --git a/homeassistant/components/sensor/vera.py b/homeassistant/components/sensor/vera.py index b6b777c8dd5..385b5165bb1 100644 --- a/homeassistant/components/sensor/vera.py +++ b/homeassistant/components/sensor/vera.py @@ -66,33 +66,36 @@ _LOGGER = logging.getLogger(__name__) # pylint: disable=unused-argument def get_devices(hass, config): """ Find and return Vera Sensors. """ + + base_url = config.get('vera_controller_url') + if not base_url: + _LOGGER.error( + "The required parameter 'vera_controller_url'" + " was not found in config" + ) + return False + + device_data = config.get('device_data', None) + + vera_controller = veraApi.VeraController(base_url) + categories = ['Temperature Sensor', 'Light Sensor', 'Sensor'] + devices = [] try: - base_url = config.get('vera_controller_url') - if not base_url: - _LOGGER.error( - "The required parameter 'vera_controller_url'" - " was not found in config" - ) - return False - - device_data = config.get('device_data', None) - - vera_controller = veraApi.VeraController(base_url) - categories = ['Temperature Sensor', 'Light Sensor', 'Sensor'] devices = vera_controller.get_devices(categories) - - vera_sensors = [] - for device in devices: - extra_data = get_extra_device_data(device_data, device.deviceId) - exclude = False - if extra_data: - exclude = extra_data.get('exclude', False) - - if exclude is not True: - vera_sensors.append(VeraSensor(device, extra_data)) # pylint: disable=broad-except except Exception as inst: _LOGGER.error("Could not find Vera sensors: %s", inst) + return False + + vera_sensors = [] + for device in devices: + extra_data = get_extra_device_data(device_data, device.deviceId) + exclude = False + if extra_data: + exclude = extra_data.get('exclude', False) + + if exclude is not True: + vera_sensors.append(VeraSensor(device, extra_data)) return vera_sensors diff --git a/homeassistant/components/switch/vera.py b/homeassistant/components/switch/vera.py index 6deb98631ee..7af893d851f 100644 --- a/homeassistant/components/switch/vera.py +++ b/homeassistant/components/switch/vera.py @@ -66,35 +66,36 @@ _LOGGER = logging.getLogger(__name__) # pylint: disable=unused-argument def get_devices(hass, config): """ Find and return Vera switches. """ + + base_url = config.get('vera_controller_url') + if not base_url: + _LOGGER.error( + "The required parameter 'vera_controller_url'" + " was not found in config" + ) + return False + + device_data = config.get('device_data', None) + + vera_controller = veraApi.VeraController(base_url) + devices = [] try: - base_url = config.get('vera_controller_url') - if not base_url: - _LOGGER.error( - "The required parameter 'vera_controller_url'" - " was not found in config" - ) - return False - - device_data = config.get('device_data', None) - - vera_controller = veraApi.VeraController(base_url) devices = vera_controller.get_devices(['Switch', 'Armable Sensor']) - - vera_switches = [] - for device in devices: - extra_data = get_extra_device_data(device_data, device.deviceId) - exclude = False - if extra_data: - exclude = extra_data.get('exclude', False) - - if exclude is not True: - vera_switches.append(VeraSwitch(device, extra_data)) - # pylint: disable=broad-except except Exception as inst: _LOGGER.error("Could not find Vera switches: %s", inst) return False + vera_switches = [] + for device in devices: + extra_data = get_extra_device_data(device_data, device.deviceId) + exclude = False + if extra_data: + exclude = extra_data.get('exclude', False) + + if exclude is not True: + vera_switches.append(VeraSwitch(device, extra_data)) + return vera_switches