frappy_psi.ccu4: add timing in Valve class

This commit is contained in:
2026-06-09 14:21:20 +02:00
committed by zolliker
co-authored by zolliker
parent 002d5abec9
commit 2201af7af1
+28 -1
View File
@@ -140,14 +140,18 @@ class Valve(Base, Writable):
_query_state = None
def write_target(self, target):
self._set_time = time.time()
if target:
self.command(**self._open_command)
else:
self.command(**self._close_command)
self.value = target
def read_status(self):
state = int(self.command(**self._query_state))
self.value, status = self.STATE_MAP[state]
value, status = self.STATE_MAP[state]
if time.time() > self._set_time + 2:
self.value = value
return status
@@ -800,3 +804,26 @@ class NeedleValveFlow(HasStates, Base, Drivable):
self.log.debug('before %g pulse %g, flowstep %g', sm.flow_before, sm.open_pulse, sm.last[-1] - sm.flow_before)
self.close()
return self.final_status(IDLE, '')
class MotorValve(Base, Drivable):
STATUS = {'1': (BUSY, 'opening'),
'2': (BUSY, 'closing'),
'3': (IDLE, 'opened'),
'4': (IDLE, 'closed'),
'5': (ERROR, 'no motor'),
}
value = Parameter('value', datatyp=BoolType())
target = Parameter('target', datatyp=BoolType(), readonly=False)
def write_target(self, target):
cmd = 1
if target == 0:
cmd = -1
self.communicate(f'mp{60 * cmd}')
def read_status(self):
status = self.communicate('fm')
return self.STATUS.get(status, (ERROR, f'undefined status: {status}'))