2023-04-17 00:37:19 +02:00
|
|
|
from typing import List, TYPE_CHECKING, Dict
|
2023-04-16 01:43:37 +02:00
|
|
|
|
|
|
|
from pyhon.parameter.enum import HonParameterEnum
|
|
|
|
|
|
|
|
if TYPE_CHECKING:
|
|
|
|
from pyhon.commands import HonCommand
|
|
|
|
|
|
|
|
|
|
|
|
class HonParameterProgram(HonParameterEnum):
|
|
|
|
_FILTER = ["iot_recipe", "iot_guided"]
|
|
|
|
|
2023-05-06 16:07:28 +02:00
|
|
|
def __init__(self, key: str, command: "HonCommand", group: str) -> None:
|
|
|
|
super().__init__(key, {}, group)
|
2023-04-16 01:43:37 +02:00
|
|
|
self._command = command
|
2023-05-06 16:07:28 +02:00
|
|
|
self._value: str = command.category
|
|
|
|
self._programs: Dict[str, "HonCommand"] = command.categories
|
2023-04-16 01:43:37 +02:00
|
|
|
self._typology: str = "enum"
|
|
|
|
|
|
|
|
@property
|
|
|
|
def value(self) -> str | float:
|
|
|
|
return self._value
|
|
|
|
|
|
|
|
@value.setter
|
|
|
|
def value(self, value: str) -> None:
|
|
|
|
if value in self.values:
|
|
|
|
self._command.program = value
|
|
|
|
else:
|
2023-04-17 00:37:19 +02:00
|
|
|
raise ValueError(f"Allowed values {self.values}")
|
2023-04-16 01:43:37 +02:00
|
|
|
|
|
|
|
@property
|
|
|
|
def values(self) -> List[str]:
|
2023-04-17 00:37:19 +02:00
|
|
|
values = [v for v in self._programs if all(f not in v for f in self._FILTER)]
|
2023-04-16 01:43:37 +02:00
|
|
|
return sorted(values)
|
2023-04-23 21:42:44 +02:00
|
|
|
|
|
|
|
@property
|
|
|
|
def ids(self):
|
|
|
|
values = {
|
|
|
|
int(p.parameters["prCode"].value): n
|
|
|
|
for i, (n, p) in enumerate(self._programs.items())
|
|
|
|
if "iot_" not in n and p.parameters.get("prCode")
|
|
|
|
}
|
|
|
|
return dict(sorted(values.items()))
|