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
« 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
5from daiquiri.core.hardware.abstract import HardwareObject
6from daiquiri.core.schema.hardware import HardwareSchema
7from daiquiri.core.schema.validators import RequireEmpty, OneOf
9import logging
11logger = logging.getLogger(__name__)
13ShutterStates = [
14 "OPEN",
15 "CLOSED",
16 "AUTO",
17 "MOVING",
18 "DISABLED",
19 "STANDBY",
20 "FAULT",
21 "UNKNOWN",
22]
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})
33class ShutterCallablesSchema(HardwareSchema):
34 open = RequireEmpty()
35 close = RequireEmpty()
36 toggle = RequireEmpty()
37 reset = RequireEmpty()
40class Shutter(HardwareObject):
41 _type = "shutter"
42 _state_ok = [ShutterStates[0], ShutterStates[1]]
44 _properties = ShutterPropertiesSchema()
45 _callables = ShutterCallablesSchema()
47 def _call_toggle(self):
48 if self.get("state") == "OPEN":
49 self.call("close", None)
50 else:
51 self.call("open", None)