diff --git a/homeassistant/components/remote_rpi_gpio/__init__.py b/homeassistant/components/remote_rpi_gpio/__init__.py index afa60e44bed..b11625eb7b2 100644 --- a/homeassistant/components/remote_rpi_gpio/__init__.py +++ b/homeassistant/components/remote_rpi_gpio/__init__.py @@ -1,5 +1,5 @@ """Support for controlling GPIO pins of a Raspberry Pi.""" -from gpiozero import LED, Button +from gpiozero import LED, DigitalInputDevice from gpiozero.pins.pigpio import PiGPIOFactory CONF_BOUNCETIME = "bouncetime" @@ -38,7 +38,7 @@ def setup_input(address, port, pull_mode, bouncetime): pull_gpio_up = False try: - return Button( + return DigitalInputDevice( port, pull_up=pull_gpio_up, bounce_time=bouncetime, @@ -56,6 +56,6 @@ def write_output(switch, value): switch.off() -def read_input(button): +def read_input(sensor): """Read a value from a GPIO.""" - return button.is_pressed + return sensor.value diff --git a/homeassistant/components/remote_rpi_gpio/binary_sensor.py b/homeassistant/components/remote_rpi_gpio/binary_sensor.py index 86966ec4d87..aeff838d68d 100644 --- a/homeassistant/components/remote_rpi_gpio/binary_sensor.py +++ b/homeassistant/components/remote_rpi_gpio/binary_sensor.py @@ -42,12 +42,12 @@ def setup_platform(hass, config, add_entities, discovery_info=None): devices = [] for port_num, port_name in ports.items(): try: - button = remote_rpi_gpio.setup_input( + remote_sensor = remote_rpi_gpio.setup_input( address, port_num, pull_mode, bouncetime ) except (ValueError, IndexError, KeyError, OSError): return - new_sensor = RemoteRPiGPIOBinarySensor(port_name, button, invert_logic) + new_sensor = RemoteRPiGPIOBinarySensor(port_name, remote_sensor, invert_logic) devices.append(new_sensor) add_entities(devices, True) @@ -56,23 +56,23 @@ def setup_platform(hass, config, add_entities, discovery_info=None): class RemoteRPiGPIOBinarySensor(BinarySensorEntity): """Represent a binary sensor that uses a Remote Raspberry Pi GPIO.""" - def __init__(self, name, button, invert_logic): + def __init__(self, name, sensor, invert_logic): """Initialize the RPi binary sensor.""" self._name = name self._invert_logic = invert_logic self._state = False - self._button = button + self._sensor = sensor async def async_added_to_hass(self): """Run when entity about to be added to hass.""" def read_gpio(): """Read state from GPIO.""" - self._state = remote_rpi_gpio.read_input(self._button) + self._state = remote_rpi_gpio.read_input(self._sensor) self.schedule_update_ha_state() - self._button.when_released = read_gpio - self._button.when_pressed = read_gpio + self._sensor.when_deactivated = read_gpio + self._sensor.when_activated = read_gpio @property def should_poll(self): @@ -97,6 +97,6 @@ class RemoteRPiGPIOBinarySensor(BinarySensorEntity): def update(self): """Update the GPIO state.""" try: - self._state = remote_rpi_gpio.read_input(self._button) + self._state = remote_rpi_gpio.read_input(self._sensor) except requests.exceptions.ConnectionError: return