mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 10:17:09 +00:00
Fix Raspi GPIO binary_sensor produces unreliable responses (#48170)
* Fix for issue #10498 Raspi GPIO binary_sensor produces unreliable responses ("Doorbell Scenario") Changes overtaken from PR#31788 which was somehow never finished * Fix for issue #10498 Raspi GPIO binary_sensor produces unreliable response. Changes taken over from PR31788 which was somehow never finished * Remove unused code (pylint warning)
This commit is contained in:
parent
3bc583607f
commit
ecec3c8ab9
@ -1,4 +1,7 @@
|
|||||||
"""Support for binary sensor using RPi GPIO."""
|
"""Support for binary sensor using RPi GPIO."""
|
||||||
|
|
||||||
|
import asyncio
|
||||||
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components import rpi_gpio
|
from homeassistant.components import rpi_gpio
|
||||||
@ -52,6 +55,14 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
|||||||
class RPiGPIOBinarySensor(BinarySensorEntity):
|
class RPiGPIOBinarySensor(BinarySensorEntity):
|
||||||
"""Represent a binary sensor that uses Raspberry Pi GPIO."""
|
"""Represent a binary sensor that uses Raspberry Pi GPIO."""
|
||||||
|
|
||||||
|
async def async_read_gpio(self):
|
||||||
|
"""Read state from GPIO."""
|
||||||
|
await asyncio.sleep(float(self._bouncetime) / 1000)
|
||||||
|
self._state = await self.hass.async_add_executor_job(
|
||||||
|
rpi_gpio.read_input, self._port
|
||||||
|
)
|
||||||
|
self.async_write_ha_state()
|
||||||
|
|
||||||
def __init__(self, name, port, pull_mode, bouncetime, invert_logic):
|
def __init__(self, name, port, pull_mode, bouncetime, invert_logic):
|
||||||
"""Initialize the RPi binary sensor."""
|
"""Initialize the RPi binary sensor."""
|
||||||
self._name = name or DEVICE_DEFAULT_NAME
|
self._name = name or DEVICE_DEFAULT_NAME
|
||||||
@ -63,12 +74,11 @@ class RPiGPIOBinarySensor(BinarySensorEntity):
|
|||||||
|
|
||||||
rpi_gpio.setup_input(self._port, self._pull_mode)
|
rpi_gpio.setup_input(self._port, self._pull_mode)
|
||||||
|
|
||||||
def read_gpio(port):
|
def edge_detected(port):
|
||||||
"""Read state from GPIO."""
|
"""Edge detection handler."""
|
||||||
self._state = rpi_gpio.read_input(self._port)
|
self.hass.add_job(self.async_read_gpio)
|
||||||
self.schedule_update_ha_state()
|
|
||||||
|
|
||||||
rpi_gpio.edge_detect(self._port, read_gpio, self._bouncetime)
|
rpi_gpio.edge_detect(self._port, edge_detected, self._bouncetime)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def should_poll(self):
|
def should_poll(self):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user