More general parsing

This commit is contained in:
Andre Basche 2023-05-06 16:07:28 +02:00
parent 7dcb34559b
commit ea8f481b01
10 changed files with 165 additions and 128 deletions

View file

@ -2,12 +2,13 @@ from typing import Dict, Any, List
class HonParameter:
def __init__(self, key: str, attributes: Dict[str, Any]) -> None:
def __init__(self, key: str, attributes: Dict[str, Any], group: str) -> None:
self._key = key
self._category: str = attributes.get("category", "")
self._typology: str = attributes.get("typology", "")
self._mandatory: int = attributes.get("mandatory", 0)
self._value: str | float = ""
self._group: str = group
@property
def key(self) -> str:
@ -19,7 +20,7 @@ class HonParameter:
@property
def values(self) -> List[str]:
return list(str(self.value))
return [str(self.value)]
@property
def category(self) -> str:
@ -32,3 +33,7 @@ class HonParameter:
@property
def mandatory(self) -> int:
return self._mandatory
@property
def group(self) -> str:
return self._group

View file

@ -4,8 +4,8 @@ from pyhon.parameter.base import HonParameter
class HonParameterEnum(HonParameter):
def __init__(self, key: str, attributes: Dict[str, Any]) -> None:
super().__init__(key, attributes)
def __init__(self, key: str, attributes: Dict[str, Any], group: str) -> None:
super().__init__(key, attributes, group)
self._default = attributes.get("defaultValue")
self._value = self._default or "0"
self._values: List[str] = attributes.get("enumValues", [])

View file

@ -4,8 +4,8 @@ from pyhon.parameter.base import HonParameter
class HonParameterFixed(HonParameter):
def __init__(self, key: str, attributes: Dict[str, Any]) -> None:
super().__init__(key, attributes)
def __init__(self, key: str, attributes: Dict[str, Any], group: str) -> None:
super().__init__(key, attributes, group)
self._value = attributes.get("fixedValue", None)
def __repr__(self) -> str:

View file

@ -9,11 +9,11 @@ if TYPE_CHECKING:
class HonParameterProgram(HonParameterEnum):
_FILTER = ["iot_recipe", "iot_guided"]
def __init__(self, key: str, command: "HonCommand") -> None:
super().__init__(key, {})
def __init__(self, key: str, command: "HonCommand", group: str) -> None:
super().__init__(key, {}, group)
self._command = command
self._value: str = command.program
self._programs: Dict[str, "HonCommand"] = command.programs
self._value: str = command.category
self._programs: Dict[str, "HonCommand"] = command.categories
self._typology: str = "enum"
@property

View file

@ -11,8 +11,8 @@ def str_to_float(string: str | float) -> float:
class HonParameterRange(HonParameter):
def __init__(self, key: str, attributes: Dict[str, Any]) -> None:
super().__init__(key, attributes)
def __init__(self, key: str, attributes: Dict[str, Any], group: str) -> None:
super().__init__(key, attributes, group)
self._min: float = str_to_float(attributes["minimumValue"])
self._max: float = str_to_float(attributes["maximumValue"])
self._step: float = str_to_float(attributes["incrementValue"])