Reset commands to defaults
This commit is contained in:
parent
bc7e8994c9
commit
2788a3ac91
@ -169,3 +169,7 @@ class HonCommand:
|
|||||||
else:
|
else:
|
||||||
result[name] = parameter
|
result[name] = parameter
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
def reset(self):
|
||||||
|
for parameter in self._parameters.values():
|
||||||
|
parameter.reset()
|
||||||
|
@ -7,14 +7,21 @@ if TYPE_CHECKING:
|
|||||||
class HonParameter:
|
class HonParameter:
|
||||||
def __init__(self, key: str, attributes: Dict[str, Any], group: str) -> None:
|
def __init__(self, key: str, attributes: Dict[str, Any], group: str) -> None:
|
||||||
self._key = key
|
self._key = key
|
||||||
self._category: str = attributes.get("category", "")
|
self._attributes = attributes
|
||||||
self._typology: str = attributes.get("typology", "")
|
self._category: str = ""
|
||||||
self._mandatory: int = attributes.get("mandatory", 0)
|
self._typology: str = ""
|
||||||
|
self._mandatory: int = 0
|
||||||
self._value: str | float = ""
|
self._value: str | float = ""
|
||||||
self._group: str = group
|
self._group: str = group
|
||||||
self._triggers: Dict[
|
self._triggers: Dict[
|
||||||
str, List[Tuple[Callable[["HonRule"], None], "HonRule"]]
|
str, List[Tuple[Callable[["HonRule"], None], "HonRule"]]
|
||||||
] = {}
|
] = {}
|
||||||
|
self._set_attributes()
|
||||||
|
|
||||||
|
def _set_attributes(self):
|
||||||
|
self._category = self._attributes.get("category", "")
|
||||||
|
self._typology = self._attributes.get("typology", "")
|
||||||
|
self._mandatory = self._attributes.get("mandatory", 0)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def key(self) -> str:
|
def key(self) -> str:
|
||||||
@ -85,3 +92,6 @@ class HonParameter:
|
|||||||
param[rule.param_key] = rule.param_data.get("defaultValue", "")
|
param[rule.param_key] = rule.param_data.get("defaultValue", "")
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
def reset(self):
|
||||||
|
self._set_attributes()
|
||||||
|
@ -10,12 +10,19 @@ def clean_value(value: str | float) -> str:
|
|||||||
class HonParameterEnum(HonParameter):
|
class HonParameterEnum(HonParameter):
|
||||||
def __init__(self, key: str, attributes: Dict[str, Any], group: str) -> None:
|
def __init__(self, key: str, attributes: Dict[str, Any], group: str) -> None:
|
||||||
super().__init__(key, attributes, group)
|
super().__init__(key, attributes, group)
|
||||||
self._default = attributes.get("defaultValue")
|
self._default = ""
|
||||||
self._value = self._default or "0"
|
self._value = ""
|
||||||
self._values: List[str] = attributes.get("enumValues", [])
|
self._values: List[str] = []
|
||||||
|
self._set_attributes()
|
||||||
if self._default and clean_value(self._default.strip("[]")) not in self.values:
|
if self._default and clean_value(self._default.strip("[]")) not in self.values:
|
||||||
self._values.append(self._default)
|
self._values.append(self._default)
|
||||||
|
|
||||||
|
def _set_attributes(self):
|
||||||
|
super()._set_attributes()
|
||||||
|
self._default = self._attributes.get("defaultValue")
|
||||||
|
self._value = self._default or "0"
|
||||||
|
self._values: List[str] = self._attributes.get("enumValues", [])
|
||||||
|
|
||||||
def __repr__(self) -> str:
|
def __repr__(self) -> str:
|
||||||
return f"{self.__class__} (<{self.key}> {self.values})"
|
return f"{self.__class__} (<{self.key}> {self.values})"
|
||||||
|
|
||||||
|
@ -6,7 +6,12 @@ from pyhon.parameter.base import HonParameter
|
|||||||
class HonParameterFixed(HonParameter):
|
class HonParameterFixed(HonParameter):
|
||||||
def __init__(self, key: str, attributes: Dict[str, Any], group: str) -> None:
|
def __init__(self, key: str, attributes: Dict[str, Any], group: str) -> None:
|
||||||
super().__init__(key, attributes, group)
|
super().__init__(key, attributes, group)
|
||||||
self._value = attributes.get("fixedValue", None)
|
self._value = None
|
||||||
|
self._set_attributes()
|
||||||
|
|
||||||
|
def _set_attributes(self):
|
||||||
|
super()._set_attributes()
|
||||||
|
self._value = self._attributes.get("fixedValue", None)
|
||||||
|
|
||||||
def __repr__(self) -> str:
|
def __repr__(self) -> str:
|
||||||
return f"{self.__class__} (<{self.key}> fixed)"
|
return f"{self.__class__} (<{self.key}> fixed)"
|
||||||
|
@ -7,10 +7,19 @@ from pyhon.parameter.base import HonParameter
|
|||||||
class HonParameterRange(HonParameter):
|
class HonParameterRange(HonParameter):
|
||||||
def __init__(self, key: str, attributes: Dict[str, Any], group: str) -> None:
|
def __init__(self, key: str, attributes: Dict[str, Any], group: str) -> None:
|
||||||
super().__init__(key, attributes, group)
|
super().__init__(key, attributes, group)
|
||||||
self._min: float = str_to_float(attributes["minimumValue"])
|
self._min: float = 0
|
||||||
self._max: float = str_to_float(attributes["maximumValue"])
|
self._max: float = 0
|
||||||
self._step: float = str_to_float(attributes["incrementValue"])
|
self._step: float = 0
|
||||||
self._default: float = str_to_float(attributes.get("defaultValue", self.min))
|
self._default: float = 0
|
||||||
|
self._value: float = 0
|
||||||
|
self._set_attributes()
|
||||||
|
|
||||||
|
def _set_attributes(self):
|
||||||
|
super()._set_attributes()
|
||||||
|
self._min: float = str_to_float(self._attributes["minimumValue"])
|
||||||
|
self._max: float = str_to_float(self._attributes["maximumValue"])
|
||||||
|
self._step: float = str_to_float(self._attributes["incrementValue"])
|
||||||
|
self._default: float = str_to_float(self._attributes.get("defaultValue", self.min))
|
||||||
self._value: float = self._default
|
self._value: float = self._default
|
||||||
|
|
||||||
def __repr__(self) -> str:
|
def __repr__(self) -> str:
|
||||||
|
Loading…
Reference in New Issue
Block a user