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,153 @@
1
+ """Command modules for XP CLI."""
2
+
3
+ # Main command groups
4
+
5
+ # Import conbus command groups (but not 'conbus' itself to avoid module shadowing in Python 3.10)
6
+ from xp.cli.commands.conbus.conbus import (
7
+ conbus_actiontable,
8
+ conbus_autoreport,
9
+ conbus_blink,
10
+ conbus_datapoint,
11
+ conbus_lightlevel,
12
+ conbus_linknumber,
13
+ conbus_modulenumber,
14
+ conbus_msactiontable,
15
+ conbus_output,
16
+ )
17
+ from xp.cli.commands.conbus.conbus_actiontable_commands import (
18
+ conbus_download_actiontable,
19
+ )
20
+
21
+ # Individual command functions that attach to groups
22
+ from xp.cli.commands.conbus.conbus_autoreport_commands import (
23
+ get_autoreport_command,
24
+ set_autoreport_command,
25
+ )
26
+ from xp.cli.commands.conbus.conbus_blink_commands import (
27
+ blink_all_off,
28
+ blink_all_on,
29
+ conbus_blink_all,
30
+ send_blink_off_telegram,
31
+ send_blink_on_telegram,
32
+ )
33
+ from xp.cli.commands.conbus.conbus_config_commands import show_config
34
+ from xp.cli.commands.conbus.conbus_custom_commands import send_custom_telegram
35
+ from xp.cli.commands.conbus.conbus_datapoint_commands import (
36
+ query_all_datapoints,
37
+ query_datapoint,
38
+ )
39
+ from xp.cli.commands.conbus.conbus_discover_commands import send_discover_telegram
40
+ from xp.cli.commands.conbus.conbus_event_commands import conbus_event, send_event_raw
41
+ from xp.cli.commands.conbus.conbus_lightlevel_commands import (
42
+ xp_lightlevel_get,
43
+ xp_lightlevel_off,
44
+ xp_lightlevel_on,
45
+ xp_lightlevel_set,
46
+ )
47
+ from xp.cli.commands.conbus.conbus_linknumber_commands import (
48
+ get_linknumber_command,
49
+ set_linknumber_command,
50
+ )
51
+ from xp.cli.commands.conbus.conbus_modulenumber_commands import (
52
+ get_modulenumber_command,
53
+ set_modulenumber_command,
54
+ )
55
+ from xp.cli.commands.conbus.conbus_msactiontable_commands import (
56
+ conbus_download_msactiontable,
57
+ )
58
+ from xp.cli.commands.conbus.conbus_output_commands import (
59
+ xp_module_state,
60
+ xp_output_off,
61
+ xp_output_on,
62
+ xp_output_status,
63
+ )
64
+ from xp.cli.commands.conbus.conbus_raw_commands import send_raw_telegrams
65
+ from xp.cli.commands.conbus.conbus_receive_commands import receive_telegrams
66
+ from xp.cli.commands.conbus.conbus_scan_commands import scan_module
67
+ from xp.cli.commands.file_commands import file
68
+ from xp.cli.commands.homekit.homekit import homekit
69
+ from xp.cli.commands.homekit.homekit_start_commands import homekit_start
70
+ from xp.cli.commands.module_commands import module
71
+ from xp.cli.commands.reverse_proxy_commands import reverse_proxy
72
+ from xp.cli.commands.server.server_commands import server
73
+ from xp.cli.commands.telegram.telegram import blink, checksum, linknumber, telegram
74
+ from xp.cli.commands.telegram.telegram_blink_commands import blink_off, blink_on
75
+ from xp.cli.commands.telegram.telegram_checksum_commands import (
76
+ calculate_checksum,
77
+ validate_checksum,
78
+ )
79
+ from xp.cli.commands.telegram.telegram_discover_commands import generate_discover
80
+ from xp.cli.commands.telegram.telegram_linknumber_commands import (
81
+ generate_read_link_number,
82
+ generate_set_link_number,
83
+ )
84
+ from xp.cli.commands.telegram.telegram_parse_commands import (
85
+ parse_any_telegram,
86
+ validate_telegram,
87
+ )
88
+ from xp.cli.commands.telegram.telegram_version_commands import generate_version_request
89
+
90
+ __all__ = [
91
+ # Main command groups (conbus excluded to avoid module shadowing)
92
+ "conbus_blink",
93
+ "conbus_output",
94
+ "conbus_datapoint",
95
+ "conbus_linknumber",
96
+ "conbus_modulenumber",
97
+ "conbus_autoreport",
98
+ "conbus_lightlevel",
99
+ "conbus_msactiontable",
100
+ "conbus_actiontable",
101
+ "conbus_event",
102
+ "file",
103
+ "module",
104
+ "reverse_proxy",
105
+ "server",
106
+ "telegram",
107
+ "linknumber",
108
+ "blink",
109
+ "checksum",
110
+ "homekit",
111
+ "homekit_start",
112
+ # Individual command functions
113
+ "conbus_download_msactiontable",
114
+ "conbus_download_actiontable",
115
+ "send_blink_on_telegram",
116
+ "send_blink_off_telegram",
117
+ "conbus_blink_all",
118
+ "blink_all_off",
119
+ "blink_all_on",
120
+ "show_config",
121
+ "send_custom_telegram",
122
+ "send_discover_telegram",
123
+ "send_event_raw",
124
+ "xp_output_on",
125
+ "xp_output_off",
126
+ "xp_output_status",
127
+ "xp_module_state",
128
+ "scan_module",
129
+ "query_datapoint",
130
+ "query_all_datapoints",
131
+ "send_raw_telegrams",
132
+ "receive_telegrams",
133
+ "set_linknumber_command",
134
+ "get_linknumber_command",
135
+ "set_modulenumber_command",
136
+ "get_modulenumber_command",
137
+ "get_autoreport_command",
138
+ "set_autoreport_command",
139
+ "xp_lightlevel_set",
140
+ "xp_lightlevel_off",
141
+ "xp_lightlevel_on",
142
+ "xp_lightlevel_get",
143
+ "blink_on",
144
+ "blink_off",
145
+ "parse_any_telegram",
146
+ "validate_telegram",
147
+ "generate_discover",
148
+ "generate_set_link_number",
149
+ "generate_read_link_number",
150
+ "generate_version_request",
151
+ "calculate_checksum",
152
+ "validate_checksum",
153
+ ]
@@ -0,0 +1,25 @@
1
+ """Conbus CLI commands package."""
2
+
3
+ from xp.cli.commands.conbus.conbus import (
4
+ conbus,
5
+ conbus_actiontable,
6
+ conbus_autoreport,
7
+ conbus_blink,
8
+ conbus_datapoint,
9
+ conbus_lightlevel,
10
+ conbus_linknumber,
11
+ conbus_msactiontable,
12
+ conbus_output,
13
+ )
14
+
15
+ __all__ = [
16
+ "conbus",
17
+ "conbus_blink",
18
+ "conbus_output",
19
+ "conbus_datapoint",
20
+ "conbus_linknumber",
21
+ "conbus_autoreport",
22
+ "conbus_lightlevel",
23
+ "conbus_msactiontable",
24
+ "conbus_actiontable",
25
+ ]
@@ -0,0 +1,128 @@
1
+ """Shared conbus CLI group definition."""
2
+
3
+ import click
4
+ from click_help_colors import HelpColorsGroup
5
+
6
+
7
+ @click.group(
8
+ cls=HelpColorsGroup, help_headers_color="yellow", help_options_color="green"
9
+ )
10
+ def conbus() -> None:
11
+ """Perform Conbus client operations for sending telegrams to remote servers."""
12
+ pass
13
+
14
+
15
+ @click.group(
16
+ name="blink",
17
+ cls=HelpColorsGroup,
18
+ help_headers_color="yellow",
19
+ help_options_color="green",
20
+ )
21
+ def conbus_blink() -> None:
22
+ """Perform Conbus client operations for sending blink telegrams to remote servers."""
23
+ pass
24
+
25
+
26
+ @click.group(
27
+ name="output",
28
+ cls=HelpColorsGroup,
29
+ help_headers_color="yellow",
30
+ help_options_color="green",
31
+ )
32
+ def conbus_output() -> None:
33
+ """Perform Conbus input operations to remote servers."""
34
+ pass
35
+
36
+
37
+ @click.group(
38
+ name="datapoint",
39
+ cls=HelpColorsGroup,
40
+ help_headers_color="yellow",
41
+ help_options_color="green",
42
+ )
43
+ def conbus_datapoint() -> None:
44
+ """Perform Conbus datapoint operations for querying module datapoints."""
45
+ pass
46
+
47
+
48
+ @click.group(
49
+ "linknumber",
50
+ cls=HelpColorsGroup,
51
+ help_headers_color="yellow",
52
+ help_options_color="green",
53
+ short_help="Link number operations",
54
+ )
55
+ def conbus_linknumber() -> None:
56
+ """Set or get the link number for specific modules."""
57
+ pass
58
+
59
+
60
+ @click.group(
61
+ "modulenumber",
62
+ cls=HelpColorsGroup,
63
+ help_headers_color="yellow",
64
+ help_options_color="green",
65
+ short_help="Module number operations",
66
+ )
67
+ def conbus_modulenumber() -> None:
68
+ """Set or get the module number for specific modules."""
69
+ pass
70
+
71
+
72
+ @click.group(
73
+ "autoreport",
74
+ cls=HelpColorsGroup,
75
+ help_headers_color="yellow",
76
+ help_options_color="green",
77
+ short_help="Auto report status operations",
78
+ )
79
+ def conbus_autoreport() -> None:
80
+ """Get or set the auto report status for specific modules."""
81
+ pass
82
+
83
+
84
+ @click.group(
85
+ "lightlevel",
86
+ cls=HelpColorsGroup,
87
+ help_headers_color="yellow",
88
+ help_options_color="green",
89
+ short_help="Light level operations",
90
+ )
91
+ def conbus_lightlevel() -> None:
92
+ """Control light level (dimming) of outputs on Conbus modules."""
93
+ pass
94
+
95
+
96
+ @click.group(
97
+ "msactiontable",
98
+ cls=HelpColorsGroup,
99
+ help_headers_color="yellow",
100
+ help_options_color="green",
101
+ short_help="MSActionTable operations",
102
+ )
103
+ def conbus_msactiontable() -> None:
104
+ """Download msactiontable on Conbus modules."""
105
+ pass
106
+
107
+
108
+ @click.group(
109
+ "actiontable",
110
+ cls=HelpColorsGroup,
111
+ help_headers_color="yellow",
112
+ help_options_color="green",
113
+ short_help="ActionTable operations",
114
+ )
115
+ def conbus_actiontable() -> None:
116
+ """Download ActionTable from Conbus modules."""
117
+ pass
118
+
119
+
120
+ conbus.add_command(conbus_blink)
121
+ conbus.add_command(conbus_output)
122
+ conbus.add_command(conbus_datapoint)
123
+ conbus.add_command(conbus_linknumber)
124
+ conbus.add_command(conbus_modulenumber)
125
+ conbus.add_command(conbus_autoreport)
126
+ conbus.add_command(conbus_lightlevel)
127
+ conbus.add_command(conbus_msactiontable)
128
+ conbus.add_command(conbus_actiontable)
@@ -0,0 +1,233 @@
1
+ """ActionTable CLI commands."""
2
+
3
+ import json
4
+ from contextlib import suppress
5
+ from pathlib import Path
6
+ from typing import Any
7
+
8
+ import click
9
+ from click import Context
10
+
11
+ from xp.cli.commands.conbus.conbus import conbus_actiontable
12
+ from xp.cli.utils.decorators import (
13
+ connection_command,
14
+ )
15
+ from xp.cli.utils.serial_number_type import SERIAL
16
+ from xp.models.actiontable.actiontable import ActionTable
17
+ from xp.models.homekit.homekit_conson_config import (
18
+ ConsonModuleConfig,
19
+ ConsonModuleListConfig,
20
+ )
21
+ from xp.services.conbus.actiontable.actiontable_download_service import (
22
+ ActionTableService,
23
+ )
24
+ from xp.services.conbus.actiontable.actiontable_list_service import (
25
+ ActionTableListService,
26
+ )
27
+ from xp.services.conbus.actiontable.actiontable_show_service import (
28
+ ActionTableShowService,
29
+ )
30
+ from xp.services.conbus.actiontable.actiontable_upload_service import (
31
+ ActionTableUploadService,
32
+ )
33
+
34
+
35
+ class ActionTableError(Exception):
36
+ """Raised when ActionTable operations fail."""
37
+
38
+ pass
39
+
40
+
41
+ @conbus_actiontable.command("download", short_help="Download ActionTable")
42
+ @click.argument("serial_number", type=SERIAL)
43
+ @click.pass_context
44
+ @connection_command()
45
+ def conbus_download_actiontable(ctx: Context, serial_number: str) -> None:
46
+ """Download action table from XP module.
47
+
48
+ Args:
49
+ ctx: Click context object.
50
+ serial_number: 10-digit module serial number.
51
+ """
52
+ service: ActionTableService = (
53
+ ctx.obj.get("container").get_container().resolve(ActionTableService)
54
+ )
55
+
56
+ def progress_callback(progress: str) -> None:
57
+ """Handle progress updates during action table download.
58
+
59
+ Args:
60
+ progress: Progress message string.
61
+ """
62
+ click.echo(progress)
63
+
64
+ def on_finish(
65
+ _actiontable: ActionTable,
66
+ actiontable_dict: dict[str, Any],
67
+ actiontable_short: list[str],
68
+ ) -> None:
69
+ """Handle successful completion of action table download.
70
+
71
+ Args:
72
+ _actiontable: Downloaded action table object.
73
+ actiontable_dict: Dictionary representation of action table.
74
+ actiontable_short: List of textual format strings.
75
+ """
76
+ output = {
77
+ "serial_number": serial_number,
78
+ "actiontable_short": actiontable_short,
79
+ "actiontable": actiontable_dict,
80
+ }
81
+ click.echo(json.dumps(output, indent=2, default=str))
82
+
83
+ def error_callback(error: str) -> None:
84
+ """Handle errors during action table download.
85
+
86
+ Args:
87
+ error: Error message string.
88
+ """
89
+ click.echo(error)
90
+
91
+ with service:
92
+ service.start(
93
+ serial_number=serial_number,
94
+ progress_callback=progress_callback,
95
+ finish_callback=on_finish,
96
+ error_callback=error_callback,
97
+ )
98
+
99
+
100
+ @conbus_actiontable.command("upload", short_help="Upload ActionTable")
101
+ @click.argument("serial_number", type=SERIAL)
102
+ @click.pass_context
103
+ @connection_command()
104
+ def conbus_upload_actiontable(ctx: Context, serial_number: str) -> None:
105
+ """Upload action table from conson.yml to XP module.
106
+
107
+ Args:
108
+ ctx: Click context object.
109
+ serial_number: 10-digit module serial number.
110
+ """
111
+ service: ActionTableUploadService = (
112
+ ctx.obj.get("container").get_container().resolve(ActionTableUploadService)
113
+ )
114
+
115
+ click.echo(f"Uploading action table to {serial_number}...")
116
+
117
+ # Track number of entries for success message
118
+ entries_count = 0
119
+
120
+ def progress_callback(progress: str) -> None:
121
+ """Handle progress updates during action table upload.
122
+
123
+ Args:
124
+ progress: Progress message string.
125
+ """
126
+ click.echo(progress, nl=False)
127
+
128
+ def success_callback() -> None:
129
+ """Handle successful completion of action table upload."""
130
+ click.echo("\nAction table uploaded successfully")
131
+ if entries_count > 0:
132
+ click.echo(f"{entries_count} entries written")
133
+
134
+ def error_callback(error: str) -> None:
135
+ """Handle errors during action table upload.
136
+
137
+ Args:
138
+ error: Error message string.
139
+
140
+ Raises:
141
+ ActionTableError: Always raised with upload failure message.
142
+ """
143
+ raise ActionTableError(f"Upload failed: {error}")
144
+
145
+ with service:
146
+ # Load config to get entry count for success message
147
+ config_path = Path.cwd() / "conson.yml"
148
+ if config_path.exists():
149
+ with suppress(Exception):
150
+ config = ConsonModuleListConfig.from_yaml(str(config_path))
151
+ module = config.find_module(serial_number)
152
+ if module and module.action_table:
153
+ entries_count = len(module.action_table)
154
+
155
+ service.start(
156
+ serial_number=serial_number,
157
+ progress_callback=progress_callback,
158
+ success_callback=success_callback,
159
+ error_callback=error_callback,
160
+ )
161
+
162
+
163
+ @conbus_actiontable.command("list", short_help="List modules with ActionTable")
164
+ @click.pass_context
165
+ def conbus_list_actiontable(ctx: Context) -> None:
166
+ """List all modules with action table configurations from conson.yml.
167
+
168
+ Args:
169
+ ctx: Click context object.
170
+ """
171
+ service: ActionTableListService = (
172
+ ctx.obj.get("container").get_container().resolve(ActionTableListService)
173
+ )
174
+
175
+ def on_finish(module_list: dict) -> None:
176
+ """Handle successful completion of action table list.
177
+
178
+ Args:
179
+ module_list: Dictionary containing modules and total count.
180
+ """
181
+ click.echo(json.dumps(module_list, indent=2, default=str))
182
+
183
+ def error_callback(error: str) -> None:
184
+ """Handle errors during action table list.
185
+
186
+ Args:
187
+ error: Error message string.
188
+ """
189
+ click.echo(error)
190
+
191
+ with service:
192
+ service.start(
193
+ finish_callback=on_finish,
194
+ error_callback=error_callback,
195
+ )
196
+
197
+
198
+ @conbus_actiontable.command("show", short_help="Show ActionTable configuration")
199
+ @click.argument("serial_number", type=SERIAL)
200
+ @click.pass_context
201
+ def conbus_show_actiontable(ctx: Context, serial_number: str) -> None:
202
+ """Show action table configuration for a specific module from conson.yml.
203
+
204
+ Args:
205
+ ctx: Click context object.
206
+ serial_number: 10-digit module serial number.
207
+ """
208
+ service: ActionTableShowService = (
209
+ ctx.obj.get("container").get_container().resolve(ActionTableShowService)
210
+ )
211
+
212
+ def on_finish(module: ConsonModuleConfig) -> None:
213
+ """Handle successful completion of action table show.
214
+
215
+ Args:
216
+ module: Dictionary containing module configuration.
217
+ """
218
+ click.echo(json.dumps(module.model_dump(), indent=2, default=str))
219
+
220
+ def error_callback(error: str) -> None:
221
+ """Handle errors during action table show.
222
+
223
+ Args:
224
+ error: Error message string.
225
+ """
226
+ click.echo(error)
227
+
228
+ with service:
229
+ service.start(
230
+ serial_number=serial_number,
231
+ finish_callback=on_finish,
232
+ error_callback=error_callback,
233
+ )
@@ -0,0 +1,108 @@
1
+ """Conbus auto report CLI commands."""
2
+
3
+ import json
4
+
5
+ import click
6
+ from click import Context
7
+
8
+ from xp.cli.commands.conbus.conbus import conbus_autoreport
9
+ from xp.cli.utils.decorators import (
10
+ connection_command,
11
+ )
12
+ from xp.cli.utils.serial_number_type import SERIAL
13
+ from xp.models import ConbusDatapointResponse
14
+ from xp.models.conbus.conbus_writeconfig import ConbusWriteConfigResponse
15
+ from xp.models.telegram.datapoint_type import DataPointType
16
+ from xp.services.conbus.conbus_datapoint_service import ConbusDatapointService
17
+ from xp.services.conbus.write_config_service import WriteConfigService
18
+ from xp.services.telegram.telegram_datapoint_service import TelegramDatapointService
19
+
20
+
21
+ @conbus_autoreport.command("get", short_help="Get auto report status for a module")
22
+ @click.argument("serial_number", type=SERIAL)
23
+ @connection_command()
24
+ @click.pass_context
25
+ def get_autoreport_command(ctx: Context, serial_number: str) -> None:
26
+ r"""Get the current auto report status for a specific module.
27
+
28
+ Args:
29
+ ctx: Click context object.
30
+ serial_number: 10-digit module serial number.
31
+
32
+ Examples:
33
+ \b
34
+ xp conbus autoreport get 0123450001
35
+ """
36
+ # Get service from container
37
+ service: ConbusDatapointService = (
38
+ ctx.obj.get("container").get_container().resolve(ConbusDatapointService)
39
+ )
40
+ telegram_service: TelegramDatapointService = (
41
+ ctx.obj.get("container").get_container().resolve(TelegramDatapointService)
42
+ )
43
+
44
+ def on_finish(service_response: ConbusDatapointResponse) -> None:
45
+ """Handle successful completion of auto report status retrieval.
46
+
47
+ Args:
48
+ service_response: Auto report response object.
49
+ """
50
+ auto_report_status = telegram_service.get_autoreport_status(
51
+ service_response.data_value
52
+ )
53
+ result = service_response.to_dict()
54
+ result["auto_report_status"] = auto_report_status
55
+ click.echo(json.dumps(result, indent=2))
56
+
57
+ with service:
58
+ service.query_datapoint(
59
+ serial_number=serial_number,
60
+ datapoint_type=DataPointType.AUTO_REPORT_STATUS,
61
+ finish_callback=on_finish,
62
+ )
63
+
64
+
65
+ @conbus_autoreport.command("set", short_help="Set auto report status for a module")
66
+ @click.argument("serial_number", type=SERIAL)
67
+ @click.argument("status", type=click.Choice(["on", "off"], case_sensitive=False))
68
+ @connection_command()
69
+ @click.pass_context
70
+ def set_autoreport_command(ctx: Context, serial_number: str, status: str) -> None:
71
+ r"""Set the auto report status for a specific module.
72
+
73
+ Args:
74
+ ctx: Click context object.
75
+ serial_number: 10-digit module serial number.
76
+ status: Auto report status - either 'on' or 'off'.
77
+
78
+ Examples:
79
+ \b
80
+ xp conbus autoreport set 0123450001 on
81
+ xp conbus autoreport set 0123450001 off
82
+ """
83
+
84
+ def on_finish(response: "ConbusWriteConfigResponse") -> None:
85
+ """Handle successful completion of light level on command.
86
+
87
+ Args:
88
+ response: Light level response object.
89
+ """
90
+ click.echo(json.dumps(response.to_dict(), indent=2))
91
+
92
+ service: WriteConfigService = (
93
+ ctx.obj.get("container").get_container().resolve(WriteConfigService)
94
+ )
95
+ telegram_service: TelegramDatapointService = (
96
+ ctx.obj.get("container").get_container().resolve(TelegramDatapointService)
97
+ )
98
+ status_value = True if status == "on" else False
99
+ data_value = telegram_service.get_autoreport_status_data_value(status_value)
100
+
101
+ with service:
102
+ service.write_config(
103
+ serial_number=serial_number,
104
+ datapoint_type=DataPointType.AUTO_REPORT_STATUS,
105
+ data_value=data_value,
106
+ finish_callback=on_finish,
107
+ timeout_seconds=0.5,
108
+ )