From a41d0aced7d729ad5923ee4be1ac25b954948d5c Mon Sep 17 00:00:00 2001 From: Fabian Affolter <mail@fabian-affolter.ch> Date: Wed, 19 Apr 2017 12:48:15 +0200 Subject: [PATCH] Supress trackback and upgrade PyMata to 2.14 (#7176) --- homeassistant/components/arduino.py | 46 +++++++++++++++-------------- requirements_all.txt | 2 +- 2 files changed, 25 insertions(+), 23 deletions(-) diff --git a/homeassistant/components/arduino.py b/homeassistant/components/arduino.py index 239c80523df..8625685c057 100644 --- a/homeassistant/components/arduino.py +++ b/homeassistant/components/arduino.py @@ -13,7 +13,7 @@ from homeassistant.const import ( from homeassistant.const import CONF_PORT import homeassistant.helpers.config_validation as cv -REQUIREMENTS = ['PyMata==2.13'] +REQUIREMENTS = ['PyMata==2.14'] _LOGGER = logging.getLogger(__name__) @@ -29,18 +29,25 @@ CONFIG_SCHEMA = vol.Schema({ def setup(hass, config): - """Setup the Arduino component.""" + """Set up the Arduino component.""" import serial + + port = config[DOMAIN][CONF_PORT] + global BOARD try: - BOARD = ArduinoBoard(config[DOMAIN][CONF_PORT]) + BOARD = ArduinoBoard(port) except (serial.serialutil.SerialException, FileNotFoundError): - _LOGGER.exception("Your port is not accessible.") + _LOGGER.error("Your port %s is not accessible", port) return False - if BOARD.get_firmata()[1] <= 2: - _LOGGER.error("The StandardFirmata sketch should be 2.2 or newer.") - return False + try: + if BOARD.get_firmata()[1] <= 2: + _LOGGER.error("The StandardFirmata sketch should be 2.2 or newer") + return False + except IndexError: + _LOGGER.warning("The version of the StandardFirmata sketch was not" + "detected. This may lead to side effects") def stop_arduino(event): """Stop the Arduino service.""" @@ -67,25 +74,20 @@ class ArduinoBoard(object): def set_mode(self, pin, direction, mode): """Set the mode and the direction of a given pin.""" if mode == 'analog' and direction == 'in': - self._board.set_pin_mode(pin, - self._board.INPUT, - self._board.ANALOG) + self._board.set_pin_mode( + pin, self._board.INPUT, self._board.ANALOG) elif mode == 'analog' and direction == 'out': - self._board.set_pin_mode(pin, - self._board.OUTPUT, - self._board.ANALOG) + self._board.set_pin_mode( + pin, self._board.OUTPUT, self._board.ANALOG) elif mode == 'digital' and direction == 'in': - self._board.set_pin_mode(pin, - self._board.INPUT, - self._board.DIGITAL) + self._board.set_pin_mode( + pin, self._board.INPUT, self._board.DIGITAL) elif mode == 'digital' and direction == 'out': - self._board.set_pin_mode(pin, - self._board.OUTPUT, - self._board.DIGITAL) + self._board.set_pin_mode( + pin, self._board.OUTPUT, self._board.DIGITAL) elif mode == 'pwm': - self._board.set_pin_mode(pin, - self._board.OUTPUT, - self._board.PWM) + self._board.set_pin_mode( + pin, self._board.OUTPUT, self._board.PWM) def get_analog_inputs(self): """Get the values from the pins.""" diff --git a/requirements_all.txt b/requirements_all.txt index baee6d80f92..32d95676c27 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -26,7 +26,7 @@ PyJWT==1.4.2 PyMVGLive==1.1.3 # homeassistant.components.arduino -PyMata==2.13 +PyMata==2.14 # homeassistant.components.rpi_gpio # RPi.GPIO==0.6.1 -- GitLab