conson-xp 1.18.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (176) hide show
  1. conson_xp-1.18.0.dist-info/METADATA +412 -0
  2. conson_xp-1.18.0.dist-info/RECORD +176 -0
  3. conson_xp-1.18.0.dist-info/WHEEL +4 -0
  4. conson_xp-1.18.0.dist-info/entry_points.txt +5 -0
  5. conson_xp-1.18.0.dist-info/licenses/LICENSE +29 -0
  6. xp/__init__.py +9 -0
  7. xp/cli/__init__.py +5 -0
  8. xp/cli/__main__.py +6 -0
  9. xp/cli/commands/__init__.py +153 -0
  10. xp/cli/commands/conbus/__init__.py +25 -0
  11. xp/cli/commands/conbus/conbus.py +128 -0
  12. xp/cli/commands/conbus/conbus_actiontable_commands.py +233 -0
  13. xp/cli/commands/conbus/conbus_autoreport_commands.py +108 -0
  14. xp/cli/commands/conbus/conbus_blink_commands.py +163 -0
  15. xp/cli/commands/conbus/conbus_config_commands.py +29 -0
  16. xp/cli/commands/conbus/conbus_custom_commands.py +57 -0
  17. xp/cli/commands/conbus/conbus_datapoint_commands.py +113 -0
  18. xp/cli/commands/conbus/conbus_discover_commands.py +61 -0
  19. xp/cli/commands/conbus/conbus_event_commands.py +81 -0
  20. xp/cli/commands/conbus/conbus_lightlevel_commands.py +207 -0
  21. xp/cli/commands/conbus/conbus_linknumber_commands.py +102 -0
  22. xp/cli/commands/conbus/conbus_modulenumber_commands.py +104 -0
  23. xp/cli/commands/conbus/conbus_msactiontable_commands.py +94 -0
  24. xp/cli/commands/conbus/conbus_output_commands.py +163 -0
  25. xp/cli/commands/conbus/conbus_raw_commands.py +62 -0
  26. xp/cli/commands/conbus/conbus_receive_commands.py +59 -0
  27. xp/cli/commands/conbus/conbus_scan_commands.py +58 -0
  28. xp/cli/commands/file_commands.py +186 -0
  29. xp/cli/commands/homekit/__init__.py +3 -0
  30. xp/cli/commands/homekit/homekit.py +118 -0
  31. xp/cli/commands/homekit/homekit_start_commands.py +43 -0
  32. xp/cli/commands/module_commands.py +187 -0
  33. xp/cli/commands/reverse_proxy_commands.py +178 -0
  34. xp/cli/commands/server/__init__.py +3 -0
  35. xp/cli/commands/server/server_commands.py +135 -0
  36. xp/cli/commands/telegram/__init__.py +5 -0
  37. xp/cli/commands/telegram/telegram.py +41 -0
  38. xp/cli/commands/telegram/telegram_blink_commands.py +79 -0
  39. xp/cli/commands/telegram/telegram_checksum_commands.py +112 -0
  40. xp/cli/commands/telegram/telegram_discover_commands.py +41 -0
  41. xp/cli/commands/telegram/telegram_linknumber_commands.py +86 -0
  42. xp/cli/commands/telegram/telegram_parse_commands.py +75 -0
  43. xp/cli/commands/telegram/telegram_version_commands.py +52 -0
  44. xp/cli/main.py +87 -0
  45. xp/cli/utils/__init__.py +1 -0
  46. xp/cli/utils/click_tree.py +57 -0
  47. xp/cli/utils/datapoint_type_choice.py +57 -0
  48. xp/cli/utils/decorators.py +351 -0
  49. xp/cli/utils/error_handlers.py +201 -0
  50. xp/cli/utils/formatters.py +312 -0
  51. xp/cli/utils/module_type_choice.py +56 -0
  52. xp/cli/utils/serial_number_type.py +52 -0
  53. xp/cli/utils/system_function_choice.py +57 -0
  54. xp/cli/utils/xp_module_type.py +53 -0
  55. xp/connection/__init__.py +13 -0
  56. xp/connection/exceptions.py +22 -0
  57. xp/models/__init__.py +36 -0
  58. xp/models/actiontable/__init__.py +1 -0
  59. xp/models/actiontable/actiontable.py +43 -0
  60. xp/models/actiontable/msactiontable_xp20.py +53 -0
  61. xp/models/actiontable/msactiontable_xp24.py +58 -0
  62. xp/models/actiontable/msactiontable_xp33.py +65 -0
  63. xp/models/conbus/__init__.py +1 -0
  64. xp/models/conbus/conbus.py +87 -0
  65. xp/models/conbus/conbus_autoreport.py +67 -0
  66. xp/models/conbus/conbus_blink.py +80 -0
  67. xp/models/conbus/conbus_client_config.py +55 -0
  68. xp/models/conbus/conbus_connection_status.py +40 -0
  69. xp/models/conbus/conbus_custom.py +58 -0
  70. xp/models/conbus/conbus_datapoint.py +89 -0
  71. xp/models/conbus/conbus_discover.py +64 -0
  72. xp/models/conbus/conbus_event_raw.py +47 -0
  73. xp/models/conbus/conbus_lightlevel.py +52 -0
  74. xp/models/conbus/conbus_linknumber.py +54 -0
  75. xp/models/conbus/conbus_output.py +57 -0
  76. xp/models/conbus/conbus_raw.py +45 -0
  77. xp/models/conbus/conbus_receive.py +42 -0
  78. xp/models/conbus/conbus_writeconfig.py +60 -0
  79. xp/models/homekit/__init__.py +1 -0
  80. xp/models/homekit/homekit_accessory.py +35 -0
  81. xp/models/homekit/homekit_config.py +106 -0
  82. xp/models/homekit/homekit_conson_config.py +86 -0
  83. xp/models/log_entry.py +130 -0
  84. xp/models/protocol/__init__.py +1 -0
  85. xp/models/protocol/conbus_protocol.py +312 -0
  86. xp/models/response.py +42 -0
  87. xp/models/telegram/__init__.py +1 -0
  88. xp/models/telegram/action_type.py +31 -0
  89. xp/models/telegram/datapoint_type.py +82 -0
  90. xp/models/telegram/event_telegram.py +140 -0
  91. xp/models/telegram/event_type.py +15 -0
  92. xp/models/telegram/input_action_type.py +69 -0
  93. xp/models/telegram/input_type.py +17 -0
  94. xp/models/telegram/module_type.py +188 -0
  95. xp/models/telegram/module_type_code.py +205 -0
  96. xp/models/telegram/output_telegram.py +103 -0
  97. xp/models/telegram/reply_telegram.py +297 -0
  98. xp/models/telegram/system_function.py +116 -0
  99. xp/models/telegram/system_telegram.py +94 -0
  100. xp/models/telegram/telegram.py +28 -0
  101. xp/models/telegram/telegram_type.py +19 -0
  102. xp/models/telegram/timeparam_type.py +51 -0
  103. xp/models/write_config_type.py +33 -0
  104. xp/services/__init__.py +26 -0
  105. xp/services/actiontable/__init__.py +1 -0
  106. xp/services/actiontable/actiontable_serializer.py +273 -0
  107. xp/services/actiontable/msactiontable_serializer.py +7 -0
  108. xp/services/actiontable/msactiontable_xp20_serializer.py +169 -0
  109. xp/services/actiontable/msactiontable_xp24_serializer.py +120 -0
  110. xp/services/actiontable/msactiontable_xp33_serializer.py +239 -0
  111. xp/services/conbus/__init__.py +1 -0
  112. xp/services/conbus/actiontable/__init__.py +1 -0
  113. xp/services/conbus/actiontable/actiontable_download_service.py +158 -0
  114. xp/services/conbus/actiontable/actiontable_list_service.py +91 -0
  115. xp/services/conbus/actiontable/actiontable_show_service.py +89 -0
  116. xp/services/conbus/actiontable/actiontable_upload_service.py +211 -0
  117. xp/services/conbus/actiontable/msactiontable_service.py +232 -0
  118. xp/services/conbus/conbus_blink_all_service.py +181 -0
  119. xp/services/conbus/conbus_blink_service.py +158 -0
  120. xp/services/conbus/conbus_custom_service.py +156 -0
  121. xp/services/conbus/conbus_datapoint_queryall_service.py +182 -0
  122. xp/services/conbus/conbus_datapoint_service.py +170 -0
  123. xp/services/conbus/conbus_discover_service.py +312 -0
  124. xp/services/conbus/conbus_event_raw_service.py +181 -0
  125. xp/services/conbus/conbus_output_service.py +194 -0
  126. xp/services/conbus/conbus_raw_service.py +122 -0
  127. xp/services/conbus/conbus_receive_service.py +115 -0
  128. xp/services/conbus/conbus_scan_service.py +150 -0
  129. xp/services/conbus/write_config_service.py +194 -0
  130. xp/services/homekit/__init__.py +1 -0
  131. xp/services/homekit/homekit_cache_service.py +307 -0
  132. xp/services/homekit/homekit_conbus_service.py +93 -0
  133. xp/services/homekit/homekit_config_validator.py +310 -0
  134. xp/services/homekit/homekit_conson_validator.py +121 -0
  135. xp/services/homekit/homekit_dimminglight.py +182 -0
  136. xp/services/homekit/homekit_dimminglight_service.py +148 -0
  137. xp/services/homekit/homekit_hap_service.py +342 -0
  138. xp/services/homekit/homekit_lightbulb.py +120 -0
  139. xp/services/homekit/homekit_lightbulb_service.py +86 -0
  140. xp/services/homekit/homekit_module_service.py +56 -0
  141. xp/services/homekit/homekit_outlet.py +168 -0
  142. xp/services/homekit/homekit_outlet_service.py +121 -0
  143. xp/services/homekit/homekit_service.py +359 -0
  144. xp/services/log_file_service.py +309 -0
  145. xp/services/module_type_service.py +257 -0
  146. xp/services/protocol/__init__.py +21 -0
  147. xp/services/protocol/conbus_event_protocol.py +360 -0
  148. xp/services/protocol/conbus_protocol.py +318 -0
  149. xp/services/protocol/protocol_factory.py +78 -0
  150. xp/services/protocol/telegram_protocol.py +264 -0
  151. xp/services/reverse_proxy_service.py +435 -0
  152. xp/services/server/__init__.py +1 -0
  153. xp/services/server/base_server_service.py +366 -0
  154. xp/services/server/cp20_server_service.py +65 -0
  155. xp/services/server/device_service_factory.py +94 -0
  156. xp/services/server/server_service.py +428 -0
  157. xp/services/server/xp130_server_service.py +67 -0
  158. xp/services/server/xp20_server_service.py +92 -0
  159. xp/services/server/xp230_server_service.py +58 -0
  160. xp/services/server/xp24_server_service.py +245 -0
  161. xp/services/server/xp33_server_service.py +535 -0
  162. xp/services/telegram/__init__.py +1 -0
  163. xp/services/telegram/telegram_blink_service.py +138 -0
  164. xp/services/telegram/telegram_checksum_service.py +149 -0
  165. xp/services/telegram/telegram_datapoint_service.py +82 -0
  166. xp/services/telegram/telegram_discover_service.py +277 -0
  167. xp/services/telegram/telegram_link_number_service.py +216 -0
  168. xp/services/telegram/telegram_output_service.py +322 -0
  169. xp/services/telegram/telegram_service.py +380 -0
  170. xp/services/telegram/telegram_version_service.py +288 -0
  171. xp/utils/__init__.py +12 -0
  172. xp/utils/checksum.py +61 -0
  173. xp/utils/dependencies.py +531 -0
  174. xp/utils/event_helper.py +31 -0
  175. xp/utils/serialization.py +205 -0
  176. xp/utils/time_utils.py +134 -0
