Coverage for src/unit_cooler/controller/message.py: 25%
12 statements
« prev ^ index » next coverage.py v7.9.1, created at 2025-06-28 08:08 +0000
« prev ^ index » next coverage.py v7.9.1, created at 2025-06-28 08:08 +0000
1#!/usr/bin/env python3
2"""
3アクチュエータに送る制御メッセージの一覧を表示します。
5Usage:
6 message.py [-D]
8Options:
9 -D : デバッグモードで動作します。
10"""
12import logging
14import unit_cooler.const
16# アクチュエータへの指示に使うメッセージ
17CONTROL_MESSAGE_LIST = [
18 # 0
19 {
20 "state": unit_cooler.const.COOLING_STATE.IDLE,
21 "duty": {"enable": False, "on_sec": 0 * 60, "off_sec": 0 * 60},
22 },
23 # 1
24 {
25 "state": unit_cooler.const.COOLING_STATE.WORKING,
26 "duty": {"enable": True, "on_sec": 1 * 60, "off_sec": 14 * 60},
27 },
28 # 2
29 {
30 "state": unit_cooler.const.COOLING_STATE.WORKING,
31 "duty": {"enable": True, "on_sec": 2 * 60, "off_sec": 13 * 60},
32 },
33 # 3
34 {
35 "state": unit_cooler.const.COOLING_STATE.WORKING,
36 "duty": {"enable": True, "on_sec": 3 * 60, "off_sec": 12 * 60},
37 },
38 # 4
39 {
40 "state": unit_cooler.const.COOLING_STATE.WORKING,
41 "duty": {"enable": True, "on_sec": 4 * 60, "off_sec": 11 * 60},
42 },
43 # 5
44 {
45 "state": unit_cooler.const.COOLING_STATE.WORKING,
46 "duty": {"enable": True, "on_sec": 5 * 60, "off_sec": 10 * 60},
47 },
48 # 6
49 {
50 "state": unit_cooler.const.COOLING_STATE.WORKING,
51 "duty": {"enable": True, "on_sec": 6 * 60, "off_sec": 9 * 60},
52 },
53 # 7
54 {
55 "state": unit_cooler.const.COOLING_STATE.WORKING,
56 "duty": {"enable": True, "on_sec": 8 * 60, "off_sec": 7 * 60},
57 },
58 # 8
59 {
60 "state": unit_cooler.const.COOLING_STATE.WORKING,
61 "duty": {"enable": True, "on_sec": 10 * 60, "off_sec": 5 * 60},
62 },
63]
66def print_control_msg():
67 for control_msg in CONTROL_MESSAGE_LIST:
68 if control_msg["duty"]["enable"]:
69 on_sec = control_msg["duty"]["on_sec"]
70 off_sec = int(control_msg["duty"]["off_sec"])
71 total = on_sec + off_sec
72 on_ratio = 100.0 * on_sec / total if total != 0 else 0
74 logging.info(
75 "state: %s, on_se_sec: %s sec, off_sec: %s sec, on_ratio: %.1f%%",
76 control_msg["state"].name,
77 f"{on_sec:,}",
78 f"{off_sec:,}",
79 on_ratio,
80 )
81 else:
82 logging.info("state: %s", control_msg["state"].name)
85if __name__ == "__main__":
86 # TEST Code
87 import docopt
88 import my_lib.config
89 import my_lib.logger
90 import my_lib.pretty
92 args = docopt.docopt(__doc__)
94 debug_mode = args["-D"]
96 my_lib.logger.init("test", level=logging.DEBUG if debug_mode else logging.INFO)
98 print_control_msg()