2023-04-17 04:07:19 +05:30
|
|
|
from typing import List, TYPE_CHECKING, Dict
|
2023-04-16 05:13:37 +05:30
|
|
|
|
|
|
|
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 19:37:28 +05:30
|
|
|
def __init__(self, key: str, command: "HonCommand", group: str) -> None:
|
|
|
|
super().__init__(key, {}, group)
|
2023-04-16 05:13:37 +05:30
|
|
|
self._command = command
|
2023-05-07 04:17:08 +05:30
|
|
|
if "PROGRAM" in command.category:
|
2023-05-07 04:18:42 +05:30
|
|
|
self._value = command.category.split(".")[-1].lower()
|
2023-05-07 04:17:08 +05:30
|
|
|
else:
|
2023-05-07 04:18:42 +05:30
|
|
|
self._value = command.category
|
2023-05-06 19:37:28 +05:30
|
|
|
self._programs: Dict[str, "HonCommand"] = command.categories
|
2023-04-16 05:13:37 +05:30
|
|
|
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 23:30:13 +05:30
|
|
|
self._command.category = value
|
2023-04-16 05:13:37 +05:30
|
|
|
else:
|
2023-07-01 18:01:37 +05:30
|
|
|
raise ValueError(f"Allowed values: {self.values} But was: {value}")
|
2023-04-16 05:13:37 +05:30
|
|
|
|
|
|
|
@property
|
|
|
|
def values(self) -> List[str]:
|
2023-04-17 04:07:19 +05:30
|
|
|
values = [v for v in self._programs if all(f not in v for f in self._FILTER)]
|
2023-04-16 05:13:37 +05:30
|
|
|
return sorted(values)
|
2023-04-24 01:12:44 +05:30
|
|
|
|
2023-05-21 05:55:43 +05:30
|
|
|
@values.setter
|
2023-06-28 22:32:11 +05:30
|
|
|
def values(self, values: List[str]) -> None:
|
2023-07-12 23:06:32 +05:30
|
|
|
raise ValueError("Cant set values {values}")
|
2023-05-21 05:55:43 +05:30
|
|
|
|
2023-04-24 01:12:44 +05:30
|
|
|
@property
|
2023-05-21 05:55:43 +05:30
|
|
|
def ids(self) -> Dict[int, str]:
|
2023-07-16 08:12:29 +05:30
|
|
|
values: Dict[int, str] = {}
|
|
|
|
for name, parameter in self._programs.items():
|
|
|
|
if "iot_" in name:
|
|
|
|
continue
|
|
|
|
if parameter.parameters.get("prCode"):
|
|
|
|
continue
|
|
|
|
if (fav := parameter.parameters.get("favourite")) and fav.value == "1":
|
|
|
|
continue
|
|
|
|
values[int(parameter.parameters["prCode"].value)] = name
|
2023-04-24 01:12:44 +05:30
|
|
|
return dict(sorted(values.items()))
|
2023-05-28 22:54:02 +05:30
|
|
|
|
2023-06-28 22:32:11 +05:30
|
|
|
def set_value(self, value: str) -> None:
|
2023-05-28 22:54:02 +05:30
|
|
|
self._value = value
|