simplify status type declaration
- StatusType: simpler inheritance (inherit from module instead of Enum) - StatusType: more robust for standard codes, give names only - <Module>.Status is automatically extended - Enum: accept duplicates with same name and value Change-Id: Iad1dacf14c31fe6f4ae48e7560b29e49838e4f23 Reviewed-on: https://forge.frm2.tum.de/review/c/secop/frappy/+/30716 Reviewed-by: Enrico Faulhaber <enrico.faulhaber@frm2.tum.de> Tested-by: Jenkins Automated Tests <pedersen+jenkins@frm2.tum.de> Reviewed-by: Markus Zolliker <markus.zolliker@psi.ch>
This commit is contained in:
@@ -1242,7 +1242,12 @@ class LimitsType(TupleOf):
|
||||
|
||||
|
||||
class StatusType(TupleOf):
|
||||
# shorten initialisation and allow access to status enumMembers from status values
|
||||
"""convenience type for status
|
||||
|
||||
:param first: an Enum or Module to inherit from, or the first member name
|
||||
:param args: member names (codes will be taken from class attributes below)
|
||||
:param kwds: additional members not matching the standard
|
||||
"""
|
||||
DISABLED = 0
|
||||
IDLE = 100
|
||||
STANDBY = 130
|
||||
@@ -1250,7 +1255,7 @@ class StatusType(TupleOf):
|
||||
WARN = 200
|
||||
WARN_STANDBY = 230
|
||||
WARN_PREPARED = 250
|
||||
UNSTABLE = 270 # no SECoP standard (yet)
|
||||
UNSTABLE = 270 # not in SECoP standard (yet)
|
||||
BUSY = 300
|
||||
DISABLING = 310
|
||||
INITIALIZING = 320
|
||||
@@ -1262,13 +1267,30 @@ class StatusType(TupleOf):
|
||||
ERROR = 400
|
||||
ERROR_STANDBY = 430
|
||||
ERROR_PREPARED = 450
|
||||
UNKNOWN = 401 # not in SECoP standard (yet)
|
||||
|
||||
def __init__(self, enum):
|
||||
super().__init__(EnumType(enum), StringType())
|
||||
self._enum = enum
|
||||
def __init__(self, first, *args, **kwds):
|
||||
if first:
|
||||
if isinstance(first, str):
|
||||
args = (first,) + args
|
||||
first = 'Status' # enum name
|
||||
else:
|
||||
if not isinstance(first, Enum):
|
||||
# assume first is a Module with a status parameter
|
||||
try:
|
||||
first = first.status.datatype.members[0]._enum
|
||||
except AttributeError:
|
||||
raise ProgrammingError('first argument must be either str, Enum or a module') from None
|
||||
else:
|
||||
first = 'Status' # enum name
|
||||
bad = {n for n in args if n not in StatusType.__dict__ or n.startswith('_')} # avoid built-in attributes
|
||||
if bad:
|
||||
raise ProgrammingError('positional arguments %r must be standard status code names' % bad)
|
||||
self.enum = Enum(Enum(first, **{n: StatusType.__dict__[n] for n in args}), **kwds)
|
||||
super().__init__(EnumType(self.enum), StringType())
|
||||
|
||||
def __getattr__(self, key):
|
||||
return getattr(self._enum, key)
|
||||
return self.enum[key]
|
||||
|
||||
|
||||
def floatargs(kwds):
|
||||
|
||||
Reference in New Issue
Block a user