2023-04-16 22:37:19 +00:00
|
|
|
from typing import List, TYPE_CHECKING, Dict
|
2023-04-15 23:43:37 +00:00
|
|
|
|
|
|
|
from pyhon.parameter.enum import HonParameterEnum
|
|
|
|
|
|
|
|
if TYPE_CHECKING:
|
|
|
|
from pyhon.commands import HonCommand
|
|
|
|
|
|
|
|
|
|
|
|
class HonParameterProgram(HonParameterEnum):
|
|
|
|
_FILTER = ["iot_recipe", "iot_guided"]
|
|
|
|
|
|
|
|
def __init__(self, key: str, command: "HonCommand") -> None:
|
|
|
|
super().__init__(key, {})
|
|
|
|
self._command = command
|
|
|
|
self._value: str = command.program
|
2023-04-16 22:37:19 +00:00
|
|
|
self._programs: Dict[str, "HonCommand"] = command.programs
|
2023-04-15 23:43:37 +00: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-16 22:37:19 +00:00
|
|
|
raise ValueError(f"Allowed values {self.values}")
|
2023-04-15 23:43:37 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def values(self) -> List[str]:
|
2023-04-16 22:37:19 +00:00
|
|
|
values = [v for v in self._programs if all(f not in v for f in self._FILTER)]
|
2023-04-15 23:43:37 +00:00
|
|
|
return sorted(values)
|