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 import re
def str_to_float(string):
return float(string.replace(",", "."))
class HonParameter: class HonParameter:
def __init__(self, key, attributes): def __init__(self, key, attributes):
self._key = key self._key = key
@ -51,10 +55,10 @@ class HonParameterFixed(HonParameter):
class HonParameterRange(HonParameter): class HonParameterRange(HonParameter):
def __init__(self, key, attributes): def __init__(self, key, attributes):
super().__init__(key, attributes) super().__init__(key, attributes)
self._min = int(attributes["minimumValue"]) self._min = str_to_float(attributes["minimumValue"])
self._max = int(attributes["maximumValue"]) self._max = str_to_float(attributes["maximumValue"])
self._step = int(attributes["incrementValue"]) self._step = str_to_float(attributes["incrementValue"])
self._default = int(attributes.get("defaultValue", self._min)) self._default = str_to_float(attributes.get("defaultValue", self._min))
self._value = self._default self._value = self._default
def __repr__(self): def __repr__(self):
@ -78,7 +82,7 @@ class HonParameterRange(HonParameter):
@value.setter @value.setter
def value(self, value): def value(self, value):
value = int(value) value = str_to_float(value)
if self._min <= value <= self._max and not value % self._step: if self._min <= value <= self._max and not value % self._step:
self._value = value self._value = value
else: else:

View file

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