mirror of
https://github.com/thecode/ha-rpi_gpio.git
synced 2025-07-27 04:36:34 +00:00
Fix wrong sensor value when pull_mode=UP (#322)
This commit is contained in:
parent
77c33715a8
commit
3e4867c3ff
@ -181,13 +181,6 @@ class Hub:
|
|||||||
self.verify_online()
|
self.verify_online()
|
||||||
self.verify_port_ready(port)
|
self.verify_port_ready(port)
|
||||||
|
|
||||||
# read current status of the sensor
|
|
||||||
line = self._chip.request_lines({ port: {} })
|
|
||||||
value = True if line.get_value(port) == Value.ACTIVE else False
|
|
||||||
entity.is_on = True if value ^ active_low else False
|
|
||||||
line.release()
|
|
||||||
_LOGGER.debug(f"current value for port {port}: {entity.is_on}")
|
|
||||||
|
|
||||||
self._entities[port] = entity
|
self._entities[port] = entity
|
||||||
self._config[port] = gpiod.LineSettings(
|
self._config[port] = gpiod.LineSettings(
|
||||||
direction = Direction.INPUT,
|
direction = Direction.INPUT,
|
||||||
@ -195,12 +188,23 @@ class Hub:
|
|||||||
bias = BIAS[bias],
|
bias = BIAS[bias],
|
||||||
active_low = active_low,
|
active_low = active_low,
|
||||||
debounce_period = timedelta(milliseconds=debounce),
|
debounce_period = timedelta(milliseconds=debounce),
|
||||||
event_clock = Clock.REALTIME,
|
event_clock = Clock.REALTIME
|
||||||
output_value = Value.ACTIVE if entity.is_on else Value.INACTIVE,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# read current status of the sensor
|
||||||
|
with self._chip.request_lines(
|
||||||
|
consumer=DOMAIN,
|
||||||
|
config={port: gpiod.LineSettings(
|
||||||
|
direction = Direction.INPUT,
|
||||||
|
bias = BIAS[bias],
|
||||||
|
active_low = active_low)},
|
||||||
|
) as request:
|
||||||
|
entity._attr_is_on = True if request.get_value(port) == Value.ACTIVE else False
|
||||||
|
|
||||||
|
_LOGGER.debug(f"current value for port {port}: {entity.is_on}")
|
||||||
self._edge_events = True
|
self._edge_events = True
|
||||||
|
|
||||||
def get_line_value(self, port, **kwargs):
|
def get_line_value(self, port):
|
||||||
return self._lines.get_value(port) == Value.ACTIVE
|
return self._lines.get_value(port) == Value.ACTIVE
|
||||||
|
|
||||||
def add_cover(self, entity, relay_port, relay_active_low, relay_bias, relay_drive,
|
def add_cover(self, entity, relay_port, relay_active_low, relay_bias, relay_drive,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user