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