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]]]:
result: Dict[str, Dict[str, Union[str, float]]] = {}
for name, parameter in self._parameters.items():
result.setdefault(parameter.group, {})[name] = parameter.value
result.setdefault(parameter.group, {})[name] = parameter.intern_value
return result
@property

View file

@ -22,6 +22,10 @@ class HonParameter:
def value(self) -> str | float:
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
def values(self) -> List[str]:
return [str(self.value)]

View file

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

View file

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