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
from collections import deque
import pint
from PyQt5.QtCore import pyqtSignal, pyqtSlot
from pint import DimensionalityError
from typing import Dict, Tuple
......@@ -138,25 +139,40 @@ class AttributeDeviceDisplayWidget(DeviceWidget, AttributeDisplayWidget):
)
def on_value_set(self, value):
if isinstance(value, units.Quantity):
self._add_in_setpoint_history(value)
self.logger.info("Set {} to {}".format(self.initial_attribute, value))
value = value.to(self.attribute[UNIT])
value = value.m
elif self.attribute.numerical and self.get_unit() is not None:
try:
value = units.Quantity(value, self.get_unit())
if isinstance(value, units.Quantity) or (
self.attribute.numerical and self.get_unit() is not None
):
if not isinstance(value, units.Quantity):
try:
value = units.Quantity(value, self.get_unit())
value = value.to(self.attribute[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.logger.info("Set {} to {}".format(self.initial_attribute, value))
value = value.to(self.attribute[UNIT]).m
except AttributeError:
pass
self.logger.info(
"Set {} to {} {}".format(
self.initial_attribute, value, self.attribute[UNIT]
)
)
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:
value = self.get_widget_value()
try:
self.device.set_attribute(
self.initial_attribute + [VALUE],
self.initial_attribute + [VALUE], # e.g. ['Position', 'Value']
self.attribute_widget.attribute_type_cast(value),
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