From 72cca0a91adca13881ebd870489270a85c4a64f2 Mon Sep 17 00:00:00 2001 From: Flyte Date: Fri, 29 Jan 2016 10:47:28 +0000 Subject: [PATCH] ZigBee: Handle case in which Serial port is unable to open --- homeassistant/components/zigbee.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/zigbee.py b/homeassistant/components/zigbee.py index 738ef012f0a..e153201e027 100644 --- a/homeassistant/components/zigbee.py +++ b/homeassistant/components/zigbee.py @@ -6,6 +6,7 @@ Sets up and provides access to a ZigBee device and contains generic entity classes. """ +import logging from binascii import unhexlify from homeassistant.core import JobPriority @@ -30,6 +31,8 @@ ADC_PERCENTAGE = None DEVICE = None +_LOGGER = logging.getLogger(__name__) + def setup(hass, config): """ @@ -43,7 +46,7 @@ def setup(hass, config): import xbee_helper.const as xb_const from xbee_helper import ZigBee - from serial import Serial + from serial import Serial, SerialException GPIO_DIGITAL_OUTPUT_LOW = xb_const.GPIO_DIGITAL_OUTPUT_LOW GPIO_DIGITAL_OUTPUT_HIGH = xb_const.GPIO_DIGITAL_OUTPUT_HIGH @@ -51,7 +54,11 @@ def setup(hass, config): usb_device = config[DOMAIN].get(CONF_DEVICE, DEFAULT_DEVICE) baud = int(config[DOMAIN].get(CONF_BAUD, DEFAULT_BAUD)) - ser = Serial(usb_device, baud) + try: + ser = Serial(usb_device, baud) + except SerialException as exc: + _LOGGER.exception("Unable to open serial port for ZigBee: %s", exc) + return False DEVICE = ZigBee(ser) hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, close_serial_port) return True