Coverage for tests/tests/test_apis_common.py: 0%

57 statements  

« prev     ^ index     » next       coverage.py v7.11.3, created at 2026-01-05 21:46 +0100

1#!/usr/bin/env python3 

2"""RAMSES RF - Test the Command.put_*, Command.set_* APIs.""" 

3 

4from ramses_tx import exceptions as exc 

5from ramses_tx.command import CODE_API_MAP, Command 

6 

7EXCLUDED_APIS = ("from_attrs", "_from_attrs", "from_cli", "get_fan_param") 

8EXCLUDED_APIS += () # APIs not added to the CODE_API_MAP, should be an empty tuple 

9 

10 

11def test_command_apis_via_map() -> None: 

12 """Check that all Command constructors are in CODE_API_MAP.""" 

13 

14 cls_apis = { 

15 v.__name__ 

16 for k, v in Command.__dict__.items() 

17 if isinstance(v, classmethod) and k[:1] != "_" and k not in EXCLUDED_APIS 

18 } 

19 

20 map_apis = {v.__name__ for v in CODE_API_MAP.values()} 

21 

22 assert not map_apis.symmetric_difference(cls_apis) 

23 

24 

25def test_1fc9_constructors_fail() -> None: 

26 """Check the 1FC9 Command constructors behave as expected when given bad params.""" 

27 

28 try: 

29 _ = Command.put_bind(" I", "29:156898", None) # should have codes, or dst_id 

30 except exc.CommandInvalid: 

31 pass 

32 else: 

33 assert False 

34 

35 

36def test_1fc9_constructors_good() -> None: 

37 """Check the 1FC9 Command constructors behave as expected when give good params.""" 

38 

39 # 

40 # SWI switch (22F1/3) binding to a FAN (31D9/A)? 

41 frame = " I --- 37:155617 --:------ 37:155617 1FC9 024 0022F1965FE10022F3965FE16710E0965FE1001FC9965FE1" 

42 cmd = Command.put_bind(" I", "37:155617", ("22F1", "22F3"), oem_code="67") 

43 assert cmd._frame == frame 

44 

45 frame = " W --- 32:132125 29:156898 --:------ 1FC9 012 0031D982041D0031DA82041D" 

46 cmd = Command.put_bind(" W", "32:132125", ("31D9", "31DA"), dst_id="29:156898") 

47 assert cmd._frame == frame 

48 

49 frame = " I --- 29:156898 32:132125 --:------ 1FC9 001 00" 

50 cmd = Command.put_bind(" I", "29:156898", None, dst_id="32:132125") 

51 assert cmd._frame == frame 

52 

53 # 

54 # CO2 remote (1298/31E0, 2E10) binding to a FAN (31D9/A) 

55 frame = " I --- 37:154011 --:------ 37:154011 1FC9 030 0031E096599B00129896599B002E1096599B0110E096599B001FC996599B" 

56 cmd = Command.put_bind(" I", "37:154011", ("31E0", "1298", "2E10"), oem_code="01") 

57 assert cmd._frame == frame 

58 

59 frame = " W --- 18:126620 37:154011 --:------ 1FC9 012 0031D949EE9C0031DA49EE9C" 

60 cmd = Command.put_bind(" W", "18:126620", ("31D9", "31DA"), dst_id="37:154011") 

61 assert cmd._frame == frame 

62 

63 frame = " I --- 37:154011 18:126620 --:------ 1FC9 001 00" 

64 cmd = Command.put_bind(" I", "37:154011", None, dst_id="18:126620") 

65 assert cmd._frame == frame 

66 

67 # 

68 # STA binding to a CTL as a thermostat (2309, 30C9, 0008, 1FC9): zone idx 08 

69 frame = " I --- 12:010740 --:------ 12:010740 1FC9 024 0023093029F40030C93029F40000083029F4001FC93029F4" 

70 cmd = Command.put_bind(" I", "12:010740", ("2309", "30C9", "0008")) 

71 assert cmd._frame == frame 

72 

73 frame = " W --- 01:145038 12:010740 --:------ 1FC9 006 08230906368E" 

74 cmd = Command.put_bind(" W", "01:145038", ("2309",), dst_id="12:010740", idx="08") 

75 assert cmd._frame == frame 

76 

77 frame = " I --- 12:010740 01:145038 --:------ 1FC9 006 0023093029F4" 

78 cmd = Command.put_bind(" I", "12:010740", ("2309",), dst_id="01:145038") 

79 assert cmd._frame == frame 

80 

81 # 

82 # DHW sensor binding to a CTL (1260, 1FC9): dhw_idx 00 

83 frame = " I --- 07:045960 --:------ 07:045960 1FC9 012 0012601CB388001FC91CB388" 

84 cmd = Command.put_bind(" I", "07:045960", "1260") 

85 assert cmd._frame == frame # using str for codes 

86 

87 frame = " W --- 01:145038 07:045960 --:------ 1FC9 006 0010A006368E" 

88 cmd = Command.put_bind(" W", "01:145038", "10A0", dst_id="07:045960") 

89 assert cmd._frame == frame # using str for codes 

90 

91 frame = " I --- 07:045960 01:145038 --:------ 1FC9 006 0012601CB388" 

92 cmd = Command.put_bind(" I", "07:045960", "1260", dst_id="01:145038") 

93 assert cmd._frame == frame # using str for codes 

94 

95 # NOTE: the APIs are not (yet) intended for these edge-case packets 

96 # TRV binding to a CTL (2309, 30C9, 1FC9): zone idx 07 - NOTE: counter-offer pkt! 

97 # # frame = " I --- 04:189076 63:262142 --:------ 1FC9 006 0030C912E294" 

98 # # cmd = Command.put_bind(" I", "04:189076", ("30C9",), dst_id="63:262142") 

99 # # assert cmd._frame == frame # NOTE: NUL-ADDR, and there is no 1FC9 in the payload! 

100 

101 # # frame = " I --- 01:145038 --:------ 01:145038 1FC9 018 07230906368E0730C906368E071FC906368E" 

102 # # cmd = Command.put_bind(" I", "01:145038", ("2309", "30C9"), idx="07") 

103 # # assert cmd._frame == frame # NOTE: this is the counter-offer 

104 

105 frame = " W --- 04:189076 01:145038 --:------ 1FC9 006 0030C912E294" 

106 cmd = Command.put_bind(" W", "04:189076", ("30C9",), dst_id="01:145038") 

107 assert cmd._frame == frame 

108 

109 frame = " I --- 01:145038 04:189076 --:------ 1FC9 006 00FFFF06368E" 

110 cmd = Command.put_bind(" I", "01:145038", "FFFF", dst_id="04:189076") 

111 assert cmd._frame == frame # using SENTINEL str for codes