mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 03:07:37 +00:00
Simplify imports in remote_rpi_gpio (#125745)
This commit is contained in:
parent
eb66a2f32f
commit
3a05855f71
@ -15,7 +15,6 @@ import homeassistant.helpers.config_validation as cv
|
|||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||||
|
|
||||||
from .. import remote_rpi_gpio
|
|
||||||
from . import (
|
from . import (
|
||||||
CONF_BOUNCETIME,
|
CONF_BOUNCETIME,
|
||||||
CONF_INVERT_LOGIC,
|
CONF_INVERT_LOGIC,
|
||||||
@ -23,6 +22,8 @@ from . import (
|
|||||||
DEFAULT_BOUNCETIME,
|
DEFAULT_BOUNCETIME,
|
||||||
DEFAULT_INVERT_LOGIC,
|
DEFAULT_INVERT_LOGIC,
|
||||||
DEFAULT_PULL_MODE,
|
DEFAULT_PULL_MODE,
|
||||||
|
read_input,
|
||||||
|
setup_input,
|
||||||
)
|
)
|
||||||
|
|
||||||
CONF_PORTS = "ports"
|
CONF_PORTS = "ports"
|
||||||
@ -56,9 +57,7 @@ def setup_platform(
|
|||||||
devices = []
|
devices = []
|
||||||
for port_num, port_name in ports.items():
|
for port_num, port_name in ports.items():
|
||||||
try:
|
try:
|
||||||
remote_sensor = remote_rpi_gpio.setup_input(
|
remote_sensor = setup_input(address, port_num, pull_mode, bouncetime)
|
||||||
address, port_num, pull_mode, bouncetime
|
|
||||||
)
|
|
||||||
except (ValueError, IndexError, KeyError, OSError):
|
except (ValueError, IndexError, KeyError, OSError):
|
||||||
return
|
return
|
||||||
new_sensor = RemoteRPiGPIOBinarySensor(port_name, remote_sensor, invert_logic)
|
new_sensor = RemoteRPiGPIOBinarySensor(port_name, remote_sensor, invert_logic)
|
||||||
@ -84,7 +83,7 @@ class RemoteRPiGPIOBinarySensor(BinarySensorEntity):
|
|||||||
|
|
||||||
def read_gpio():
|
def read_gpio():
|
||||||
"""Read state from 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.schedule_update_ha_state()
|
||||||
|
|
||||||
self._sensor.when_deactivated = read_gpio
|
self._sensor.when_deactivated = read_gpio
|
||||||
@ -108,6 +107,6 @@ class RemoteRPiGPIOBinarySensor(BinarySensorEntity):
|
|||||||
def update(self) -> None:
|
def update(self) -> None:
|
||||||
"""Update the GPIO state."""
|
"""Update the GPIO state."""
|
||||||
try:
|
try:
|
||||||
self._state = remote_rpi_gpio.read_input(self._sensor)
|
self._state = read_input(self._sensor)
|
||||||
except requests.exceptions.ConnectionError:
|
except requests.exceptions.ConnectionError:
|
||||||
return
|
return
|
||||||
|
@ -16,8 +16,7 @@ import homeassistant.helpers.config_validation as cv
|
|||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||||
|
|
||||||
from .. import remote_rpi_gpio
|
from . import CONF_INVERT_LOGIC, DEFAULT_INVERT_LOGIC, setup_output, write_output
|
||||||
from . import CONF_INVERT_LOGIC, DEFAULT_INVERT_LOGIC
|
|
||||||
|
|
||||||
CONF_PORTS = "ports"
|
CONF_PORTS = "ports"
|
||||||
|
|
||||||
@ -46,7 +45,7 @@ def setup_platform(
|
|||||||
devices = []
|
devices = []
|
||||||
for port, name in ports.items():
|
for port, name in ports.items():
|
||||||
try:
|
try:
|
||||||
led = remote_rpi_gpio.setup_output(address, port, invert_logic)
|
led = setup_output(address, port, invert_logic)
|
||||||
except (ValueError, IndexError, KeyError, OSError):
|
except (ValueError, IndexError, KeyError, OSError):
|
||||||
return
|
return
|
||||||
new_switch = RemoteRPiGPIOSwitch(name, led)
|
new_switch = RemoteRPiGPIOSwitch(name, led)
|
||||||
@ -83,12 +82,12 @@ class RemoteRPiGPIOSwitch(SwitchEntity):
|
|||||||
|
|
||||||
def turn_on(self, **kwargs: Any) -> None:
|
def turn_on(self, **kwargs: Any) -> None:
|
||||||
"""Turn the device on."""
|
"""Turn the device on."""
|
||||||
remote_rpi_gpio.write_output(self._switch, 1)
|
write_output(self._switch, 1)
|
||||||
self._state = True
|
self._state = True
|
||||||
self.schedule_update_ha_state()
|
self.schedule_update_ha_state()
|
||||||
|
|
||||||
def turn_off(self, **kwargs: Any) -> None:
|
def turn_off(self, **kwargs: Any) -> None:
|
||||||
"""Turn the device off."""
|
"""Turn the device off."""
|
||||||
remote_rpi_gpio.write_output(self._switch, 0)
|
write_output(self._switch, 0)
|
||||||
self._state = False
|
self._state = False
|
||||||
self.schedule_update_ha_state()
|
self.schedule_update_ha_state()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user