Commit 46260b05 authored by Philipp Middendorf's avatar Philipp Middendorf
Browse files

Merge branch 'bug_limits' into 'master'

attributeDeviceDisplayWidget.py: fix bug with soft limits

See merge request !35
parents c20d2b1e c5eb0044
import time import time
from collections import deque from collections import deque
import pint
from PyQt5.QtCore import pyqtSignal, pyqtSlot from PyQt5.QtCore import pyqtSignal, pyqtSlot
from pint import DimensionalityError from pint import DimensionalityError
from typing import Dict, Tuple from typing import Dict, Tuple
...@@ -138,25 +139,40 @@ class AttributeDeviceDisplayWidget(DeviceWidget, AttributeDisplayWidget): ...@@ -138,25 +139,40 @@ class AttributeDeviceDisplayWidget(DeviceWidget, AttributeDisplayWidget):
) )
def on_value_set(self, value): def on_value_set(self, value):
if isinstance(value, units.Quantity): if isinstance(value, units.Quantity) or (
self._add_in_setpoint_history(value) self.attribute.numerical and self.get_unit() is not None
self.logger.info("Set {} to {}".format(self.initial_attribute, value)) ):
value = value.to(self.attribute[UNIT]) if not isinstance(value, units.Quantity):
value = value.m try:
elif self.attribute.numerical and self.get_unit() is not None: value = units.Quantity(value, self.get_unit())
try: value = value.to(self.attribute[UNIT])
value = units.Quantity(value, self.get_unit()) except (
AttributeError,
pint.UndefinedUnitError,
pint.DefinitionSyntaxError,
):
value = units.Quantity(value)
else:
value = value.to(self.attribute[UNIT])
if self.attribute.within_limits(value):
value = value.m
self._add_in_setpoint_history(value) self._add_in_setpoint_history(value)
self.logger.info("Set {} to {}".format(self.initial_attribute, value)) self.logger.info(
value = value.to(self.attribute[UNIT]).m "Set {} to {} {}".format(
except AttributeError: self.initial_attribute, value, self.attribute[UNIT]
pass )
)
else:
self.logger.info(f"Can't set value {value}, out of limits")
value = self.attribute.value().m # set value back to what it was before
elif self.attribute[TYPE] == TYPE_LIST: elif self.attribute[TYPE] == TYPE_LIST:
value = self.get_widget_value() value = self.get_widget_value()
try: try:
self.device.set_attribute( self.device.set_attribute(
self.initial_attribute + [VALUE], self.initial_attribute + [VALUE], # e.g. ['Position', 'Value']
self.attribute_widget.attribute_type_cast(value), self.attribute_widget.attribute_type_cast(value),
callback=self.sigErrorCheck.emit, callback=self.sigErrorCheck.emit,
) )
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment