From eea79e28b9f5d0b1125b6cf887e898977f828d4c Mon Sep 17 00:00:00 2001 From: Andre Basche Date: Mon, 22 May 2023 01:07:55 +0200 Subject: [PATCH] Fix for fridge program names --- pyhon/commands.py | 2 +- pyhon/parameter/base.py | 4 ++++ pyhon/parameter/enum.py | 10 +++++++--- setup.py | 2 +- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/pyhon/commands.py b/pyhon/commands.py index f839fc0..82a7c6d 100644 --- a/pyhon/commands.py +++ b/pyhon/commands.py @@ -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 diff --git a/pyhon/parameter/base.py b/pyhon/parameter/base.py index 7f505c1..f7b8086 100644 --- a/pyhon/parameter/base.py +++ b/pyhon/parameter/base.py @@ -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)] diff --git a/pyhon/parameter/enum.py b/pyhon/parameter/enum.py index 016c617..b9074c7 100644 --- a/pyhon/parameter/enum.py +++ b/pyhon/parameter/enum.py @@ -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: diff --git a/setup.py b/setup.py index 2c7caca..2bea08b 100644 --- a/setup.py +++ b/setup.py @@ -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,