From 2bb5573ddc296eb4e5ab679e5a63e462f827e5db Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Sat, 12 Mar 2022 13:04:46 +0100 Subject: [PATCH] Remove deprecated PiFace Digital I/O (PFIO) integration (#67282) --- .coveragerc | 1 - homeassistant/components/rpi_pfio/__init__.py | 62 ------------- .../components/rpi_pfio/binary_sensor.py | 90 ------------------- .../components/rpi_pfio/manifest.json | 9 -- homeassistant/components/rpi_pfio/switch.py | 85 ------------------ requirements_all.txt | 6 -- 6 files changed, 253 deletions(-) delete mode 100644 homeassistant/components/rpi_pfio/__init__.py delete mode 100644 homeassistant/components/rpi_pfio/binary_sensor.py delete mode 100644 homeassistant/components/rpi_pfio/manifest.json delete mode 100644 homeassistant/components/rpi_pfio/switch.py diff --git a/.coveragerc b/.coveragerc index 95856947fb6..aa2eef16079 100644 --- a/.coveragerc +++ b/.coveragerc @@ -983,7 +983,6 @@ omit = homeassistant/components/rova/sensor.py homeassistant/components/rpi_camera/* homeassistant/components/rpi_gpio/* - homeassistant/components/rpi_pfio/* homeassistant/components/rtorrent/sensor.py homeassistant/components/russound_rio/media_player.py homeassistant/components/russound_rnet/media_player.py diff --git a/homeassistant/components/rpi_pfio/__init__.py b/homeassistant/components/rpi_pfio/__init__.py deleted file mode 100644 index c4687c59114..00000000000 --- a/homeassistant/components/rpi_pfio/__init__.py +++ /dev/null @@ -1,62 +0,0 @@ -"""Support for controlling the PiFace Digital I/O module on a RPi.""" -import logging - -import pifacedigitalio as PFIO - -from homeassistant.const import EVENT_HOMEASSISTANT_START, EVENT_HOMEASSISTANT_STOP -from homeassistant.core import HomeAssistant -from homeassistant.helpers.typing import ConfigType - -DOMAIN = "rpi_pfio" - -DATA_PFIO_LISTENER = "pfio_listener" - -_LOGGER = logging.getLogger(__name__) - - -def setup(hass: HomeAssistant, config: ConfigType) -> bool: - """Set up the Raspberry PI PFIO component.""" - _LOGGER.warning( - "The PiFace Digital I/O (PFIO) 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" - ) - - pifacedigital = PFIO.PiFaceDigital() - hass.data[DATA_PFIO_LISTENER] = PFIO.InputEventListener(chip=pifacedigital) - - def cleanup_pfio(event): - """Stuff to do before stopping.""" - PFIO.deinit() - - def prepare_pfio(event): - """Stuff to do when Home Assistant starts.""" - hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, cleanup_pfio) - - hass.bus.listen_once(EVENT_HOMEASSISTANT_START, prepare_pfio) - PFIO.init() - - return True - - -def write_output(port, value): - """Write a value to a PFIO.""" - PFIO.digital_write(port, value) - - -def read_input(port): - """Read a value from a PFIO.""" - return PFIO.digital_read(port) - - -def edge_detect(hass, port, event_callback, settle): - """Add detection for RISING and FALLING events.""" - hass.data[DATA_PFIO_LISTENER].register( - port, PFIO.IODIR_BOTH, event_callback, settle_time=settle - ) - - -def activate_listener(hass): - """Activate the registered listener events.""" - hass.data[DATA_PFIO_LISTENER].activate() diff --git a/homeassistant/components/rpi_pfio/binary_sensor.py b/homeassistant/components/rpi_pfio/binary_sensor.py deleted file mode 100644 index ddce88949fd..00000000000 --- a/homeassistant/components/rpi_pfio/binary_sensor.py +++ /dev/null @@ -1,90 +0,0 @@ -"""Support for binary sensor using the PiFace Digital I/O module on a RPi.""" -from __future__ import annotations - -import voluptuous as vol - -from homeassistant.components import rpi_pfio -from homeassistant.components.binary_sensor import PLATFORM_SCHEMA, BinarySensorEntity -from homeassistant.const import CONF_NAME, 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_PORTS = "ports" -CONF_SETTLE_TIME = "settle_time" - -DEFAULT_INVERT_LOGIC = False -DEFAULT_SETTLE_TIME = 20 - -PORT_SCHEMA = vol.Schema( - { - vol.Optional(CONF_NAME): cv.string, - vol.Optional(CONF_SETTLE_TIME, default=DEFAULT_SETTLE_TIME): cv.positive_int, - vol.Optional(CONF_INVERT_LOGIC, default=DEFAULT_INVERT_LOGIC): cv.boolean, - } -) - -PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( - {vol.Optional(CONF_PORTS, default={}): vol.Schema({cv.positive_int: PORT_SCHEMA})} -) - - -def setup_platform( - hass: HomeAssistant, - config: ConfigType, - add_entities: AddEntitiesCallback, - discovery_info: DiscoveryInfoType | None = None, -) -> None: - """Set up the PiFace Digital Input devices.""" - binary_sensors = [] - ports = config[CONF_PORTS] - for port, port_entity in ports.items(): - name = port_entity.get(CONF_NAME) - settle_time = port_entity[CONF_SETTLE_TIME] / 1000 - invert_logic = port_entity[CONF_INVERT_LOGIC] - - binary_sensors.append( - RPiPFIOBinarySensor(hass, port, name, settle_time, invert_logic) - ) - add_entities(binary_sensors, True) - - rpi_pfio.activate_listener(hass) - - -class RPiPFIOBinarySensor(BinarySensorEntity): - """Represent a binary sensor that a PiFace Digital Input.""" - - def __init__(self, hass, port, name, settle_time, invert_logic): - """Initialize the RPi binary sensor.""" - self._port = port - self._name = name or DEVICE_DEFAULT_NAME - self._invert_logic = invert_logic - self._state = None - - def read_pfio(port): - """Read state from PFIO.""" - self._state = rpi_pfio.read_input(self._port) - self.schedule_update_ha_state() - - rpi_pfio.edge_detect(hass, self._port, read_pfio, settle_time) - - @property - def should_poll(self): - """No polling needed.""" - return False - - @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 PFIO state.""" - self._state = rpi_pfio.read_input(self._port) diff --git a/homeassistant/components/rpi_pfio/manifest.json b/homeassistant/components/rpi_pfio/manifest.json deleted file mode 100644 index 7f72a7ba77d..00000000000 --- a/homeassistant/components/rpi_pfio/manifest.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "domain": "rpi_pfio", - "name": "PiFace Digital I/O (PFIO)", - "documentation": "https://www.home-assistant.io/integrations/rpi_pfio", - "requirements": ["pifacecommon==4.2.2", "pifacedigitalio==3.0.5"], - "codeowners": [], - "iot_class": "local_push", - "loggers": ["pifacedigitalio"] -} diff --git a/homeassistant/components/rpi_pfio/switch.py b/homeassistant/components/rpi_pfio/switch.py deleted file mode 100644 index ca3d176eecb..00000000000 --- a/homeassistant/components/rpi_pfio/switch.py +++ /dev/null @@ -1,85 +0,0 @@ -"""Support for switches using the PiFace Digital I/O module on a RPi.""" -from __future__ import annotations - -import voluptuous as vol - -from homeassistant.components import rpi_pfio -from homeassistant.components.switch import PLATFORM_SCHEMA, SwitchEntity -from homeassistant.const import ATTR_NAME, 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 - -ATTR_INVERT_LOGIC = "invert_logic" - -CONF_PORTS = "ports" - -DEFAULT_INVERT_LOGIC = False - -PORT_SCHEMA = vol.Schema( - { - vol.Optional(ATTR_NAME): cv.string, - vol.Optional(ATTR_INVERT_LOGIC, default=DEFAULT_INVERT_LOGIC): cv.boolean, - } -) - -PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( - {vol.Optional(CONF_PORTS, default={}): vol.Schema({cv.positive_int: PORT_SCHEMA})} -) - - -def setup_platform( - hass: HomeAssistant, - config: ConfigType, - add_entities: AddEntitiesCallback, - discovery_info: DiscoveryInfoType | None = None, -) -> None: - """Set up the PiFace Digital Output devices.""" - switches = [] - ports = config[CONF_PORTS] - for port, port_entity in ports.items(): - name = port_entity.get(ATTR_NAME) - invert_logic = port_entity[ATTR_INVERT_LOGIC] - - switches.append(RPiPFIOSwitch(port, name, invert_logic)) - add_entities(switches) - - -class RPiPFIOSwitch(SwitchEntity): - """Representation of a PiFace Digital Output.""" - - def __init__(self, port, name, invert_logic): - """Initialize the pin.""" - self._port = port - self._name = name or DEVICE_DEFAULT_NAME - self._invert_logic = invert_logic - self._state = False - rpi_pfio.write_output(self._port, 1 if self._invert_logic else 0) - - @property - def name(self): - """Return the name of the switch.""" - return self._name - - @property - def should_poll(self): - """Return the polling state.""" - return False - - @property - def is_on(self): - """Return true if device is on.""" - return self._state - - def turn_on(self, **kwargs): - """Turn the device on.""" - rpi_pfio.write_output(self._port, 0 if self._invert_logic else 1) - self._state = True - self.schedule_update_ha_state() - - def turn_off(self, **kwargs): - """Turn the device off.""" - rpi_pfio.write_output(self._port, 1 if self._invert_logic else 0) - self._state = False - self.schedule_update_ha_state() diff --git a/requirements_all.txt b/requirements_all.txt index fa3e8e745c9..2b7667e524f 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -1192,12 +1192,6 @@ phone_modem==0.1.1 # homeassistant.components.onewire pi1wire==0.1.0 -# homeassistant.components.rpi_pfio -pifacecommon==4.2.2 - -# homeassistant.components.rpi_pfio -pifacedigitalio==3.0.5 - # homeassistant.components.pilight pilight==0.1.1