Coverage for /opt/conda/envs/apienv/lib/python3.10/site-packages/daiquiri/core/hardware/abstract/shutter.py: 89%

27 statements  

« prev     ^ index     » next       coverage.py v7.6.5, created at 2024-11-15 02:12 +0000

1#!/usr/bin/env python 

2# -*- coding: utf-8 -*- 

3from marshmallow import fields 

4 

5from daiquiri.core.hardware.abstract import HardwareObject 

6from daiquiri.core.schema.hardware import HardwareSchema 

7from daiquiri.core.schema.validators import RequireEmpty, OneOf 

8 

9import logging 

10 

11logger = logging.getLogger(__name__) 

12 

13ShutterStates = [ 

14 "OPEN", 

15 "CLOSED", 

16 "AUTO", 

17 "MOVING", 

18 "DISABLED", 

19 "STANDBY", 

20 "FAULT", 

21 "UNKNOWN", 

22] 

23 

24 

25class ShutterPropertiesSchema(HardwareSchema): 

26 state = OneOf(ShutterStates, metadata={"readOnly": True}) 

27 status = fields.Str(metadata={"readOnly": True}) 

28 valid = fields.Bool() 

29 open_text = fields.Str(metadata={"readOnly": True}) 

30 closed_text = fields.Str(metadata={"readOnly": True}) 

31 

32 

33class ShutterCallablesSchema(HardwareSchema): 

34 open = RequireEmpty() 

35 close = RequireEmpty() 

36 toggle = RequireEmpty() 

37 reset = RequireEmpty() 

38 

39 

40class Shutter(HardwareObject): 

41 _type = "shutter" 

42 _state_ok = [ShutterStates[0], ShutterStates[1]] 

43 

44 _properties = ShutterPropertiesSchema() 

45 _callables = ShutterCallablesSchema() 

46 

47 def _call_toggle(self): 

48 if self.get("state") == "OPEN": 

49 self.call("close", None) 

50 else: 

51 self.call("open", None)