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"]
|
|
|
|
|
2023-05-06 14:07:28 +00:00
|
|
|
def __init__(self, key: str, command: "HonCommand", group: str) -> None:
|
|
|
|
super().__init__(key, {}, group)
|
2023-04-15 23:43:37 +00:00
|
|
|
self._command = command
|
2023-05-06 22:47:08 +00:00
|
|
|
if "PROGRAM" in command.category:
|
2023-05-06 22:48:42 +00:00
|
|
|
self._value = command.category.split(".")[-1].lower()
|
2023-05-06 22:47:08 +00:00
|
|
|
else:
|
2023-05-06 22:48:42 +00:00
|
|
|
self._value = command.category
|
2023-05-06 14:07:28 +00:00
|
|
|
self._programs: Dict[str, "HonCommand"] = command.categories
|
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:
|
2023-05-06 18:00:13 +00:00
|
|
|
self._command.category = value
|
2023-04-15 23:43:37 +00:00
|
|
|
else:
|
2023-07-01 12:31:37 +00:00
|
|
|
raise ValueError(f"Allowed values: {self.values} But was: {value}")
|
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)
|
2023-04-23 19:42:44 +00:00
|
|
|
|
2023-05-21 00:25:43 +00:00
|
|
|
@values.setter
|
2023-06-28 17:02:11 +00:00
|
|
|
def values(self, values: List[str]) -> None:
|
2023-05-21 00:25:43 +00:00
|
|
|
return
|
|
|
|
|
2023-04-23 19:42:44 +00:00
|
|
|
@property
|
2023-05-21 00:25:43 +00:00
|
|
|
def ids(self) -> Dict[int, str]:
|
2023-04-23 19:42:44 +00:00
|
|
|
values = {
|
|
|
|
int(p.parameters["prCode"].value): n
|
|
|
|
for i, (n, p) in enumerate(self._programs.items())
|
2023-05-29 16:58:50 +00:00
|
|
|
if "iot_" not in n
|
|
|
|
and p.parameters.get("prCode")
|
|
|
|
and not ((fav := p.parameters.get("favourite")) and fav.value == "1")
|
2023-04-23 19:42:44 +00:00
|
|
|
}
|
|
|
|
return dict(sorted(values.items()))
|
2023-05-28 17:24:02 +00:00
|
|
|
|
2023-06-28 17:02:11 +00:00
|
|
|
def set_value(self, value: str) -> None:
|
2023-05-28 17:24:02 +00:00
|
|
|
self._value = value
|