From 7c4958994487f55aa01f2f13c07cf67fa3fbf260 Mon Sep 17 00:00:00 2001 From: Andre Basche Date: Mon, 10 Apr 2023 16:59:10 +0200 Subject: [PATCH] Use float for range parameter --- pyhon/parameter.py | 14 +++++++++----- setup.py | 2 +- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/pyhon/parameter.py b/pyhon/parameter.py index bbb269b..0e31cd3 100644 --- a/pyhon/parameter.py +++ b/pyhon/parameter.py @@ -1,6 +1,10 @@ import re +def str_to_float(string): + return float(string.replace(",", ".")) + + class HonParameter: def __init__(self, key, attributes): self._key = key @@ -51,10 +55,10 @@ class HonParameterFixed(HonParameter): class HonParameterRange(HonParameter): def __init__(self, key, attributes): super().__init__(key, attributes) - self._min = int(attributes["minimumValue"]) - self._max = int(attributes["maximumValue"]) - self._step = int(attributes["incrementValue"]) - self._default = int(attributes.get("defaultValue", self._min)) + self._min = str_to_float(attributes["minimumValue"]) + self._max = str_to_float(attributes["maximumValue"]) + self._step = str_to_float(attributes["incrementValue"]) + self._default = str_to_float(attributes.get("defaultValue", self._min)) self._value = self._default def __repr__(self): @@ -78,7 +82,7 @@ class HonParameterRange(HonParameter): @value.setter def value(self, value): - value = int(value) + value = str_to_float(value) if self._min <= value <= self._max and not value % self._step: self._value = value else: diff --git a/setup.py b/setup.py index 83d4176..0151d1a 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ with open("README.md", "r") as f: setup( name="pyhOn", - version="0.6.0", + version="0.6.1", author="Andre Basche", description="Control hOn devices with python", long_description=long_description,