From 0a1367744fbd860e07fca2353b340d5159233ab7 Mon Sep 17 00:00:00 2001 From: Eric Callahan Date: Tue, 23 Nov 2021 08:21:56 -0500 Subject: [PATCH] confighelper: fix json parsing error for gpios Signed-off-by: Eric Callahan --- moonraker/components/gpio.py | 8 +++++++- moonraker/confighelper.py | 8 ++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/moonraker/components/gpio.py b/moonraker/components/gpio.py index 329a502..0b786e7 100644 --- a/moonraker/components/gpio.py +++ b/moonraker/components/gpio.py @@ -62,7 +62,8 @@ class GpioFactory: f"Unable to init {pin_id}. Make sure the gpio is not in " "use by another program or exported by sysfs.") raise - gpio_out = GpioOutputPin(full_name, line, invert, initial_value) + gpio_out = GpioOutputPin(pin_name, full_name, line, invert, + initial_value) self.reserved_gpios[full_name] = gpio_out return gpio_out @@ -96,11 +97,13 @@ class GpioFactory: class GpioOutputPin: def __init__(self, + orig_name: str, name: str, line: Any, inverted: bool, initial_val: int ) -> None: + self.orig = orig_name self.name = name self.line = line self.inverted = inverted @@ -120,5 +123,8 @@ class GpioOutputPin: def get_name(self) -> str: return self.name + def __str__(self) -> str: + return self.orig + def load_component(config: ConfigHelper) -> GpioFactory: return GpioFactory(config) diff --git a/moonraker/confighelper.py b/moonraker/confighelper.py index b2c6ac9..499f5ab 100644 --- a/moonraker/confighelper.py +++ b/moonraker/confighelper.py @@ -8,6 +8,7 @@ from __future__ import annotations import configparser import os from utils import SentinelClass +from components.gpio import GpioOutputPin # Annotation imports from typing import ( @@ -25,7 +26,7 @@ from typing import ( ) if TYPE_CHECKING: from moonraker import Server - from .components.gpio import GpioFactory, GpioOutputPin + from components.gpio import GpioFactory _T = TypeVar("_T") ConfigVal = Union[None, int, float, bool, str] @@ -105,7 +106,10 @@ class ConfigHelper: self._check_option(option, val, above, below, minval, maxval) if self.section in self.orig_sections: # Only track sections included in the original config - self.parsed[self.section][option] = val + if isinstance(val, GpioOutputPin): + self.parsed[self.section][option] = str(val) + else: + self.parsed[self.section][option] = val return val def _check_option(self,