@@ -0,0 +1,207 @@
1
+ """Conbus lightlevel operations CLI commands."""
2
+
3
+ import json
4
+
5
+ import click
6
+
7
+ from xp.cli.commands.conbus.conbus import conbus_lightlevel
8
+ from xp.cli.utils.decorators import (
9
+ connection_command,
10
+ )
11
+ from xp.cli.utils.serial_number_type import SERIAL
12
+ from xp.models import ConbusDatapointResponse
13
+ from xp.models.conbus.conbus_writeconfig import ConbusWriteConfigResponse
14
+ from xp.models.telegram.datapoint_type import DataPointType
15
+ from xp.services.conbus.conbus_datapoint_service import ConbusDatapointService
16
+ from xp.services.conbus.write_config_service import WriteConfigService
17
+ from xp.services.telegram.telegram_datapoint_service import TelegramDatapointService
18
+
19
+
20
+ @conbus_lightlevel.command("set")
21
+ @click.argument("serial_number", type=SERIAL)
22
+ @click.argument("output_number", type=click.IntRange(0, 8))
23
+ @click.argument("level", type=click.IntRange(0, 100))
24
+ @click.pass_context
25
+ @connection_command()
26
+ def xp_lightlevel_set(
27
+ ctx: click.Context, serial_number: str, output_number: int, level: int
28
+ ) -> None:
29
+ r"""Set light level for output_number on XP module serial_number.
30
+
31
+ Args:
32
+ ctx: Click context object.
33
+ serial_number: 10-digit module serial number.
34
+ output_number: Output number (0-8).
35
+ level: Light level (0-100).
36
+
37
+ Examples:
38
+ \b
39
+ xp conbus lightlevel set 0123450001 2 50 # Set output 2 to 50%
40
+ xp conbus lightlevel set 0011223344 0 100 # Set output 0 to 100%
41
+ """
42
+
43
+ def on_finish(response: "ConbusWriteConfigResponse") -> None:
44
+ """Handle successful completion of light level on command.
45
+
46
+ Args:
47
+ response: Light level response object.
48
+ """
49
+ click.echo(json.dumps(response.to_dict(), indent=2))
50
+
51
+ service: WriteConfigService = (
52
+ ctx.obj.get("container").get_container().resolve(WriteConfigService)
53
+ )
54
+
55
+ data_value = f"{output_number:02d}:{level:03d}"
56
+
57
+ with service:
58
+ service.write_config(
59
+ serial_number=serial_number,
60
+ datapoint_type=DataPointType.MODULE_LIGHT_LEVEL,
61
+ data_value=data_value,
62
+ finish_callback=on_finish,
63
+ timeout_seconds=0.5,
64
+ )
65
+
66
+
67
+ @conbus_lightlevel.command("off")
68
+ @click.argument("serial_number", type=SERIAL)
69
+ @click.argument("output_number", type=click.IntRange(0, 8))
70
+ @click.pass_context
71
+ @connection_command()
72
+ def xp_lightlevel_off(
73
+ ctx: click.Context, serial_number: str, output_number: int
74
+ ) -> None:
75
+ r"""Turn off light for output_number on XP module serial_number (set level to 0).
76
+
77
+ Args:
78
+ ctx: Click context object.
79
+ serial_number: 10-digit module serial number.
80
+ output_number: Output number (0-8).
81
+
82
+ Examples:
83
+ \b
84
+ xp conbus lightlevel off 0123450001 2 # Turn off output 2
85
+ xp conbus lightlevel off 0011223344 0 # Turn off output 0
86
+ """
87
+
88
+ def on_finish(response: "ConbusWriteConfigResponse") -> None:
89
+ """Handle successful completion of light level on command.
90
+
91
+ Args:
92
+ response: Light level response object.
93
+ """
94
+ click.echo(json.dumps(response.to_dict(), indent=2))
95
+
96
+ service: WriteConfigService = (
97
+ ctx.obj.get("container").get_container().resolve(WriteConfigService)
98
+ )
99
+
100
+ level = 0
101
+ data_value = f"{output_number:02d}:{level:03d}"
102
+
103
+ with service:
104
+ service.write_config(
105
+ serial_number=serial_number,
106
+ datapoint_type=DataPointType.MODULE_LIGHT_LEVEL,
107
+ data_value=data_value,
108
+ finish_callback=on_finish,
109
+ timeout_seconds=0.5,
110
+ )
111
+
112
+
113
+ @conbus_lightlevel.command("on")
114
+ @click.argument("serial_number", type=SERIAL)
115
+ @click.argument("output_number", type=click.IntRange(0, 8))
116
+ @click.pass_context
117
+ @connection_command()
118
+ def xp_lightlevel_on(
119
+ ctx: click.Context, serial_number: str, output_number: int
120
+ ) -> None:
121
+ r"""Turn on light for output_number on XP module serial_number (set level to 80%).
122
+
123
+ Args:
124
+ ctx: Click context object.
125
+ serial_number: 10-digit module serial number.
126
+ output_number: Output number (0-8).
127
+
128
+ Examples:
129
+ \b
130
+ xp conbus lightlevel on 0123450001 2 # Turn on output 2 (80%)
131
+ xp conbus lightlevel on 0011223344 0 # Turn on output 0 (80%)
132
+ """
133
+
134
+ def on_finish(response: "ConbusWriteConfigResponse") -> None:
135
+ """Handle successful completion of light level on command.
136
+
137
+ Args:
138
+ response: Light level response object.
139
+ """
140
+ click.echo(json.dumps(response.to_dict(), indent=2))
141
+
142
+ service: WriteConfigService = (
143
+ ctx.obj.get("container").get_container().resolve(WriteConfigService)
144
+ )
145
+
146
+ level = 60
147
+ data_value = f"{output_number:02d}:{level:03d}"
148
+
149
+ with service:
150
+ service.write_config(
151
+ serial_number=serial_number,
152
+ datapoint_type=DataPointType.MODULE_LIGHT_LEVEL,
153
+ data_value=data_value,
154
+ finish_callback=on_finish,
155
+ timeout_seconds=0.5,
156
+ )
157
+
158
+
159
+ @conbus_lightlevel.command("get")
160
+ @click.argument("serial_number", type=SERIAL)
161
+ @click.argument("output_number", type=click.IntRange(0, 8))
162
+ @click.pass_context
163
+ @connection_command()
164
+ def xp_lightlevel_get(
165
+ ctx: click.Context, serial_number: str, output_number: int
166
+ ) -> None:
167
+ r"""Get current light level for output_number on XP module serial_number.
168
+
169
+ Args:
170
+ ctx: Click context object.
171
+ serial_number: 10-digit module serial number.
172
+ output_number: Output number (0-8).
173
+
174
+ Examples:
175
+ \b
176
+ xp conbus lightlevel get 0123450001 2 # Get light level for output 2
177
+ xp conbus lightlevel get 0011223344 0 # Get light level for output 0
178
+ """
179
+ # Get service from container
180
+ service: ConbusDatapointService = (
181
+ ctx.obj.get("container").get_container().resolve(ConbusDatapointService)
182
+ )
183
+ telegram_service: TelegramDatapointService = (
184
+ ctx.obj.get("container").get_container().resolve(TelegramDatapointService)
185
+ )
186
+
187
+ def on_finish(service_response: "ConbusDatapointResponse") -> None:
188
+ """Handle successful completion of light level get command.
189
+
190
+ Args:
191
+ service_response: Light level response object.
192
+ """
193
+ lightlevel_level = telegram_service.get_lightlevel(
194
+ service_response.data_value, output_number
195
+ )
196
+ result = service_response.to_dict()
197
+ result["output_number"] = output_number
198
+ result["lightlevel_level"] = lightlevel_level
199
+ click.echo(json.dumps(result, indent=2))
200
+
201
+ with service:
202
+ service.query_datapoint(
203
+ serial_number=serial_number,
204
+ datapoint_type=DataPointType.MODULE_LIGHT_LEVEL,
205
+ finish_callback=on_finish,
206
+ timeout_seconds=0.5,
207
+ )
@@ -0,0 +1,102 @@
1
+ """Conbus link number CLI commands."""
2
+
3
+ import json
4
+
5
+ import click
6
+
7
+ from xp.cli.commands.conbus.conbus import conbus_linknumber
8
+ from xp.cli.utils.decorators import (
9
+ connection_command,
10
+ )
11
+ from xp.cli.utils.serial_number_type import SERIAL
12
+ from xp.models import ConbusDatapointResponse
13
+ from xp.models.conbus.conbus_writeconfig import ConbusWriteConfigResponse
14
+ from xp.models.telegram.datapoint_type import DataPointType
15
+ from xp.services.conbus.conbus_datapoint_service import ConbusDatapointService
16
+ from xp.services.conbus.write_config_service import WriteConfigService
17
+ from xp.services.telegram.telegram_datapoint_service import TelegramDatapointService
18
+
19
+
20
+ @conbus_linknumber.command("set", short_help="Set link number for a module")
21
+ @click.argument("serial_number", type=SERIAL)
22
+ @click.argument("link_number", type=click.IntRange(0, 99))
23
+ @click.pass_context
24
+ @connection_command()
25
+ def set_linknumber_command(
26
+ ctx: click.Context, serial_number: str, link_number: int
27
+ ) -> None:
28
+ r"""Set the link number for a specific module.
29
+
30
+ Args:
31
+ ctx: Click context object.
32
+ serial_number: 10-digit module serial number.
33
+ link_number: Link number to set (0-99).
34
+
35
+ Examples:
36
+ \b
37
+ xp conbus linknumber set 0123450001 25
38
+ """
39
+
40
+ def on_finish(response: "ConbusWriteConfigResponse") -> None:
41
+ """Handle successful completion of light level on command.
42
+
43
+ Args:
44
+ response: Light level response object.
45
+ """
46
+ click.echo(json.dumps(response.to_dict(), indent=2))
47
+
48
+ service: WriteConfigService = (
49
+ ctx.obj.get("container").get_container().resolve(WriteConfigService)
50
+ )
51
+
52
+ data_value = f"{link_number:02d}"
53
+ with service:
54
+ service.write_config(
55
+ serial_number=serial_number,
56
+ datapoint_type=DataPointType.LINK_NUMBER,
57
+ data_value=data_value,
58
+ finish_callback=on_finish,
59
+ timeout_seconds=0.5,
60
+ )
61
+
62
+
63
+ @conbus_linknumber.command("get", short_help="Get link number for a module")
64
+ @click.argument("serial_number", type=SERIAL)
65
+ @click.pass_context
66
+ @connection_command()
67
+ def get_linknumber_command(ctx: click.Context, serial_number: str) -> None:
68
+ r"""Get the current link number for a specific module.
69
+
70
+ Args:
71
+ ctx: Click context object.
72
+ serial_number: 10-digit module serial number.
73
+
74
+ Examples:
75
+ \b
76
+ xp conbus linknumber get 0123450001
77
+ """
78
+ service: ConbusDatapointService = (
79
+ ctx.obj.get("container").get_container().resolve(ConbusDatapointService)
80
+ )
81
+ telegram_service: TelegramDatapointService = (
82
+ ctx.obj.get("container").get_container().resolve(TelegramDatapointService)
83
+ )
84
+
85
+ def on_finish(service_response: ConbusDatapointResponse) -> None:
86
+ """Handle successful completion of link number get command.
87
+
88
+ Args:
89
+ service_response: Link number response object.
90
+ """
91
+ linknumber_value = telegram_service.get_linknumber(service_response.data_value)
92
+ result = service_response.to_dict()
93
+ result["linknumber_value"] = linknumber_value
94
+ click.echo(json.dumps(result, indent=2))
95
+
96
+ with service:
97
+ service.query_datapoint(
98
+ serial_number=serial_number,
99
+ datapoint_type=DataPointType.LINK_NUMBER,
100
+ finish_callback=on_finish,
101
+ timeout_seconds=0.5,
102
+ )
@@ -0,0 +1,104 @@
1
+ """Conbus module number CLI commands."""
2
+
3
+ import json
4
+
5
+ import click
6
+
7
+ from xp.cli.commands.conbus.conbus import conbus_modulenumber
8
+ from xp.cli.utils.decorators import (
9
+ connection_command,
10
+ )
11
+ from xp.cli.utils.serial_number_type import SERIAL
12
+ from xp.models import ConbusDatapointResponse
13
+ from xp.models.conbus.conbus_writeconfig import ConbusWriteConfigResponse
14
+ from xp.models.telegram.datapoint_type import DataPointType
15
+ from xp.services.conbus.conbus_datapoint_service import ConbusDatapointService
16
+ from xp.services.conbus.write_config_service import WriteConfigService
17
+ from xp.services.telegram.telegram_datapoint_service import TelegramDatapointService
18
+
19
+
20
+ @conbus_modulenumber.command("set", short_help="Set module number for a module")
21
+ @click.argument("serial_number", type=SERIAL)
22
+ @click.argument("module_number", type=click.IntRange(0, 99))
23
+ @click.pass_context
24
+ @connection_command()
25
+ def set_modulenumber_command(
26
+ ctx: click.Context, serial_number: str, module_number: int
27
+ ) -> None:
28
+ r"""Set the module number for a specific module.
29
+
30
+ Args:
31
+ ctx: Click context object.
32
+ serial_number: 10-digit module serial number.
33
+ module_number: Module number to set (0-99).
34
+
35
+ Examples:
36
+ \b
37
+ xp conbus modulenumber set 0123450001 25
38
+ """
39
+
40
+ def on_finish(response: "ConbusWriteConfigResponse") -> None:
41
+ """Handle successful completion of light level on command.
42
+
43
+ Args:
44
+ response: Light level response object.
45
+ """
46
+ click.echo(json.dumps(response.to_dict(), indent=2))
47
+
48
+ service: WriteConfigService = (
49
+ ctx.obj.get("container").get_container().resolve(WriteConfigService)
50
+ )
51
+
52
+ data_value = f"{module_number:02d}"
53
+ with service:
54
+ service.write_config(
55
+ serial_number=serial_number,
56
+ datapoint_type=DataPointType.MODULE_NUMBER,
57
+ data_value=data_value,
58
+ finish_callback=on_finish,
59
+ timeout_seconds=0.5,
60
+ )
61
+
62
+
63
+ @conbus_modulenumber.command("get", short_help="Get module number for a module")
64
+ @click.argument("serial_number", type=SERIAL)
65
+ @click.pass_context
66
+ @connection_command()
67
+ def get_modulenumber_command(ctx: click.Context, serial_number: str) -> None:
68
+ r"""Get the current module number for a specific module.
69
+
70
+ Args:
71
+ ctx: Click context object.
72
+ serial_number: 10-digit module serial number.
73
+
74
+ Examples:
75
+ \b
76
+ xp conbus modulenumber get 0123450001
77
+ """
78
+ service: ConbusDatapointService = (
79
+ ctx.obj.get("container").get_container().resolve(ConbusDatapointService)
80
+ )
81
+ telegram_service: TelegramDatapointService = (
82
+ ctx.obj.get("container").get_container().resolve(TelegramDatapointService)
83
+ )
84
+
85
+ def on_finish(service_response: ConbusDatapointResponse) -> None:
86
+ """Handle successful completion of module number get command.
87
+
88
+ Args:
89
+ service_response: Module number response object.
90
+ """
91
+ modulenumber_value = telegram_service.get_modulenumber(
92
+ service_response.data_value
93
+ )
94
+ result = service_response.to_dict()
95
+ result["modulenumber_value"] = modulenumber_value
96
+ click.echo(json.dumps(result, indent=2))
97
+
98
+ with service:
99
+ service.query_datapoint(
100
+ serial_number=serial_number,
101
+ datapoint_type=DataPointType.MODULE_NUMBER,
102
+ finish_callback=on_finish,
103
+ timeout_seconds=0.5,
104
+ )
@@ -0,0 +1,94 @@
1
+ """XP24 Action Table CLI commands."""
2
+
3
+ import json
4
+ from dataclasses import asdict
5
+ from typing import Union
6
+
7
+ import click
8
+ from click import Context
9
+
10
+ from xp.cli.commands.conbus.conbus import conbus_msactiontable
11
+ from xp.cli.utils.decorators import (
12
+ connection_command,
13
+ )
14
+ from xp.cli.utils.serial_number_type import SERIAL
15
+ from xp.cli.utils.xp_module_type import XP_MODULE_TYPE
16
+ from xp.models.actiontable.msactiontable_xp20 import Xp20MsActionTable
17
+ from xp.models.actiontable.msactiontable_xp24 import Xp24MsActionTable
18
+ from xp.models.actiontable.msactiontable_xp33 import Xp33MsActionTable
19
+ from xp.services.conbus.actiontable.msactiontable_service import (
20
+ MsActionTableService,
21
+ )
22
+
23
+
24
+ @conbus_msactiontable.command("download", short_help="Download MSActionTable")
25
+ @click.argument("serial_number", type=SERIAL)
26
+ @click.argument("xpmoduletype", type=XP_MODULE_TYPE)
27
+ @click.pass_context
28
+ @connection_command()
29
+ def conbus_download_msactiontable(
30
+ ctx: Context, serial_number: str, xpmoduletype: str
31
+ ) -> None:
32
+ """Download MS action table from XP24 module.
33
+
34
+ Args:
35
+ ctx: Click context object.
36
+ serial_number: 10-digit module serial number.
37
+ xpmoduletype: XP module type.
38
+ """
39
+ service: MsActionTableService = (
40
+ ctx.obj.get("container").get_container().resolve(MsActionTableService)
41
+ )
42
+
43
+ def progress_callback(progress: str) -> None:
44
+ """Handle progress updates during MS action table download.
45
+
46
+ Args:
47
+ progress: Progress message string.
48
+ """
49
+ click.echo(progress, nl=False)
50
+
51
+ def on_finish(
52
+ action_table: Union[
53
+ Xp20MsActionTable, Xp24MsActionTable, Xp33MsActionTable, None
54
+ ],
55
+ ) -> None:
56
+ """Handle successful completion of MS action table download.
57
+
58
+ Args:
59
+ action_table: Downloaded MS action table object or None if failed.
60
+
61
+ Raises:
62
+ Abort: If action table download failed.
63
+ """
64
+ if action_table is None:
65
+ click.echo("Error: Failed to download MS action table")
66
+ raise click.Abort()
67
+
68
+ output = {
69
+ "serial_number": serial_number,
70
+ "xpmoduletype": xpmoduletype,
71
+ "action_table": asdict(action_table),
72
+ }
73
+ click.echo(json.dumps(output, indent=2, default=str))
74
+
75
+ def error_callback(error: str) -> None:
76
+ """Handle errors during MS action table download.
77
+
78
+ Args:
79
+ error: Error message string.
80
+
81
+ Raises:
82
+ Abort: Always raised to abort the command on error.
83
+ """
84
+ click.echo(f"Error: {error}")
85
+ raise click.Abort()
86
+
87
+ with service:
88
+ service.start(
89
+ serial_number=serial_number,
90
+ xpmoduletype=xpmoduletype,
91
+ progress_callback=progress_callback,
92
+ finish_callback=on_finish,
93
+ error_callback=error_callback,
94
+ )
@@ -0,0 +1,163 @@
1
+ """Conbus client operations CLI commands."""
2
+
3
+ import json
4
+
5
+ import click
6
+
7
+ from xp.cli.commands.conbus.conbus import conbus_output
8
+ from xp.cli.utils.decorators import (
9
+ connection_command,
10
+ )
11
+ from xp.cli.utils.serial_number_type import SERIAL
12
+ from xp.models import ConbusDatapointResponse
13
+ from xp.models.conbus.conbus_output import ConbusOutputResponse
14
+ from xp.models.telegram.action_type import ActionType
15
+ from xp.models.telegram.datapoint_type import DataPointType
16
+ from xp.services.conbus.conbus_datapoint_service import ConbusDatapointService
17
+ from xp.services.conbus.conbus_output_service import ConbusOutputService
18
+
19
+
20
+ @conbus_output.command("on")
21
+ @click.argument("serial_number", type=SERIAL)
22
+ @click.argument("output_number", type=int)
23
+ @click.pass_context
24
+ @connection_command()
25
+ def xp_output_on(ctx: click.Context, serial_number: str, output_number: int) -> None:
26
+ r"""Send ON command for output_number XP module serial_number.
27
+
28
+ Args:
29
+ ctx: Click context object.
30
+ serial_number: 10-digit module serial number.
31
+ output_number: Output number.
32
+
33
+ Examples:
34
+ \b
35
+ xp conbus output on 0011223344 0 # Turn on output 0
36
+ """
37
+ service: ConbusOutputService = (
38
+ ctx.obj.get("container").get_container().resolve(ConbusOutputService)
39
+ )
40
+
41
+ def on_finish(response: ConbusOutputResponse) -> None:
42
+ """Handle successful completion of output on command.
43
+
44
+ Args:
45
+ response: Output response object.
46
+ """
47
+ click.echo(json.dumps(response.to_dict(), indent=2))
48
+
49
+ with service:
50
+ service.send_action(
51
+ serial_number=serial_number,
52
+ output_number=output_number,
53
+ action_type=ActionType.ON_RELEASE,
54
+ finish_callback=on_finish,
55
+ )
56
+
57
+
58
+ @conbus_output.command("off")
59
+ @click.argument("serial_number", type=SERIAL)
60
+ @click.argument("output_number", type=int)
61
+ @click.pass_context
62
+ @connection_command()
63
+ def xp_output_off(ctx: click.Context, serial_number: str, output_number: int) -> None:
64
+ r"""Send OFF command for output_number XP module serial_number.
65
+
66
+ Args:
67
+ ctx: Click context object.
68
+ serial_number: 10-digit module serial number.
69
+ output_number: Output number.
70
+
71
+ Examples:
72
+ \b
73
+ xp conbus output off 0011223344 1 # Turn off output 1
74
+ """
75
+ service: ConbusOutputService = (
76
+ ctx.obj.get("container").get_container().resolve(ConbusOutputService)
77
+ )
78
+
79
+ def on_finish(response: ConbusOutputResponse) -> None:
80
+ """Handle successful completion of output off command.
81
+
82
+ Args:
83
+ response: Output response object.
84
+ """
85
+ click.echo(json.dumps(response.to_dict(), indent=2))
86
+
87
+ with service:
88
+ service.send_action(
89
+ serial_number=serial_number,
90
+ output_number=output_number,
91
+ action_type=ActionType.OFF_PRESS,
92
+ finish_callback=on_finish,
93
+ )
94
+
95
+
96
+ @conbus_output.command("status")
97
+ @click.argument("serial_number", type=SERIAL)
98
+ @click.pass_context
99
+ @connection_command()
100
+ def xp_output_status(ctx: click.Context, serial_number: str) -> None:
101
+ r"""Query output state command to XP module serial_number.
102
+
103
+ Args:
104
+ ctx: Click context object.
105
+ serial_number: 10-digit module serial number.
106
+
107
+ Examples:
108
+ \b
109
+ xp conbus output status 0011223344 # Query output status
110
+ """
111
+ service: ConbusDatapointService = (
112
+ ctx.obj.get("container").get_container().resolve(ConbusDatapointService)
113
+ )
114
+
115
+ def on_finish(response: ConbusDatapointResponse) -> None:
116
+ """Handle successful completion of output status query.
117
+
118
+ Args:
119
+ response: Datapoint response object.
120
+ """
121
+ click.echo(json.dumps(response.to_dict(), indent=2))
122
+
123
+ with service:
124
+ service.query_datapoint(
125
+ serial_number=serial_number,
126
+ datapoint_type=DataPointType.MODULE_OUTPUT_STATE,
127
+ finish_callback=on_finish,
128
+ )
129
+
130
+
131
+ @conbus_output.command("state")
132
+ @click.argument("serial_number", type=SERIAL)
133
+ @click.pass_context
134
+ @connection_command()
135
+ def xp_module_state(ctx: click.Context, serial_number: str) -> None:
136
+ r"""Query module state of the XP module serial_number.
137
+
138
+ Args:
139
+ ctx: Click context object.
140
+ serial_number: 10-digit module serial number.
141
+
142
+ Examples:
143
+ \b
144
+ xp conbus output state 0011223344 # Query module state
145
+ """
146
+ service: ConbusDatapointService = (
147
+ ctx.obj.get("container").get_container().resolve(ConbusDatapointService)
148
+ )
149
+
150
+ def on_finish(response: ConbusDatapointResponse) -> None:
151
+ """Handle successful completion of module state query.
152
+
153
+ Args:
154
+ response: Datapoint response object.
155
+ """
156
+ click.echo(json.dumps(response.to_dict(), indent=2))
157
+
158
+ with service:
159
+ service.query_datapoint(
160
+ serial_number=serial_number,
161
+ datapoint_type=DataPointType.MODULE_STATE,
162
+ finish_callback=on_finish,
163
+ )