From 56520b69ac455f7b850c2427a239238eb7a3159e Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Wed, 5 Jan 2022 09:15:50 +0100 Subject: [PATCH] Remove deprecated Arduino integration (#63406) --- .coveragerc | 1 - CODEOWNERS | 1 - homeassistant/components/arduino/__init__.py | 117 ------------------ .../components/arduino/manifest.json | 8 -- homeassistant/components/arduino/sensor.py | 55 -------- homeassistant/components/arduino/switch.py | 78 ------------ requirements_all.txt | 3 - 7 files changed, 263 deletions(-) delete mode 100644 homeassistant/components/arduino/__init__.py delete mode 100644 homeassistant/components/arduino/manifest.json delete mode 100644 homeassistant/components/arduino/sensor.py delete mode 100644 homeassistant/components/arduino/switch.py diff --git a/.coveragerc b/.coveragerc index dca566c8a26f..f99adb019cd2 100644 --- a/.coveragerc +++ b/.coveragerc @@ -66,7 +66,6 @@ omit = homeassistant/components/aquostv/media_player.py homeassistant/components/arcam_fmj/media_player.py homeassistant/components/arcam_fmj/__init__.py - homeassistant/components/arduino/* homeassistant/components/arest/binary_sensor.py homeassistant/components/arest/sensor.py homeassistant/components/arest/switch.py diff --git a/CODEOWNERS b/CODEOWNERS index 53f0359fede8..1a7707275afe 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -77,7 +77,6 @@ homeassistant/components/aprs/* @PhilRW tests/components/aprs/* @PhilRW homeassistant/components/arcam_fmj/* @elupus tests/components/arcam_fmj/* @elupus -homeassistant/components/arduino/* @fabaff homeassistant/components/arest/* @fabaff homeassistant/components/arris_tg2492lg/* @vanbalken homeassistant/components/aseko_pool_live/* @milanmeu diff --git a/homeassistant/components/arduino/__init__.py b/homeassistant/components/arduino/__init__.py deleted file mode 100644 index 6de03526ed34..000000000000 --- a/homeassistant/components/arduino/__init__.py +++ /dev/null @@ -1,117 +0,0 @@ -"""Support for Arduino boards running with the Firmata firmware.""" -import logging - -from PyMata.pymata import PyMata -import serial -import voluptuous as vol - -from homeassistant.const import ( - CONF_PORT, - EVENT_HOMEASSISTANT_START, - EVENT_HOMEASSISTANT_STOP, -) -from homeassistant.core import HomeAssistant -import homeassistant.helpers.config_validation as cv -from homeassistant.helpers.typing import ConfigType - -_LOGGER = logging.getLogger(__name__) - -DOMAIN = "arduino" - -CONFIG_SCHEMA = vol.Schema( - {DOMAIN: vol.Schema({vol.Required(CONF_PORT): cv.string})}, extra=vol.ALLOW_EXTRA -) - - -def setup(hass: HomeAssistant, config: ConfigType) -> bool: - """Set up the Arduino component.""" - _LOGGER.warning( - "The %s integration has been deprecated. Please move your " - "configuration to the firmata integration. " - "https://www.home-assistant.io/integrations/firmata", - DOMAIN, - ) - - port = config[DOMAIN][CONF_PORT] - - try: - board = ArduinoBoard(port) - except (serial.serialutil.SerialException, FileNotFoundError): - _LOGGER.error("Your port %s is not accessible", port) - 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.""" - board.disconnect() - - def start_arduino(event): - """Start the Arduino service.""" - hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, stop_arduino) - - hass.bus.listen_once(EVENT_HOMEASSISTANT_START, start_arduino) - hass.data[DOMAIN] = board - - return True - - -class ArduinoBoard: - """Representation of an Arduino board.""" - - def __init__(self, port): - """Initialize the board.""" - - self._port = port - self._board = PyMata(self._port, verbose=False) - - 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) - elif mode == "analog" and direction == "out": - 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) - elif mode == "digital" and direction == "out": - 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) - - def get_analog_inputs(self): - """Get the values from the pins.""" - self._board.capability_query() - return self._board.get_analog_response_table() - - def set_digital_out_high(self, pin): - """Set a given digital pin to high.""" - self._board.digital_write(pin, 1) - - def set_digital_out_low(self, pin): - """Set a given digital pin to low.""" - self._board.digital_write(pin, 0) - - def get_digital_in(self, pin): - """Get the value from a given digital pin.""" - self._board.digital_read(pin) - - def get_analog_in(self, pin): - """Get the value from a given analog pin.""" - self._board.analog_read(pin) - - def get_firmata(self): - """Return the version of the Firmata firmware.""" - return self._board.get_firmata_version() - - def disconnect(self): - """Disconnect the board and close the serial connection.""" - self._board.reset() - self._board.close() diff --git a/homeassistant/components/arduino/manifest.json b/homeassistant/components/arduino/manifest.json deleted file mode 100644 index 95764ebb913f..000000000000 --- a/homeassistant/components/arduino/manifest.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "domain": "arduino", - "name": "Arduino", - "documentation": "https://www.home-assistant.io/integrations/arduino", - "requirements": ["PyMata==2.20"], - "codeowners": ["@fabaff"], - "iot_class": "local_polling" -} diff --git a/homeassistant/components/arduino/sensor.py b/homeassistant/components/arduino/sensor.py deleted file mode 100644 index 36c4c767a7d4..000000000000 --- a/homeassistant/components/arduino/sensor.py +++ /dev/null @@ -1,55 +0,0 @@ -"""Support for getting information from Arduino pins.""" -from __future__ import annotations - -import voluptuous as vol - -from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity -from homeassistant.const import CONF_NAME -from homeassistant.core import HomeAssistant -import homeassistant.helpers.config_validation as cv -from homeassistant.helpers.entity_platform import AddEntitiesCallback -from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType - -from . import DOMAIN - -CONF_PINS = "pins" -CONF_TYPE = "analog" - -PIN_SCHEMA = vol.Schema({vol.Required(CONF_NAME): cv.string}) - -PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( - {vol.Required(CONF_PINS): vol.Schema({cv.positive_int: PIN_SCHEMA})} -) - - -def setup_platform( - hass: HomeAssistant, - config: ConfigType, - add_entities: AddEntitiesCallback, - discovery_info: DiscoveryInfoType | None = None, -) -> None: - """Set up the Arduino platform.""" - board = hass.data[DOMAIN] - - pins = config[CONF_PINS] - - sensors = [] - for pinnum, pin in pins.items(): - sensors.append(ArduinoSensor(pin.get(CONF_NAME), pinnum, CONF_TYPE, board)) - add_entities(sensors) - - -class ArduinoSensor(SensorEntity): - """Representation of an Arduino Sensor.""" - - def __init__(self, name, pin, pin_type, board): - """Initialize the sensor.""" - self._pin = pin - self._attr_name = name - - board.set_mode(self._pin, "in", pin_type) - self._board = board - - def update(self): - """Get the latest value from the pin.""" - self._attr_native_value = self._board.get_analog_inputs()[self._pin][1] diff --git a/homeassistant/components/arduino/switch.py b/homeassistant/components/arduino/switch.py deleted file mode 100644 index 8de4cc1e592e..000000000000 --- a/homeassistant/components/arduino/switch.py +++ /dev/null @@ -1,78 +0,0 @@ -"""Support for switching Arduino pins on and off.""" -from __future__ import annotations - -import voluptuous as vol - -from homeassistant.components.switch import PLATFORM_SCHEMA, SwitchEntity -from homeassistant.const import CONF_NAME -from homeassistant.core import HomeAssistant -import homeassistant.helpers.config_validation as cv -from homeassistant.helpers.entity_platform import AddEntitiesCallback -from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType - -from . import DOMAIN - -CONF_PINS = "pins" -CONF_TYPE = "digital" -CONF_NEGATE = "negate" -CONF_INITIAL = "initial" - -PIN_SCHEMA = vol.Schema( - { - vol.Required(CONF_NAME): cv.string, - vol.Optional(CONF_INITIAL, default=False): cv.boolean, - vol.Optional(CONF_NEGATE, default=False): cv.boolean, - } -) - -PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( - {vol.Required(CONF_PINS, default={}): vol.Schema({cv.positive_int: PIN_SCHEMA})} -) - - -def setup_platform( - hass: HomeAssistant, - config: ConfigType, - add_entities: AddEntitiesCallback, - discovery_info: DiscoveryInfoType | None = None, -) -> None: - """Set up the Arduino platform.""" - board = hass.data[DOMAIN] - - pins = config[CONF_PINS] - - switches = [] - for pinnum, pin in pins.items(): - switches.append(ArduinoSwitch(pinnum, pin, board)) - add_entities(switches) - - -class ArduinoSwitch(SwitchEntity): - """Representation of an Arduino switch.""" - - def __init__(self, pin, options, board): - """Initialize the Pin.""" - self._pin = pin - self._attr_name = options[CONF_NAME] - - self._attr_is_on = options[CONF_INITIAL] - - if options[CONF_NEGATE]: - self.turn_on_handler = board.set_digital_out_low - self.turn_off_handler = board.set_digital_out_high - else: - self.turn_on_handler = board.set_digital_out_high - self.turn_off_handler = board.set_digital_out_low - - board.set_mode(pin, "out", CONF_TYPE) - (self.turn_on_handler if self.is_on else self.turn_off_handler)(pin) - - def turn_on(self, **kwargs): - """Turn the pin to high/on.""" - self._attr_is_on = True - self.turn_on_handler(self._pin) - - def turn_off(self, **kwargs): - """Turn the pin to low/off.""" - self._attr_is_on = False - self.turn_off_handler(self._pin) diff --git a/requirements_all.txt b/requirements_all.txt index d32d93498183..8598b8c9ad74 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -31,9 +31,6 @@ PyFlick==0.0.2 # homeassistant.components.mvglive PyMVGLive==1.1.4 -# homeassistant.components.arduino -PyMata==2.20 - # homeassistant.components.mobile_app # homeassistant.components.owntracks PyNaCl==1.4.0