mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 16:57:53 +00:00
Made exception handling more specific
This commit is contained in:
parent
7a21e8a3fb
commit
1b29d61562
@ -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 """
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user