add a small sleep before reading the rpi-gpio sensor (#5446)

* add a small sleep before reading the sensor

The read of the sensor might be incorrect if it's read too soon after the setup_input call. It might be isolated to my case where I rely on the the PI internal PULL, but once I added this sleep I never get false initial read. If you think this change is appropriate please merge it.

* Update rpi_gpio.py

* Update rpi_gpio.py

* Update rpi_gpio.py
This commit is contained in:
snagytx 2017-01-24 23:35:12 -06:00 committed by Paulus Schoutsen
parent 6adc5c318e
commit 59cad0f6ef

View File

@ -51,7 +51,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
for port_num, port_name in ports.items():
binary_sensors.append(RPiGPIOBinarySensor(
port_name, port_num, pull_mode, bouncetime, invert_logic))
add_devices(binary_sensors)
add_devices(binary_sensors, True)
class RPiGPIOBinarySensor(BinarySensorDevice):
@ -65,9 +65,9 @@ class RPiGPIOBinarySensor(BinarySensorDevice):
self._pull_mode = pull_mode
self._bouncetime = bouncetime
self._invert_logic = invert_logic
self._state = None
rpi_gpio.setup_input(self._port, self._pull_mode)
self._state = rpi_gpio.read_input(self._port)
def read_gpio(port):
"""Read state from GPIO."""
@ -90,3 +90,7 @@ class RPiGPIOBinarySensor(BinarySensorDevice):
def is_on(self):
"""Return the state of the entity."""
return self._state != self._invert_logic
def update(self):
"""Update the GPIO state."""
self._state = rpi_gpio.read_input(self._port)