mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
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:
parent
6adc5c318e
commit
59cad0f6ef
@ -51,7 +51,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||||||
for port_num, port_name in ports.items():
|
for port_num, port_name in ports.items():
|
||||||
binary_sensors.append(RPiGPIOBinarySensor(
|
binary_sensors.append(RPiGPIOBinarySensor(
|
||||||
port_name, port_num, pull_mode, bouncetime, invert_logic))
|
port_name, port_num, pull_mode, bouncetime, invert_logic))
|
||||||
add_devices(binary_sensors)
|
add_devices(binary_sensors, True)
|
||||||
|
|
||||||
|
|
||||||
class RPiGPIOBinarySensor(BinarySensorDevice):
|
class RPiGPIOBinarySensor(BinarySensorDevice):
|
||||||
@ -65,9 +65,9 @@ class RPiGPIOBinarySensor(BinarySensorDevice):
|
|||||||
self._pull_mode = pull_mode
|
self._pull_mode = pull_mode
|
||||||
self._bouncetime = bouncetime
|
self._bouncetime = bouncetime
|
||||||
self._invert_logic = invert_logic
|
self._invert_logic = invert_logic
|
||||||
|
self._state = None
|
||||||
|
|
||||||
rpi_gpio.setup_input(self._port, self._pull_mode)
|
rpi_gpio.setup_input(self._port, self._pull_mode)
|
||||||
self._state = rpi_gpio.read_input(self._port)
|
|
||||||
|
|
||||||
def read_gpio(port):
|
def read_gpio(port):
|
||||||
"""Read state from GPIO."""
|
"""Read state from GPIO."""
|
||||||
@ -90,3 +90,7 @@ class RPiGPIOBinarySensor(BinarySensorDevice):
|
|||||||
def is_on(self):
|
def is_on(self):
|
||||||
"""Return the state of the entity."""
|
"""Return the state of the entity."""
|
||||||
return self._state != self._invert_logic
|
return self._state != self._invert_logic
|
||||||
|
|
||||||
|
def update(self):
|
||||||
|
"""Update the GPIO state."""
|
||||||
|
self._state = rpi_gpio.read_input(self._port)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user