From 1c0365a72b5a0a15f2dc6a3c0fad2a7fb4e42bc3 Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Sun, 27 Feb 2022 15:40:25 +0100 Subject: [PATCH] Remove deprecated MCP23017 I/O Expander integration (#67281) --- .coveragerc | 1 - CODEOWNERS | 1 - homeassistant/components/mcp23017/__init__.py | 3 - .../components/mcp23017/binary_sensor.py | 104 ----------------- .../components/mcp23017/manifest.json | 12 -- homeassistant/components/mcp23017/switch.py | 110 ------------------ requirements_all.txt | 4 - 7 files changed, 235 deletions(-) delete mode 100644 homeassistant/components/mcp23017/__init__.py delete mode 100644 homeassistant/components/mcp23017/binary_sensor.py delete mode 100644 homeassistant/components/mcp23017/manifest.json delete mode 100644 homeassistant/components/mcp23017/switch.py diff --git a/.coveragerc b/.coveragerc index c25d85eba1f..a1f6d339429 100644 --- a/.coveragerc +++ b/.coveragerc @@ -668,7 +668,6 @@ omit = homeassistant/components/map/* homeassistant/components/mastodon/notify.py homeassistant/components/matrix/* - homeassistant/components/mcp23017/* homeassistant/components/media_extractor/* homeassistant/components/mediaroom/media_player.py homeassistant/components/melcloud/__init__.py diff --git a/CODEOWNERS b/CODEOWNERS index fb191264d89..da5c2b0c23a 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -540,7 +540,6 @@ homeassistant/components/mastodon/* @fabaff homeassistant/components/matrix/* @tinloaf homeassistant/components/mazda/* @bdr99 tests/components/mazda/* @bdr99 -homeassistant/components/mcp23017/* @jardiamj homeassistant/components/media_source/* @hunterjm tests/components/media_source/* @hunterjm homeassistant/components/mediaroom/* @dgomes diff --git a/homeassistant/components/mcp23017/__init__.py b/homeassistant/components/mcp23017/__init__.py deleted file mode 100644 index 14799217a6b..00000000000 --- a/homeassistant/components/mcp23017/__init__.py +++ /dev/null @@ -1,3 +0,0 @@ -"""Support for I2C MCP23017 chip.""" - -DOMAIN = "mcp23017" diff --git a/homeassistant/components/mcp23017/binary_sensor.py b/homeassistant/components/mcp23017/binary_sensor.py deleted file mode 100644 index 161b1ceaac8..00000000000 --- a/homeassistant/components/mcp23017/binary_sensor.py +++ /dev/null @@ -1,104 +0,0 @@ -"""Support for binary sensor using I2C MCP23017 chip.""" -from __future__ import annotations - -import logging - -from adafruit_mcp230xx.mcp23017 import MCP23017 -import board -import busio -import digitalio -import voluptuous as vol - -from homeassistant.components.binary_sensor import PLATFORM_SCHEMA, BinarySensorEntity -from homeassistant.const import DEVICE_DEFAULT_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 - -CONF_INVERT_LOGIC = "invert_logic" -CONF_I2C_ADDRESS = "i2c_address" -CONF_PINS = "pins" -CONF_PULL_MODE = "pull_mode" - -MODE_UP = "UP" -MODE_DOWN = "DOWN" - -DEFAULT_INVERT_LOGIC = False -DEFAULT_I2C_ADDRESS = 0x20 -DEFAULT_PULL_MODE = MODE_UP - -_SENSORS_SCHEMA = vol.Schema({cv.positive_int: cv.string}) - -PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( - { - vol.Required(CONF_PINS): _SENSORS_SCHEMA, - vol.Optional(CONF_INVERT_LOGIC, default=DEFAULT_INVERT_LOGIC): cv.boolean, - vol.Optional(CONF_PULL_MODE, default=DEFAULT_PULL_MODE): vol.All( - vol.Upper, vol.In([MODE_UP, MODE_DOWN]) - ), - vol.Optional(CONF_I2C_ADDRESS, default=DEFAULT_I2C_ADDRESS): vol.Coerce(int), - } -) - -_LOGGER = logging.getLogger(__name__) - - -def setup_platform( - hass: HomeAssistant, - config: ConfigType, - add_devices: AddEntitiesCallback, - discovery_info: DiscoveryInfoType | None = None, -) -> None: - """Set up the MCP23017 binary sensors.""" - _LOGGER.warning( - "The MCP23017 I/O Expander integration is deprecated and will be removed " - "in Home Assistant Core 2022.4; this integration is removed under " - "Architectural Decision Record 0019, more information can be found here: " - "https://github.com/home-assistant/architecture/blob/master/adr/0019-GPIO.md" - ) - pull_mode = config[CONF_PULL_MODE] - invert_logic = config[CONF_INVERT_LOGIC] - i2c_address = config[CONF_I2C_ADDRESS] - - i2c = busio.I2C(board.SCL, board.SDA) - mcp = MCP23017(i2c, address=i2c_address) - - binary_sensors = [] - pins = config[CONF_PINS] - - for pin_num, pin_name in pins.items(): - pin = mcp.get_pin(pin_num) - binary_sensors.append( - MCP23017BinarySensor(pin_name, pin, pull_mode, invert_logic) - ) - - add_devices(binary_sensors, True) - - -class MCP23017BinarySensor(BinarySensorEntity): - """Represent a binary sensor that uses MCP23017.""" - - def __init__(self, name, pin, pull_mode, invert_logic): - """Initialize the MCP23017 binary sensor.""" - self._name = name or DEVICE_DEFAULT_NAME - self._pin = pin - self._pull_mode = pull_mode - self._invert_logic = invert_logic - self._state = None - self._pin.direction = digitalio.Direction.INPUT - self._pin.pull = digitalio.Pull.UP - - @property - def name(self): - """Return the name of the sensor.""" - return self._name - - @property - def is_on(self): - """Return the state of the entity.""" - return self._state != self._invert_logic - - def update(self): - """Update the GPIO state.""" - self._state = self._pin.value diff --git a/homeassistant/components/mcp23017/manifest.json b/homeassistant/components/mcp23017/manifest.json deleted file mode 100644 index e6f04ad1171..00000000000 --- a/homeassistant/components/mcp23017/manifest.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "domain": "mcp23017", - "name": "MCP23017 I/O Expander", - "documentation": "https://www.home-assistant.io/integrations/mcp23017", - "requirements": [ - "RPi.GPIO==0.7.1a4", - "adafruit-circuitpython-mcp230xx==2.2.2" - ], - "codeowners": ["@jardiamj"], - "iot_class": "local_polling", - "loggers": ["adafruit_mcp230xx"] -} diff --git a/homeassistant/components/mcp23017/switch.py b/homeassistant/components/mcp23017/switch.py deleted file mode 100644 index b67f20e3bf6..00000000000 --- a/homeassistant/components/mcp23017/switch.py +++ /dev/null @@ -1,110 +0,0 @@ -"""Support for switch sensor using I2C MCP23017 chip.""" -from __future__ import annotations - -import logging - -from adafruit_mcp230xx.mcp23017 import MCP23017 -import board -import busio -import digitalio -import voluptuous as vol - -from homeassistant.components.switch import PLATFORM_SCHEMA, SwitchEntity -from homeassistant.const import DEVICE_DEFAULT_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 - -CONF_INVERT_LOGIC = "invert_logic" -CONF_I2C_ADDRESS = "i2c_address" -CONF_PINS = "pins" -CONF_PULL_MODE = "pull_mode" - -DEFAULT_INVERT_LOGIC = False -DEFAULT_I2C_ADDRESS = 0x20 - -_SWITCHES_SCHEMA = vol.Schema({cv.positive_int: cv.string}) - -PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( - { - vol.Required(CONF_PINS): _SWITCHES_SCHEMA, - vol.Optional(CONF_INVERT_LOGIC, default=DEFAULT_INVERT_LOGIC): cv.boolean, - vol.Optional(CONF_I2C_ADDRESS, default=DEFAULT_I2C_ADDRESS): vol.Coerce(int), - } -) - -_LOGGER = logging.getLogger(__name__) - - -def setup_platform( - hass: HomeAssistant, - config: ConfigType, - add_entities: AddEntitiesCallback, - discovery_info: DiscoveryInfoType | None = None, -) -> None: - """Set up the MCP23017 devices.""" - _LOGGER.warning( - "The MCP23017 I/O Expander integration is deprecated and will be removed " - "in Home Assistant Core 2022.4; this integration is removed under " - "Architectural Decision Record 0019, more information can be found here: " - "https://github.com/home-assistant/architecture/blob/master/adr/0019-GPIO.md" - ) - invert_logic = config.get(CONF_INVERT_LOGIC) - i2c_address = config.get(CONF_I2C_ADDRESS) - - i2c = busio.I2C(board.SCL, board.SDA) - mcp = MCP23017(i2c, address=i2c_address) - - switches = [] - pins = config[CONF_PINS] - for pin_num, pin_name in pins.items(): - pin = mcp.get_pin(pin_num) - switches.append(MCP23017Switch(pin_name, pin, invert_logic)) - add_entities(switches) - - -class MCP23017Switch(SwitchEntity): - """Representation of a MCP23017 output pin.""" - - def __init__(self, name, pin, invert_logic): - """Initialize the pin.""" - self._name = name or DEVICE_DEFAULT_NAME - self._pin = pin - self._invert_logic = invert_logic - self._state = False - - self._pin.direction = digitalio.Direction.OUTPUT - self._pin.value = self._invert_logic - - @property - def name(self): - """Return the name of the switch.""" - return self._name - - @property - def should_poll(self): - """No polling needed.""" - return False - - @property - def is_on(self): - """Return true if device is on.""" - return self._state - - @property - def assumed_state(self): - """Return true if optimistic updates are used.""" - return True - - def turn_on(self, **kwargs): - """Turn the device on.""" - self._pin.value = not self._invert_logic - self._state = True - self.schedule_update_ha_state() - - def turn_off(self, **kwargs): - """Turn the device off.""" - self._pin.value = self._invert_logic - self._state = False - self.schedule_update_ha_state() diff --git a/requirements_all.txt b/requirements_all.txt index d40f0bae869..923c8f45956 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -50,7 +50,6 @@ PyViCare==2.16.1 PyXiaomiGateway==0.13.4 # homeassistant.components.bmp280 -# homeassistant.components.mcp23017 # homeassistant.components.rpi_gpio # RPi.GPIO==0.7.1a4 @@ -78,9 +77,6 @@ accuweather==0.3.0 # homeassistant.components.bmp280 adafruit-circuitpython-bmp280==3.1.1 -# homeassistant.components.mcp23017 -adafruit-circuitpython-mcp230xx==2.2.2 - # homeassistant.components.adax adax==0.2.0