Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix wrong sensor value when pull_mode=UP #322

Merged
merged 1 commit into from
Dec 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions custom_components/rpi_gpio/hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,26 +181,30 @@ def add_sensor(self, entity, port, active_low, bias, debounce) -> None:
self.verify_online()
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._config[port] = gpiod.LineSettings(
direction = Direction.INPUT,
edge_detection = Edge.BOTH,
bias = BIAS[bias],
active_low = active_low,
debounce_period = timedelta(milliseconds=debounce),
event_clock = Clock.REALTIME,
output_value = Value.ACTIVE if entity.is_on else Value.INACTIVE,
event_clock = Clock.REALTIME
)

# 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

def get_line_value(self, port, **kwargs):
def get_line_value(self, port):
return self._lines.get_value(port) == Value.ACTIVE

def add_cover(self, entity, relay_port, relay_active_low, relay_bias, relay_drive,
Expand Down