mirror of
https://github.com/Andre0512/pyhOn.git
synced 2024-12-22 18:55:32 +00:00
Improve parameter settings
This commit is contained in:
parent
3efa2fd3f5
commit
531548f000
|
@ -26,7 +26,7 @@ class HonCommand:
|
||||||
case "fixed":
|
case "fixed":
|
||||||
result[parameter] = HonParameterFixed(parameter, attributes)
|
result[parameter] = HonParameterFixed(parameter, attributes)
|
||||||
if self._multi:
|
if self._multi:
|
||||||
result["program"] = HonParameterProgram("program", {"current": self._category, "values": list(self._multi)})
|
result["program"] = HonParameterProgram("program", self)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -42,10 +42,10 @@ class HonCommand:
|
||||||
return await self._connector.send_command(self._device, self._name, self.parameters,
|
return await self._connector.send_command(self._device, self._name, self.parameters,
|
||||||
self.ancillary_parameters)
|
self.ancillary_parameters)
|
||||||
|
|
||||||
async def get_programs(self):
|
def get_programs(self):
|
||||||
return self._multi
|
return self._multi
|
||||||
|
|
||||||
async def set_program(self, program):
|
def set_program(self, program):
|
||||||
self._device.commands[self._name] = self._multi[program]
|
self._device.commands[self._name] = self._multi[program]
|
||||||
|
|
||||||
def _get_settings_keys(self, command=None):
|
def _get_settings_keys(self, command=None):
|
||||||
|
@ -69,8 +69,3 @@ class HonCommand:
|
||||||
def settings(self):
|
def settings(self):
|
||||||
return {s: self._parameters[s] for s in self.setting_keys}
|
return {s: self._parameters[s] for s in self.setting_keys}
|
||||||
|
|
||||||
def set_setting(self, key, value):
|
|
||||||
if key == "program":
|
|
||||||
self.set_program(key)
|
|
||||||
else:
|
|
||||||
self.parameters[key].value = value
|
|
||||||
|
|
|
@ -26,7 +26,8 @@ class HonParameterFixed(HonParameter):
|
||||||
|
|
||||||
@value.setter
|
@value.setter
|
||||||
def value(self, value):
|
def value(self, value):
|
||||||
raise ValueError("fixed value")
|
if not value == self._value:
|
||||||
|
raise ValueError("Can't change fixed value")
|
||||||
|
|
||||||
|
|
||||||
class HonParameterRange(HonParameter):
|
class HonParameterRange(HonParameter):
|
||||||
|
@ -41,30 +42,43 @@ class HonParameterRange(HonParameter):
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return f"{self.key} [{self._min} - {self._max}]"
|
return f"{self.key} [{self._min} - {self._max}]"
|
||||||
|
|
||||||
|
@property
|
||||||
|
def min(self):
|
||||||
|
return self._min
|
||||||
|
|
||||||
|
@property
|
||||||
|
def max(self):
|
||||||
|
return self._max
|
||||||
|
|
||||||
|
@property
|
||||||
|
def step(self):
|
||||||
|
return self._step
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def value(self):
|
def value(self):
|
||||||
return self._value if self._value is not None else self._min
|
return self._value if self._value is not None else self._min
|
||||||
|
|
||||||
@value.setter
|
@value.setter
|
||||||
def value(self, value):
|
def value(self, 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 = self._value
|
self._value = self._value
|
||||||
raise ValueError(f"min {self._min} max {self._max} step {self._step}")
|
else:
|
||||||
|
raise ValueError(f"Allowed: min {self._min} max {self._max} step {self._step}")
|
||||||
|
|
||||||
|
|
||||||
class HonParameterEnum(HonParameter):
|
class HonParameterEnum(HonParameter):
|
||||||
def __init__(self, key, attributes):
|
def __init__(self, key, attributes):
|
||||||
super().__init__(key, attributes)
|
super().__init__(key, attributes)
|
||||||
self._value = attributes.get("defaultValue", "0")
|
|
||||||
self._default = attributes.get("defaultValue")
|
self._default = attributes.get("defaultValue")
|
||||||
|
self._value = self._default or "0"
|
||||||
self._values = attributes.get("enumValues")
|
self._values = attributes.get("enumValues")
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return f"{self.key} {self._values}"
|
return f"{self.key} {self.values}"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def values(self):
|
def values(self):
|
||||||
return self._values
|
return [str(value) for value in self._values]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def value(self):
|
def value(self):
|
||||||
|
@ -72,13 +86,26 @@ class HonParameterEnum(HonParameter):
|
||||||
|
|
||||||
@value.setter
|
@value.setter
|
||||||
def value(self, value):
|
def value(self, value):
|
||||||
if value in self._values:
|
if value in self.values:
|
||||||
self._value = self._value
|
self._value = self._value
|
||||||
raise ValueError(f"values {self._value}")
|
else:
|
||||||
|
raise ValueError(f"Allowed values {self._value}")
|
||||||
|
|
||||||
|
|
||||||
class HonParameterProgram(HonParameterEnum):
|
class HonParameterProgram(HonParameterEnum):
|
||||||
def __init__(self, key, attributes):
|
def __init__(self, key, command):
|
||||||
super().__init__(key, attributes)
|
super().__init__(key, {})
|
||||||
self._value = attributes["current"]
|
self._command = command
|
||||||
self._values = attributes["values"]
|
self._value = command._category
|
||||||
|
self._values = command._multi
|
||||||
|
|
||||||
|
@property
|
||||||
|
def value(self):
|
||||||
|
return self._value
|
||||||
|
|
||||||
|
@value.setter
|
||||||
|
def value(self, value):
|
||||||
|
if value in self.values:
|
||||||
|
self._command.set_program(value)
|
||||||
|
else:
|
||||||
|
raise ValueError(f"Allowed values {self._value}")
|
||||||
|
|
2
setup.py
2
setup.py
|
@ -7,7 +7,7 @@ with open("README.md", "r") as f:
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name="pyhOn",
|
name="pyhOn",
|
||||||
version="0.0.6",
|
version="0.0.12",
|
||||||
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,
|
||||||
|
|
Loading…
Reference in a new issue