Simplify imports in remote_rpi_gpio (#125745)

pull/125743/head^2
epenet 2024-09-11 14:19:49 +02:00 committed by GitHub
parent eb66a2f32f
commit 3a05855f71
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 11 deletions

View File

@ -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

View File

@ -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()