From 6cd83eabcc14d68a0c7f49edf69e361b41ec1288 Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Wed, 15 May 2024 17:19:47 +0200 Subject: [PATCH] fix LimitsType to be actually used and validated Change-Id: Id0f67e91f4ff57d4c29c33960e736c8c3ae77209 Reviewed-on: https://forge.frm2.tum.de/review/c/secop/frappy/+/33683 Tested-by: Jenkins Automated Tests Reviewed-by: Enrico Faulhaber --- frappy/datatypes.py | 14 +++++++++----- frappy_mlz/entangle.py | 12 +++--------- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/frappy/datatypes.py b/frappy/datatypes.py index 30b7840..e8240a8 100644 --- a/frappy/datatypes.py +++ b/frappy/datatypes.py @@ -1244,16 +1244,20 @@ UInt64 = IntRange(0, (1 << 64) - 1) # Goodie: Convenience Datatypes for Programming class LimitsType(TupleOf): - def __init__(self, members): - super().__init__(members, members) + def __init__(self, member): + super().__init__(member, member) - def __call__(self, value): + def validate(self, value, previous=None): """accepts an ordered tuple of numeric member types""" - limits = TupleOf.validate(self, value) + limits = TupleOf.validate(self, value, previous) if limits[1] < limits[0]: - raise RangeError(f'Maximum Value {limits[1]} must be greater than minimum value {limits[0]}!') + raise RangeError(f'maximum value {limits[1]} must be greater than ' + f'minimum value {limits[0]}') return limits + def copy(self): + return LimitsType(TupleOf.copy(self).members[0]) + class StatusType(TupleOf): """convenience type for status diff --git a/frappy_mlz/entangle.py b/frappy_mlz/entangle.py index 7b7d599..62925af 100644 --- a/frappy_mlz/entangle.py +++ b/frappy_mlz/entangle.py @@ -620,20 +620,14 @@ class AnalogOutput(PyTangoDevice, Drivable): del __getusermin, __setusermin, __getusermax, __setusermax - def _checkLimits(self, limits): - umin, umax = limits + def write_userlimits(self, value): + umin, umax = value amin, amax = self.abslimits - if umin > umax: - raise RangeError( - f'user minimum ({umin}) above the user maximum ({umax})') if umin < amin - abs(amin * 1e-12): umin = amin if umax > amax + abs(amax * 1e-12): umax = amax - return (umin, umax) - - def write_userlimits(self, value): - return self._checkLimits(value) + return umin, umax def write_target(self, value=FloatRange()): umin, umax = self.userlimits