Use float for range parameter

This commit is contained in:
Andre Basche 2023-04-10 16:59:10 +02:00
parent f421cf1ce6
commit 7c49589944
2 changed files with 10 additions and 6 deletions

View file

@ -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:

View file

@ -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,