Skip to content

Commit

Permalink
Fix for fridge program names
Browse files Browse the repository at this point in the history
  • Loading branch information
Andre0512 committed May 21, 2023
1 parent ecbf438 commit eea79e2
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pyhon/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def settings(self) -> Dict[str, HonParameter]:
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
Expand Down
4 changes: 4 additions & 0 deletions pyhon/parameter/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ def key(self) -> str:
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)]
Expand Down
10 changes: 7 additions & 3 deletions pyhon/parameter/enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,33 @@
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:
return f"{self.__class__} (<{self.key}> {self.values})"

@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:
self._values = values

@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:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

setup(
name="pyhOn",
version="0.11.0",
version="0.11.1",
author="Andre Basche",
description="Control hOn devices with python",
long_description=long_description,
Expand Down

0 comments on commit eea79e2

Please sign in to comment.