Coverage for tests/tests_tx/test_command.py: 0%

63 statements  

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

1#!/usr/bin/env python3 

2"""Unittests for ramses_tx/command.py""" 

3 

4import logging 

5from datetime import datetime as dt, timedelta as td 

6from typing import Final 

7 

8from ramses_tx.command import Command 

9from ramses_tx.const import SYS_MODE_MAP, ZON_MODE_MAP 

10from ramses_tx.exceptions import CommandInvalid 

11 

12# 

13 

14_LOGGER = logging.getLogger(__name__) 

15 

16####################################################################################### 

17 

18# until an hour from now as "2025-08-02 14:00:00" 

19_UNTIL = (dt.now().replace(minute=0, second=0, microsecond=0) + td(hours=2)).strftime( 

20 "%Y-%m-%d %H:%M:%S" 

21) 

22 

23TEST_COMMANDS: Final = [ 

24 " W --- 18:000730 12:123456 --:------ 1F41 006 00FF00FFFFFF", # . set_dhw_mode 

25 " W --- 18:000730 12:123456 --:------ 1F41 006 000002FFFFFF", # . set_dhw_mode_perm, active-false 

26 " W --- 18:000730 12:123456 --:------ 2E04 008 00FFFFFFFFFFFF00", # set_system_mode 

27 " W --- 18:000730 12:123456 --:------ 2349 007 027FFF00FFFFFF", # set_zone_mode 

28 " W --- 18:000730 12:123456 --:------ 2349 007 0101F402FFFFFF", # set_zone_mode_perm, setpoint 

29] 

30 

31 

32async def test_set_dhw_mode_follow() -> None: 

33 """Test parameter checks from ZON_MODE_MAP key""" 

34 cmd = Command.set_dhw_mode(ctl_id="12:123456", mode=ZON_MODE_MAP["follow_schedule"]) 

35 # cls, 

36 # ctl_id: DeviceIdT | str, 

37 # mode: int | str | None = None, 

38 # active: bool | None = None, 

39 # until: dt | str | None = None, 

40 # duration: int | None = None, # never passed on by ramses_cc 

41 

42 assert str(cmd) == TEST_COMMANDS[0] 

43 

44 

45async def test_set_dhw_mode_follow_int() -> None: 

46 """Test parameter checks from int""" 

47 cmd = Command.set_dhw_mode(ctl_id="12:123456", mode=0) 

48 

49 assert str(cmd) == TEST_COMMANDS[0] 

50 

51 

52async def test_set_dhw_mode_perm_false() -> None: 

53 """Test parameter checks mode 2, active false""" # from Peter Nash 

54 cmd = Command.set_dhw_mode( 

55 ctl_id="12:123456", mode=ZON_MODE_MAP.PERMANENT, active=False 

56 ) 

57 

58 assert str(cmd) == TEST_COMMANDS[1] 

59 

60 

61async def test_set_dhw_mode_follow_extra() -> None: 

62 """Test parameter checks extra""" 

63 try: 

64 _ = Command.set_dhw_mode( 

65 ctl_id="12:123456", mode=ZON_MODE_MAP["follow_schedule"], duration=1 

66 ) 

67 except CommandInvalid: 

68 pass 

69 else: 

70 assert False 

71 

72 

73async def test_set_dhw_mode_untilduration() -> None: 

74 """Test parameter checks extra""" 

75 try: 

76 _ = Command.set_dhw_mode( 

77 ctl_id="12:123456", 

78 mode="temporary_override", 

79 active=True, 

80 duration=3600, # never passed on by ramses_cc 

81 until=_UNTIL, # Invalid args: At least one of until or duration must be None 

82 ) 

83 except CommandInvalid: 

84 pass 

85 else: 

86 assert False 

87 

88 

89async def test_set_system_mode_auto_none() -> None: 

90 """Test parameter checks from int""" 

91 cmd = Command.set_system_mode(ctl_id="12:123456", system_mode=None) 

92 

93 assert str(cmd) == TEST_COMMANDS[2] 

94 

95 

96async def test_set_system_mode_auto() -> None: 

97 """Test parameter checks""" 

98 cmd = Command.set_system_mode(ctl_id="12:123456", system_mode=SYS_MODE_MAP["auto"]) 

99 # cls, 

100 # ctl_id: DeviceIdT | str, 

101 # system_mode: int | str | None, 

102 # *, 

103 # until: dt | str | None = None, 

104 

105 assert str(cmd) == TEST_COMMANDS[2] 

106 

107 

108async def test_set_system_mode_auto_int() -> None: 

109 """Test parameter checks from int""" 

110 cmd = Command.set_system_mode(ctl_id="12:123456", system_mode=0) 

111 

112 assert str(cmd) == TEST_COMMANDS[2] 

113 

114 

115async def test_set_system_mode_heatoff() -> None: 

116 """Test parameter checks mode 1""" 

117 

118 try: 

119 _ = Command.set_system_mode( 

120 ctl_id="12:123456", 

121 system_mode=SYS_MODE_MAP.HEAT_OFF, # until should be None 

122 until="456789566", 

123 ) 

124 except CommandInvalid: 

125 pass 

126 else: 

127 assert False 

128 

129 

130async def test_set_zone_mode_noargs() -> None: 

131 """Test parameter checks extra""" 

132 

133 try: 

134 _ = Command.set_zone_mode( 

135 ctl_id="12:123456", 

136 zone_idx=4, 

137 ) 

138 except CommandInvalid: 

139 pass 

140 else: 

141 assert False 

142 

143 

144async def test_set_zone_mode_follow() -> None: 

145 """Test parameter checks""" 

146 cmd = Command.set_zone_mode( 

147 ctl_id="12:123456", mode=ZON_MODE_MAP["follow_schedule"], zone_idx=2 

148 ) 

149 # cls, 

150 # ctl_id: DeviceIdT | str, 

151 # mode: int | str | None = None, 

152 # zone_idx: _ZoneIdxT, 

153 # * 

154 # active: bool | None = None, 

155 # until: dt | str | None = None, 

156 # duration: int | None = None, 

157 

158 assert str(cmd) == TEST_COMMANDS[3] 

159 

160 

161async def test_set_zone_mode_follow_extra() -> None: 

162 """Test parameter checks extra""" 

163 

164 try: 

165 _ = Command.set_zone_mode( 

166 ctl_id="12:123456", 

167 zone_idx=1, 

168 mode=ZON_MODE_MAP["follow_schedule"], 

169 duration=1, # never passed on by ramses_cc 

170 ) 

171 except CommandInvalid: 

172 pass 

173 else: 

174 assert False 

175 

176 

177async def test_set_zone_mode_perm_setp() -> None: 

178 """Test parameter checks mode 2, active false""" # from Peter Nash 

179 cmd = Command.set_zone_mode( 

180 ctl_id="12:123456", zone_idx=1, mode=ZON_MODE_MAP.PERMANENT, setpoint=5 

181 ) 

182 

183 assert str(cmd) == TEST_COMMANDS[4]