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', {}) vera_controller = veraApi.VeraController(base_url) categories = ['Temperature Sensor', 'Light Sensor', 'Sensor'] devices = [] try: devices = vera_controller.get_devices(categories) except RequestException: # There was a network related error connecting to the vera controller _LOGGER.exception("Error communicating with Vera API") return False vera_sensors = [] for device in devices: extra_data = device_data.get(device.deviceId, {}) exclude = extra_data.get('exclude', False) if exclude is not True: vera_sensors.append(VeraSensor(device, extra_data)) return vera_sensors
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', {}) controller = veraApi.VeraController(base_url) devices = [] try: devices = controller.get_devices(['Switch', 'On/Off Switch']) except RequestException: # There was a network related error connecting to the vera controller _LOGGER.exception("Error communicating with Vera API") return False lights = [] for device in devices: extra_data = device_data.get(device.deviceId, {}) exclude = extra_data.get('exclude', False) if exclude is not True: lights.append(VeraSwitch(device, extra_data)) add_devices_callback(lights)