frappy_psi/magfield: fix status of SimpleMagfield

+ improve error message when converting to enum datatype
This commit is contained in:
2026-05-20 13:59:29 +02:00
parent 0decbf52d2
commit e5a78b84a7
2 changed files with 9 additions and 4 deletions
+2 -2
View File
@@ -31,7 +31,7 @@ from base64 import b64decode, b64encode
from frappy.errors import ConfigError, ProgrammingError, \
RangeError, WrongTypeError
from frappy.lib import clamp, generalConfig
from frappy.lib.enum import Enum
from frappy.lib.enum import Enum, EnumMember
from frappy.properties import HasProperties, Property
generalConfig.set_default('lazy_number_validation', False)
@@ -524,7 +524,7 @@ class EnumType(DataType):
try:
return self._enum[value]
except (KeyError, TypeError): # TypeError will be raised when value is not hashable
if isinstance(value, (int, str)):
if isinstance(value, (int, str, EnumMember)):
raise RangeError(f'{shortrepr(value)} is not a member of enum {self._enum!r}') from None
raise WrongTypeError(f'{shortrepr(value)} must be either int or str for an enum value') from None
+7 -2
View File
@@ -33,11 +33,15 @@ Mode = Enum(
DRIVEN=50,
)
Status = Enum(
SimpleStatus = Enum(
Drivable.Status,
RAMPING=370,
)
Status = Enum(
SimpleStatus,
PREPARED=150,
PREPARING=340,
RAMPING=370,
STABILIZING=380,
FINALIZING=390,
)
@@ -48,6 +52,7 @@ ON = 1
class SimpleMagfield(HasStates, Drivable):
value = Parameter('magnetic field', datatype=FloatRange(unit='T'))
status = Parameter(datatype=StatusType(SimpleStatus))
target_min = Limit()
target_max = Limit()
ramp = Parameter(