Compare commits

...

2 Commits

Author SHA1 Message Date
79c9678492 Fix float convertion 2023-04-10 18:48:46 +02:00
7c49589944 Use float for range parameter 2023-04-10 16:59:10 +02:00
2 changed files with 13 additions and 6 deletions

View File

@ -1,6 +1,13 @@
import re
def str_to_float(string):
try:
return int(string)
except ValueError:
return float(str(string.replace(",", ".")))
class HonParameter:
def __init__(self, key, attributes):
self._key = key
@ -51,10 +58,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 +85,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:

View File

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