conson-xp 1.46.0__py3-none-any.whl → 1.48.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 (179) hide show
  1. {conson_xp-1.46.0.dist-info → conson_xp-1.48.0.dist-info}/METADATA +1 -1
  2. conson_xp-1.48.0.dist-info/RECORD +210 -0
  3. xp/__init__.py +3 -2
  4. xp/cli/commands/conbus/conbus.py +1 -1
  5. xp/cli/commands/conbus/conbus_actiontable_commands.py +33 -19
  6. xp/cli/commands/conbus/conbus_autoreport_commands.py +8 -4
  7. xp/cli/commands/conbus/conbus_blink_commands.py +20 -10
  8. xp/cli/commands/conbus/conbus_config_commands.py +2 -1
  9. xp/cli/commands/conbus/conbus_custom_commands.py +4 -2
  10. xp/cli/commands/conbus/conbus_datapoint_commands.py +10 -5
  11. xp/cli/commands/conbus/conbus_discover_commands.py +8 -4
  12. xp/cli/commands/conbus/conbus_event_commands.py +8 -4
  13. xp/cli/commands/conbus/conbus_export_commands.py +8 -4
  14. xp/cli/commands/conbus/conbus_lightlevel_commands.py +16 -8
  15. xp/cli/commands/conbus/conbus_linknumber_commands.py +8 -4
  16. xp/cli/commands/conbus/conbus_modulenumber_commands.py +8 -4
  17. xp/cli/commands/conbus/conbus_msactiontable_commands.py +78 -40
  18. xp/cli/commands/conbus/conbus_output_commands.py +16 -8
  19. xp/cli/commands/conbus/conbus_raw_commands.py +6 -3
  20. xp/cli/commands/conbus/conbus_receive_commands.py +6 -3
  21. xp/cli/commands/conbus/conbus_scan_commands.py +6 -3
  22. xp/cli/commands/file_commands.py +6 -3
  23. xp/cli/commands/homekit/homekit.py +4 -2
  24. xp/cli/commands/homekit/homekit_start_commands.py +2 -1
  25. xp/cli/commands/module_commands.py +8 -4
  26. xp/cli/commands/reverse_proxy_commands.py +8 -4
  27. xp/cli/commands/server/server_commands.py +6 -3
  28. xp/cli/commands/telegram/telegram_blink_commands.py +4 -2
  29. xp/cli/commands/telegram/telegram_checksum_commands.py +4 -2
  30. xp/cli/commands/telegram/telegram_discover_commands.py +2 -1
  31. xp/cli/commands/telegram/telegram_linknumber_commands.py +4 -2
  32. xp/cli/commands/telegram/telegram_parse_commands.py +4 -2
  33. xp/cli/commands/telegram/telegram_version_commands.py +2 -1
  34. xp/cli/commands/term/term_commands.py +4 -2
  35. xp/cli/main.py +2 -1
  36. xp/cli/utils/click_tree.py +6 -3
  37. xp/cli/utils/datapoint_type_choice.py +4 -2
  38. xp/cli/utils/decorators.py +42 -21
  39. xp/cli/utils/error_handlers.py +16 -8
  40. xp/cli/utils/formatters.py +22 -11
  41. xp/cli/utils/module_type_choice.py +4 -2
  42. xp/cli/utils/serial_number_type.py +4 -2
  43. xp/cli/utils/system_function_choice.py +4 -2
  44. xp/cli/utils/xp_module_type.py +4 -2
  45. xp/models/actiontable/actiontable.py +8 -8
  46. xp/models/actiontable/actiontable_type.py +20 -0
  47. xp/models/actiontable/msactiontable_xp20.py +8 -4
  48. xp/models/actiontable/msactiontable_xp24.py +12 -6
  49. xp/models/actiontable/msactiontable_xp33.py +20 -10
  50. xp/models/conbus/conbus.py +8 -4
  51. xp/models/conbus/conbus_autoreport.py +4 -2
  52. xp/models/conbus/conbus_blink.py +4 -2
  53. xp/models/conbus/conbus_client_config.py +6 -3
  54. xp/models/conbus/conbus_connection_status.py +4 -2
  55. xp/models/conbus/conbus_custom.py +4 -2
  56. xp/models/conbus/conbus_datapoint.py +4 -2
  57. xp/models/conbus/conbus_discover.py +6 -3
  58. xp/models/conbus/conbus_event_list.py +4 -2
  59. xp/models/conbus/conbus_event_raw.py +4 -2
  60. xp/models/conbus/conbus_export.py +2 -1
  61. xp/models/conbus/conbus_lightlevel.py +4 -2
  62. xp/models/conbus/conbus_linknumber.py +4 -2
  63. xp/models/conbus/conbus_logger_config.py +8 -4
  64. xp/models/conbus/conbus_output.py +4 -2
  65. xp/models/conbus/conbus_raw.py +4 -2
  66. xp/models/conbus/conbus_receive.py +4 -2
  67. xp/models/conbus/conbus_writeconfig.py +4 -2
  68. xp/models/config/conson_module_config.py +8 -4
  69. xp/models/homekit/homekit_accessory.py +4 -2
  70. xp/models/homekit/homekit_config.py +12 -6
  71. xp/models/log_entry.py +16 -8
  72. xp/models/protocol/conbus_protocol.py +36 -18
  73. xp/models/response.py +12 -8
  74. xp/models/telegram/action_type.py +4 -2
  75. xp/models/telegram/datapoint_type.py +4 -2
  76. xp/models/telegram/event_telegram.py +14 -7
  77. xp/models/telegram/event_type.py +2 -1
  78. xp/models/telegram/input_action_type.py +2 -1
  79. xp/models/telegram/input_type.py +2 -1
  80. xp/models/telegram/module_type.py +24 -12
  81. xp/models/telegram/module_type_code.py +2 -1
  82. xp/models/telegram/output_telegram.py +16 -10
  83. xp/models/telegram/reply_telegram.py +24 -13
  84. xp/models/telegram/system_function.py +6 -3
  85. xp/models/telegram/system_telegram.py +10 -6
  86. xp/models/telegram/telegram.py +2 -1
  87. xp/models/telegram/telegram_type.py +2 -1
  88. xp/models/telegram/timeparam_type.py +2 -1
  89. xp/models/term/connection_state.py +4 -2
  90. xp/models/term/module_state.py +2 -1
  91. xp/models/term/protocol_keys_config.py +6 -3
  92. xp/models/term/status_message.py +2 -1
  93. xp/models/term/telegram_display.py +2 -1
  94. xp/models/write_config_type.py +4 -2
  95. xp/services/actiontable/actiontable_serializer.py +34 -41
  96. xp/services/{conbus/actiontable/actiontable_download_state_machine.py → actiontable/download_state_machine.py} +13 -8
  97. xp/services/actiontable/msactiontable_xp20_serializer.py +73 -50
  98. xp/services/actiontable/msactiontable_xp24_serializer.py +73 -54
  99. xp/services/actiontable/msactiontable_xp33_serializer.py +44 -20
  100. xp/services/actiontable/serializer_protocol.py +76 -0
  101. xp/services/conbus/actiontable/actiontable_download_service.py +68 -31
  102. xp/services/conbus/actiontable/actiontable_list_service.py +17 -4
  103. xp/services/conbus/actiontable/actiontable_show_service.py +10 -6
  104. xp/services/conbus/actiontable/actiontable_upload_service.py +17 -9
  105. xp/services/conbus/conbus_blink_all_service.py +16 -8
  106. xp/services/conbus/conbus_blink_service.py +14 -7
  107. xp/services/conbus/conbus_custom_service.py +16 -8
  108. xp/services/conbus/conbus_datapoint_queryall_service.py +18 -9
  109. xp/services/conbus/conbus_datapoint_service.py +18 -9
  110. xp/services/conbus/conbus_discover_service.py +24 -13
  111. xp/services/conbus/conbus_event_list_service.py +11 -7
  112. xp/services/conbus/conbus_event_raw_service.py +18 -10
  113. xp/services/conbus/conbus_export_service.py +28 -14
  114. xp/services/conbus/conbus_output_service.py +18 -10
  115. xp/services/conbus/conbus_raw_service.py +16 -8
  116. xp/services/conbus/conbus_receive_service.py +18 -10
  117. xp/services/conbus/conbus_scan_service.py +18 -10
  118. xp/services/conbus/msactiontable/msactiontable_upload_service.py +18 -10
  119. xp/services/conbus/write_config_service.py +18 -9
  120. xp/services/homekit/homekit_cache_service.py +12 -6
  121. xp/services/homekit/homekit_conbus_service.py +12 -6
  122. xp/services/homekit/homekit_config_validator.py +34 -17
  123. xp/services/homekit/homekit_conson_validator.py +18 -9
  124. xp/services/homekit/homekit_dimminglight.py +14 -7
  125. xp/services/homekit/homekit_dimminglight_service.py +14 -7
  126. xp/services/homekit/homekit_hap_service.py +18 -9
  127. xp/services/homekit/homekit_lightbulb.py +10 -5
  128. xp/services/homekit/homekit_lightbulb_service.py +10 -5
  129. xp/services/homekit/homekit_module_service.py +8 -4
  130. xp/services/homekit/homekit_outlet.py +14 -7
  131. xp/services/homekit/homekit_outlet_service.py +12 -6
  132. xp/services/homekit/homekit_service.py +24 -12
  133. xp/services/log_file_service.py +16 -8
  134. xp/services/module_type_service.py +10 -5
  135. xp/services/protocol/conbus_event_protocol.py +51 -26
  136. xp/services/protocol/conbus_protocol.py +36 -19
  137. xp/services/protocol/protocol_factory.py +12 -6
  138. xp/services/protocol/telegram_protocol.py +12 -6
  139. xp/services/reverse_proxy_service.py +26 -14
  140. xp/services/server/base_server_service.py +42 -23
  141. xp/services/server/client_buffer_manager.py +12 -7
  142. xp/services/server/cp20_server_service.py +10 -7
  143. xp/services/server/device_service_factory.py +12 -8
  144. xp/services/server/server_service.py +18 -11
  145. xp/services/server/xp130_server_service.py +11 -8
  146. xp/services/server/xp20_server_service.py +16 -10
  147. xp/services/server/xp230_server_service.py +10 -7
  148. xp/services/server/xp24_server_service.py +22 -13
  149. xp/services/server/xp33_server_service.py +44 -25
  150. xp/services/telegram/telegram_blink_service.py +14 -8
  151. xp/services/telegram/telegram_checksum_service.py +12 -7
  152. xp/services/telegram/telegram_datapoint_service.py +14 -9
  153. xp/services/telegram/telegram_discover_service.py +28 -15
  154. xp/services/telegram/telegram_link_number_service.py +18 -10
  155. xp/services/telegram/telegram_output_service.py +24 -12
  156. xp/services/telegram/telegram_service.py +22 -11
  157. xp/services/telegram/telegram_version_service.py +14 -8
  158. xp/services/term/protocol_monitor_service.py +30 -16
  159. xp/services/term/state_monitor_service.py +39 -21
  160. xp/term/protocol.py +12 -6
  161. xp/term/state.py +12 -7
  162. xp/term/widgets/help_menu.py +6 -3
  163. xp/term/widgets/modules_list.py +20 -10
  164. xp/term/widgets/protocol_log.py +12 -6
  165. xp/term/widgets/status_footer.py +10 -5
  166. xp/utils/checksum.py +6 -3
  167. xp/utils/dependencies.py +25 -30
  168. xp/utils/event_helper.py +6 -4
  169. xp/utils/logging.py +6 -3
  170. xp/utils/serialization.py +30 -16
  171. xp/utils/state_machine.py +16 -9
  172. xp/utils/time_utils.py +6 -3
  173. conson_xp-1.46.0.dist-info/RECORD +0 -211
  174. xp/services/conbus/msactiontable/msactiontable_download_service.py +0 -275
  175. xp/services/conbus/msactiontable/msactiontable_list_service.py +0 -100
  176. xp/services/conbus/msactiontable/msactiontable_show_service.py +0 -89
  177. {conson_xp-1.46.0.dist-info → conson_xp-1.48.0.dist-info}/WHEEL +0 -0
  178. {conson_xp-1.46.0.dist-info → conson_xp-1.48.0.dist-info}/entry_points.txt +0 -0
  179. {conson_xp-1.46.0.dist-info → conson_xp-1.48.0.dist-info}/licenses/LICENSE +0 -0
