From f6838ff9043fd43064f74bd18b887684a0273840 Mon Sep 17 00:00:00 2001 From: Artur Albov Date: Sun, 20 Oct 2024 13:51:58 +0200 Subject: [PATCH] Fix KeyError for gpiozero digital_outputs #414 --- mqtt_io/modules/gpio/gpiozero.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/mqtt_io/modules/gpio/gpiozero.py b/mqtt_io/modules/gpio/gpiozero.py index a1ad88c1..10f9ff9d 100644 --- a/mqtt_io/modules/gpio/gpiozero.py +++ b/mqtt_io/modules/gpio/gpiozero.py @@ -80,9 +80,14 @@ def set_pin(self, pin: PinType, value: bool) -> None: self._out_pins[pin].on() else: self._out_pins[pin].off() - + def get_pin(self, pin: PinType) -> bool: - return cast(bool, self._in_pins[pin].is_active) + if pin in self._in_pins: + return cast(bool, self._in_pins[pin].is_active) + elif pin in self._out_pins: + return bool(self._out_pins[pin].value) + else: + raise ValueError(f"Pin {pin} not found") def setup_interrupt_callback( self,