From 3a05855f716be4797207e47d66ba462bf53fcc80 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Wed, 11 Sep 2024 14:19:49 +0200 Subject: [PATCH] Simplify imports in remote_rpi_gpio (#125745) --- .../components/remote_rpi_gpio/binary_sensor.py | 11 +++++------ homeassistant/components/remote_rpi_gpio/switch.py | 9 ++++----- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/homeassistant/components/remote_rpi_gpio/binary_sensor.py b/homeassistant/components/remote_rpi_gpio/binary_sensor.py index 98ae7328bc5..b3a8075c6ba 100644 --- a/homeassistant/components/remote_rpi_gpio/binary_sensor.py +++ b/homeassistant/components/remote_rpi_gpio/binary_sensor.py @@ -15,7 +15,6 @@ import homeassistant.helpers.config_validation as cv from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType -from .. import remote_rpi_gpio from . import ( CONF_BOUNCETIME, CONF_INVERT_LOGIC, @@ -23,6 +22,8 @@ from . import ( DEFAULT_BOUNCETIME, DEFAULT_INVERT_LOGIC, DEFAULT_PULL_MODE, + read_input, + setup_input, ) CONF_PORTS = "ports" @@ -56,9 +57,7 @@ def setup_platform( devices = [] for port_num, port_name in ports.items(): try: - remote_sensor = remote_rpi_gpio.setup_input( - address, port_num, pull_mode, bouncetime - ) + remote_sensor = setup_input(address, port_num, pull_mode, bouncetime) except (ValueError, IndexError, KeyError, OSError): return new_sensor = RemoteRPiGPIOBinarySensor(port_name, remote_sensor, invert_logic) @@ -84,7 +83,7 @@ class RemoteRPiGPIOBinarySensor(BinarySensorEntity): def read_gpio(): """Read state from GPIO.""" - self._state = remote_rpi_gpio.read_input(self._sensor) + self._state = read_input(self._sensor) self.schedule_update_ha_state() self._sensor.when_deactivated = read_gpio @@ -108,6 +107,6 @@ class RemoteRPiGPIOBinarySensor(BinarySensorEntity): def update(self) -> None: """Update the GPIO state.""" try: - self._state = remote_rpi_gpio.read_input(self._sensor) + self._state = read_input(self._sensor) except requests.exceptions.ConnectionError: return diff --git a/homeassistant/components/remote_rpi_gpio/switch.py b/homeassistant/components/remote_rpi_gpio/switch.py index ff9ecbcd97b..bf31e4bb55a 100644 --- a/homeassistant/components/remote_rpi_gpio/switch.py +++ b/homeassistant/components/remote_rpi_gpio/switch.py @@ -16,8 +16,7 @@ import homeassistant.helpers.config_validation as cv from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType -from .. import remote_rpi_gpio -from . import CONF_INVERT_LOGIC, DEFAULT_INVERT_LOGIC +from . import CONF_INVERT_LOGIC, DEFAULT_INVERT_LOGIC, setup_output, write_output CONF_PORTS = "ports" @@ -46,7 +45,7 @@ def setup_platform( devices = [] for port, name in ports.items(): try: - led = remote_rpi_gpio.setup_output(address, port, invert_logic) + led = setup_output(address, port, invert_logic) except (ValueError, IndexError, KeyError, OSError): return new_switch = RemoteRPiGPIOSwitch(name, led) @@ -83,12 +82,12 @@ class RemoteRPiGPIOSwitch(SwitchEntity): def turn_on(self, **kwargs: Any) -> None: """Turn the device on.""" - remote_rpi_gpio.write_output(self._switch, 1) + write_output(self._switch, 1) self._state = True self.schedule_update_ha_state() def turn_off(self, **kwargs: Any) -> None: """Turn the device off.""" - remote_rpi_gpio.write_output(self._switch, 0) + write_output(self._switch, 0) self._state = False self.schedule_update_ha_state()