Made exception handling more specific

This commit is contained in:
jamespcole 2015-03-09 07:03:56 +11:00
parent 7a21e8a3fb
commit 1b29d61562
3 changed files with 73 additions and 67 deletions

View File

@ -70,7 +70,7 @@ _LOGGER = logging.getLogger(__name__)
# pylint: disable=unused-argument
def setup_platform(hass, config, add_devices_callback, discovery_info=None):
""" Find and return Vera lights. """
try:
base_url = config.get('vera_controller_url')
if not base_url:
_LOGGER.error(
@ -82,7 +82,13 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
device_data = config.get('device_data', None)
controller = veraApi.VeraController(base_url)
devices = []
try:
devices = controller.get_devices('Switch')
# pylint: disable=broad-except
except Exception as inst:
_LOGGER.error("Could not find Vera lights: %s", inst)
return False
lights = []
for device in devices:
@ -95,10 +101,6 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
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
def get_extra_device_data(device_data, device_id):

View File

@ -66,7 +66,7 @@ _LOGGER = logging.getLogger(__name__)
# pylint: disable=unused-argument
def get_devices(hass, config):
""" Find and return Vera Sensors. """
try:
base_url = config.get('vera_controller_url')
if not base_url:
_LOGGER.error(
@ -79,7 +79,13 @@ def get_devices(hass, config):
vera_controller = veraApi.VeraController(base_url)
categories = ['Temperature Sensor', 'Light Sensor', 'Sensor']
devices = []
try:
devices = vera_controller.get_devices(categories)
# 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:
@ -90,9 +96,6 @@ def get_devices(hass, config):
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 vera_sensors

View File

@ -66,7 +66,7 @@ _LOGGER = logging.getLogger(__name__)
# pylint: disable=unused-argument
def get_devices(hass, config):
""" Find and return Vera switches. """
try:
base_url = config.get('vera_controller_url')
if not base_url:
_LOGGER.error(
@ -78,7 +78,13 @@ def get_devices(hass, config):
device_data = config.get('device_data', None)
vera_controller = veraApi.VeraController(base_url)
devices = []
try:
devices = vera_controller.get_devices(['Switch', 'Armable Sensor'])
# 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:
@ -90,11 +96,6 @@ def get_devices(hass, config):
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
return vera_switches