confighelper: fix json parsing error for gpios

Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
Eric Callahan 2021-11-23 08:21:56 -05:00
parent 4e8e4f7d14
commit 0a1367744f
2 changed files with 13 additions and 3 deletions

View File

@ -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)

View File

@ -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,