@@ -1,275 +0,0 @@
1
- """Service for downloading XP24 action tables via Conbus protocol."""
2
-
3
- import logging
4
- from typing import Any, Optional, Union
5
-
6
- from psygnal import Signal
7
-
8
- from xp.models.actiontable.msactiontable_xp20 import Xp20MsActionTable
9
- from xp.models.actiontable.msactiontable_xp24 import Xp24MsActionTable
10
- from xp.models.actiontable.msactiontable_xp33 import Xp33MsActionTable
11
- from xp.models.protocol.conbus_protocol import TelegramReceivedEvent
12
- from xp.models.telegram.system_function import SystemFunction
13
- from xp.models.telegram.telegram_type import TelegramType
14
- from xp.services.actiontable.msactiontable_xp20_serializer import (
15
- Xp20MsActionTableSerializer,
16
- )
17
- from xp.services.actiontable.msactiontable_xp24_serializer import (
18
- Xp24MsActionTableSerializer,
19
- )
20
- from xp.services.actiontable.msactiontable_xp33_serializer import (
21
- Xp33MsActionTableSerializer,
22
- )
23
- from xp.services.protocol.conbus_event_protocol import ConbusEventProtocol
24
- from xp.services.telegram.telegram_service import TelegramService
25
-
26
-
27
- class MsActionTableError(Exception):
28
- """Raised when XP24 action table operations fail."""
29
-
30
- pass
31
-
32
-
33
- class MsActionTableDownloadService:
34
- """
35
- Service for downloading MS action tables via Conbus protocol.
36
-
37
- Uses ConbusEventProtocol to download action tables from XP20, XP24, or XP33 modules.
38
- Emits signals for progress updates, errors, and completion.
39
-
40
- Attributes:
41
- conbus_protocol: Protocol instance for Conbus communication.
42
- on_progress: Signal emitted for progress updates (str).
43
- on_error: Signal emitted for errors (str).
44
- on_finish: Signal emitted when XP download completes (Xp20MsActionTable, str).
45
- """
46
-
47
- on_progress: Signal = Signal(str)
48
- on_error: Signal = Signal(str)
49
- on_finish: Signal = Signal(object, list[str])
50
-
51
- def __init__(
52
- self,
53
- conbus_protocol: ConbusEventProtocol,
54
- xp20ms_serializer: Xp20MsActionTableSerializer,
55
- xp24ms_serializer: Xp24MsActionTableSerializer,
56
- xp33ms_serializer: Xp33MsActionTableSerializer,
57
- telegram_service: TelegramService,
58
- ) -> None:
59
- """Initialize the MS action table service.
60
-
61
- Args:
62
- conbus_protocol: ConbusEventProtocol instance.
63
- xp20ms_serializer: XP20 MS action table serializer.
64
- xp24ms_serializer: XP24 MS action table serializer.
65
- xp33ms_serializer: XP33 MS action table serializer.
66
- telegram_service: Telegram service for parsing.
67
- """
68
- self.conbus_protocol = conbus_protocol
69
- self.xp20ms_serializer = xp20ms_serializer
70
- self.xp24ms_serializer = xp24ms_serializer
71
- self.xp33ms_serializer = xp33ms_serializer
72
- self.serializer: Union[
73
- Xp20MsActionTableSerializer,
74
- Xp24MsActionTableSerializer,
75
- Xp33MsActionTableSerializer,
76
- ] = xp20ms_serializer
77
- self.telegram_service = telegram_service
78
- self.serial_number: str = ""
79
- self.xpmoduletype: str = ""
80
- self.msactiontable_data: list[str] = []
81
- # Set up logging
82
- self.logger = logging.getLogger(__name__)
83
-
84
- # Connect protocol signals
85
- self.conbus_protocol.on_connection_made.connect(self.connection_made)
86
- self.conbus_protocol.on_telegram_sent.connect(self.telegram_sent)
87
- self.conbus_protocol.on_telegram_received.connect(self.telegram_received)
88
- self.conbus_protocol.on_timeout.connect(self.timeout)
89
- self.conbus_protocol.on_failed.connect(self.failed)
90
-
91
- def connection_made(self) -> None:
92
- """Handle connection made event."""
93
- self.logger.debug(
94
- "Connection established, sending download msactiontable telegram"
95
- )
96
- self.conbus_protocol.send_telegram(
97
- telegram_type=TelegramType.SYSTEM,
98
- serial_number=self.serial_number,
99
- system_function=SystemFunction.DOWNLOAD_MSACTIONTABLE,
100
- data_value="00",
101
- )
102
-
103
- def telegram_sent(self, telegram_sent: str) -> None:
104
- """Handle telegram sent event.
105
-
106
- Args:
107
- telegram_sent: The telegram that was sent.
108
- """
109
- self.logger.debug(f"Telegram sent: {telegram_sent}")
110
-
111
- def telegram_received(self, telegram_received: TelegramReceivedEvent) -> None:
112
- """Handle telegram received event.
113
-
114
- Args:
115
- telegram_received: The telegram received event.
116
- """
117
- self.logger.debug(f"Telegram received: {telegram_received}")
118
- if (
119
- not telegram_received.checksum_valid
120
- or telegram_received.telegram_type != TelegramType.REPLY.value
121
- or telegram_received.serial_number != self.serial_number
122
- ):
123
- self.logger.debug("Not a reply response")
124
- return
125
-
126
- reply_telegram = self.telegram_service.parse_reply_telegram(
127
- telegram_received.frame
128
- )
129
- if reply_telegram.system_function not in (
130
- SystemFunction.MSACTIONTABLE,
131
- SystemFunction.ACK,
132
- SystemFunction.NAK,
133
- SystemFunction.EOF,
134
- ):
135
- self.logger.debug("Not a msactiontable response")
136
- return
137
-
138
- if reply_telegram.system_function == SystemFunction.ACK:
139
- self.logger.debug("Received ACK")
140
- return
141
-
142
- if reply_telegram.system_function == SystemFunction.NAK:
143
- self.logger.debug("Received NAK")
144
- self.failed("Received NAK")
145
- return
146
-
147
- if reply_telegram.system_function == SystemFunction.MSACTIONTABLE:
148
- self.logger.debug("Received MSACTIONTABLE")
149
- self.msactiontable_data.extend(
150
- (reply_telegram.data, reply_telegram.data_value)
151
- )
152
- self.on_progress.emit(".")
153
-
154
- self.conbus_protocol.send_telegram(
155
- telegram_type=TelegramType.SYSTEM,
156
- serial_number=self.serial_number,
157
- system_function=SystemFunction.ACK,
158
- data_value="00",
159
- )
160
- return
161
-
162
- if reply_telegram.system_function == SystemFunction.EOF:
163
- self.logger.debug("Received EOF")
164
- all_data = "".join(self.msactiontable_data)
165
- # Deserialize from received data
166
- msactiontable = self.serializer.from_data(all_data)
167
- msactiontable_short = self.serializer.format_decoded_output(msactiontable) # type: ignore[arg-type]
168
- self.succeed(msactiontable, msactiontable_short)
169
- return
170
-
171
- self.logger.debug("Invalid msactiontable response")
172
-
173
- def timeout(self) -> None:
174
- """Handle timeout event."""
175
- self.logger.debug("Timeout occurred")
176
- self.failed("Timeout")
177
-
178
- def failed(self, message: str) -> None:
179
- """Handle failed connection event.
180
-
181
- Args:
182
- message: Failure message.
183
- """
184
- self.logger.debug(f"Failed: {message}")
185
- self.on_error.emit(message)
186
-
187
- def succeed(
188
- self,
189
- msactiontable: Union[Xp20MsActionTable, Xp24MsActionTable, Xp33MsActionTable],
190
- msactiontable_short: list[str],
191
- ) -> None:
192
- """Handle succeed connection event.
193
-
194
- Args:
195
- msactiontable: result.
196
- msactiontable_short: result in short form.
197
- """
198
- # Emit to the appropriate signal based on module type
199
- self.on_finish.emit(msactiontable, msactiontable_short)
200
-
201
- def start(
202
- self,
203
- serial_number: str,
204
- xpmoduletype: str,
205
- timeout_seconds: Optional[float] = None,
206
- ) -> None:
207
- """Setup download parameters.
208
-
209
- Args:
210
- serial_number: Module serial number.
211
- xpmoduletype: XP module type (xp20, xp24, xp33).
212
- timeout_seconds: Optional timeout in seconds.
213
-
214
- Raises:
215
- MsActionTableError: If unsupported module type is provided.
216
- """
217
- self.logger.info("Starting msactiontable")
218
- self.serial_number = serial_number
219
- self.xpmoduletype = xpmoduletype
220
- if xpmoduletype == "xp20":
221
- self.serializer = self.xp20ms_serializer
222
- elif xpmoduletype == "xp24":
223
- self.serializer = self.xp24ms_serializer
224
- elif xpmoduletype == "xp33":
225
- self.serializer = self.xp33ms_serializer
226
- else:
227
- raise MsActionTableError(f"Unsupported module type: {xpmoduletype}")
228
-
229
- if timeout_seconds:
230
- self.conbus_protocol.timeout_seconds = timeout_seconds
231
-
232
- def set_timeout(self, timeout_seconds: float) -> None:
233
- """Set operation timeout.
234
-
235
- Args:
236
- timeout_seconds: Timeout in seconds.
237
- """
238
- self.conbus_protocol.timeout_seconds = timeout_seconds
239
-
240
- def start_reactor(self) -> None:
241
- """Start the reactor."""
242
- self.conbus_protocol.start_reactor()
243
-
244
- def stop_reactor(self) -> None:
245
- """Stop the reactor."""
246
- self.conbus_protocol.stop_reactor()
247
-
248
- def __enter__(self) -> "MsActionTableDownloadService":
249
- """Enter context manager.
250
-
251
- Returns:
252
- Self for context manager protocol.
253
- """
254
- # Reset state for singleton reuse
255
- self.msactiontable_data = []
256
- self.serial_number = ""
257
- self.xpmoduletype = ""
258
- return self
259
-
260
- def __exit__(
261
- self, _exc_type: Optional[type], _exc_val: Optional[Exception], _exc_tb: Any
262
- ) -> None:
263
- """Exit context manager and disconnect signals."""
264
- # Disconnect protocol signals
265
- self.conbus_protocol.on_connection_made.disconnect(self.connection_made)
266
- self.conbus_protocol.on_telegram_sent.disconnect(self.telegram_sent)
267
- self.conbus_protocol.on_telegram_received.disconnect(self.telegram_received)
268
- self.conbus_protocol.on_timeout.disconnect(self.timeout)
269
- self.conbus_protocol.on_failed.disconnect(self.failed)
270
- # Disconnect service signals
271
- self.on_progress.disconnect()
272
- self.on_error.disconnect()
273
- self.on_finish.disconnect()
274
- # Stop reactor
275
- self.stop_reactor()
@@ -1,100 +0,0 @@
1
- """Service for listing modules with action table configurations from conson.yml."""
2
-
3
- import logging
4
- from pathlib import Path
5
- from typing import Any, Optional
6
-
7
- from psygnal import Signal
8
-
9
-
10
- class MsActionTableListService:
11
- """Service for listing modules with action table configurations.
12
-
13
- Reads conson.yml and returns a list of all modules that have action table
14
- configurations defined.
15
-
16
- Attributes:
17
- on_finish: Signal emitted with dict[str, Any] when listing completes.
18
- on_error: Signal emitted with error message string when an error occurs.
19
- """
20
-
21
- on_finish: Signal = Signal(object) # dict[str, Any]
22
- on_error: Signal = Signal(str)
23
-
24
- def __init__(self) -> None:
25
- """Initialize the action table list service."""
26
- self.logger = logging.getLogger(__name__)
27
-
28
- def __enter__(self) -> "MsActionTableListService":
29
- """Context manager entry.
30
-
31
- Returns:
32
- Self for context manager use.
33
- """
34
- return self
35
-
36
- def __exit__(self, _exc_type: Any, _exc_val: Any, _exc_tb: Any) -> None:
37
- """Context manager exit."""
38
- # Disconnect service signals
39
- self.on_finish.disconnect()
40
- self.on_error.disconnect()
41
-
42
- def start(
43
- self,
44
- config_path: Optional[Path] = None,
45
- ) -> None:
46
- """List all modules with action table configurations.
47
-
48
- Args:
49
- config_path: Optional path to conson.yml. Defaults to current directory.
50
- """
51
- # Default to current directory if not specified
52
- if config_path is None:
53
- config_path = Path.cwd() / "conson.yml"
54
-
55
- # Check if config file exists
56
- if not config_path.exists():
57
- self._handle_error("Error: conson.yml not found in current directory")
58
- return
59
-
60
- # Load configuration
61
- try:
62
- from xp.models.config.conson_module_config import ConsonModuleListConfig
63
-
64
- config = ConsonModuleListConfig.from_yaml(str(config_path))
65
- except Exception as e:
66
- self.logger.error(f"Failed to load conson.yml: {e}")
67
- self._handle_error(f"Error: Failed to load conson.yml: {e}")
68
- return
69
-
70
- # Filter modules that have ms_action_table configured
71
- modules_with_msactiontable = [
72
- {
73
- "serial_number": module.serial_number,
74
- "module_type": module.module_type,
75
- "msaction_table": (
76
- 1
77
- if (
78
- module.xp20_msaction_table
79
- or module.xp24_msaction_table
80
- or module.xp33_msaction_table
81
- )
82
- else 0
83
- ),
84
- }
85
- for module in config.root
86
- ]
87
-
88
- # Prepare result
89
- result = {"modules": modules_with_msactiontable}
90
-
91
- # Emit finish signal
92
- self.on_finish.emit(result)
93
-
94
- def _handle_error(self, message: str) -> None:
95
- """Handle error and emit error signal.
96
-
97
- Args:
98
- message: Error message.
99
- """
100
- self.on_error.emit(message)
@@ -1,89 +0,0 @@
1
- """Service for showing ms action table configuration for a specific module."""
2
-
3
- import logging
4
- from pathlib import Path
5
- from typing import Any, Callable, Optional
6
-
7
- from xp.models.config.conson_module_config import ConsonModuleConfig
8
-
9
-
10
- class MsActionTableShowService:
11
- """Service for showing action table configuration for a specific module.
12
-
13
- Reads conson.yml and returns the action table configuration for the specified
14
- module serial number.
15
- """
16
-
17
- def __init__(self) -> None:
18
- """Initialize the action table show service."""
19
- self.logger = logging.getLogger(__name__)
20
- self.finish_callback: Optional[Callable[[ConsonModuleConfig], None]] = None
21
- self.error_callback: Optional[Callable[[str], None]] = None
22
-
23
- def __enter__(self) -> "MsActionTableShowService":
24
- """Context manager entry.
25
-
26
- Returns:
27
- Self for context manager use.
28
- """
29
- return self
30
-
31
- def __exit__(self, _exc_type: Any, _exc_val: Any, _exc_tb: Any) -> None:
32
- """Context manager exit."""
33
- pass
34
-
35
- def start(
36
- self,
37
- serial_number: str,
38
- finish_callback: Callable[[ConsonModuleConfig], None],
39
- error_callback: Callable[[str], None],
40
- config_path: Optional[Path] = None,
41
- ) -> None:
42
- """Show ms action table configuration for a specific module.
43
-
44
- Args:
45
- serial_number: Module serial number.
46
- finish_callback: Callback to invoke with the module configuration.
47
- error_callback: Callback to invoke on error.
48
- config_path: Optional path to conson.yml. Defaults to current directory.
49
- """
50
- self.finish_callback = finish_callback
51
- self.error_callback = error_callback
52
-
53
- # Default to current directory if not specified
54
- if config_path is None:
55
- config_path = Path.cwd() / "conson.yml"
56
-
57
- # Check if config file exists
58
- if not config_path.exists():
59
- self._handle_error("Error: conson.yml not found in current directory")
60
- return
61
-
62
- # Load configuration
63
- try:
64
- from xp.models.config.conson_module_config import ConsonModuleListConfig
65
-
66
- config = ConsonModuleListConfig.from_yaml(str(config_path))
67
- except Exception as e:
68
- self.logger.error(f"Failed to load conson.yml: {e}")
69
- self._handle_error(f"Error: Failed to load conson.yml: {e}")
70
- return
71
-
72
- # Find module
73
- module = config.find_module(serial_number)
74
- if not module:
75
- self._handle_error(f"Error: Module {serial_number} not found in conson.yml")
76
- return
77
-
78
- # Invoke callback
79
- if self.finish_callback is not None:
80
- self.finish_callback(module)
81
-
82
- def _handle_error(self, message: str) -> None:
83
- """Handle error and invoke error callback.
84
-
85
- Args:
86
- message: Error message.
87
- """
88
- if self.error_callback is not None:
89
- self.error_callback(message)