Fix for fridge program names

This commit is contained in:
Andre Basche 2023-05-22 01:07:55 +02:00
parent ecbf438889
commit eea79e28b9
4 changed files with 13 additions and 5 deletions

View file

@ -71,7 +71,7 @@ class HonCommand:
def parameter_groups(self) -> Dict[str, Dict[str, Union[str, float]]]: def parameter_groups(self) -> Dict[str, Dict[str, Union[str, float]]]:
result: Dict[str, Dict[str, Union[str, float]]] = {} result: Dict[str, Dict[str, Union[str, float]]] = {}
for name, parameter in self._parameters.items(): for name, parameter in self._parameters.items():
result.setdefault(parameter.group, {})[name] = parameter.value result.setdefault(parameter.group, {})[name] = parameter.intern_value
return result return result
@property @property

View file

@ -22,6 +22,10 @@ class HonParameter:
def value(self) -> str | float: def value(self) -> str | float:
return self._value if self._value is not None else "0" return self._value if self._value is not None else "0"
@property
def intern_value(self) -> str | float:
return str(self._value) if self._value is not None else ""
@property @property
def values(self) -> List[str]: def values(self) -> List[str]:
return [str(self.value)] return [str(self.value)]

View file

@ -3,13 +3,17 @@ from typing import Dict, Any, List
from pyhon.parameter.base import HonParameter from pyhon.parameter.base import HonParameter
def clean_value(value):
return str(value).strip("[]").replace("|", "_").lower()
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 = attributes.get("defaultValue")
self._value = self._default or "0" self._value = self._default or "0"
self._values: List[str] = attributes.get("enumValues", []) self._values: List[str] = attributes.get("enumValues", [])
if self._default and str(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 __repr__(self) -> str: def __repr__(self) -> str:
@ -17,7 +21,7 @@ class HonParameterEnum(HonParameter):
@property @property
def values(self) -> List[str]: def values(self) -> List[str]:
return [str(value) for value in self._values] return [clean_value(value) for value in self._values]
@values.setter @values.setter
def values(self, values) -> None: def values(self, values) -> None:
@ -25,7 +29,7 @@ class HonParameterEnum(HonParameter):
@property @property
def value(self) -> str | float: def value(self) -> str | float:
return self._value if self._value is not None else self.values[0] return clean_value(self._value) if self._value is not None else self.values[0]
@value.setter @value.setter
def value(self, value: str) -> None: def value(self, value: str) -> None:

View file

@ -7,7 +7,7 @@ with open("README.md", "r") as f:
setup( setup(
name="pyhOn", name="pyhOn",
version="0.11.0", version="0.11.1",
author="Andre Basche", author="Andre Basche",
description="Control hOn devices with python", description="Control hOn devices with python",
long_description=long_description, long_description=long_description,