conson-xp 1.46.0__py3-none-any.whl → 1.47.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.
- {conson_xp-1.46.0.dist-info → conson_xp-1.47.0.dist-info}/METADATA +1 -1
- conson_xp-1.47.0.dist-info/RECORD +210 -0
- xp/__init__.py +3 -2
- xp/cli/commands/conbus/conbus.py +1 -1
- xp/cli/commands/conbus/conbus_actiontable_commands.py +33 -15
- xp/cli/commands/conbus/conbus_autoreport_commands.py +8 -4
- xp/cli/commands/conbus/conbus_blink_commands.py +20 -10
- xp/cli/commands/conbus/conbus_config_commands.py +2 -1
- xp/cli/commands/conbus/conbus_custom_commands.py +4 -2
- xp/cli/commands/conbus/conbus_datapoint_commands.py +10 -5
- xp/cli/commands/conbus/conbus_discover_commands.py +8 -4
- xp/cli/commands/conbus/conbus_event_commands.py +8 -4
- xp/cli/commands/conbus/conbus_export_commands.py +8 -4
- xp/cli/commands/conbus/conbus_lightlevel_commands.py +16 -8
- xp/cli/commands/conbus/conbus_linknumber_commands.py +8 -4
- xp/cli/commands/conbus/conbus_modulenumber_commands.py +8 -4
- xp/cli/commands/conbus/conbus_msactiontable_commands.py +78 -40
- xp/cli/commands/conbus/conbus_output_commands.py +16 -8
- xp/cli/commands/conbus/conbus_raw_commands.py +6 -3
- xp/cli/commands/conbus/conbus_receive_commands.py +6 -3
- xp/cli/commands/conbus/conbus_scan_commands.py +6 -3
- xp/cli/commands/file_commands.py +6 -3
- xp/cli/commands/homekit/homekit.py +4 -2
- xp/cli/commands/homekit/homekit_start_commands.py +2 -1
- xp/cli/commands/module_commands.py +8 -4
- xp/cli/commands/reverse_proxy_commands.py +8 -4
- xp/cli/commands/server/server_commands.py +6 -3
- xp/cli/commands/telegram/telegram_blink_commands.py +4 -2
- xp/cli/commands/telegram/telegram_checksum_commands.py +4 -2
- xp/cli/commands/telegram/telegram_discover_commands.py +2 -1
- xp/cli/commands/telegram/telegram_linknumber_commands.py +4 -2
- xp/cli/commands/telegram/telegram_parse_commands.py +4 -2
- xp/cli/commands/telegram/telegram_version_commands.py +2 -1
- xp/cli/commands/term/term_commands.py +4 -2
- xp/cli/main.py +2 -1
- xp/cli/utils/click_tree.py +6 -3
- xp/cli/utils/datapoint_type_choice.py +4 -2
- xp/cli/utils/decorators.py +42 -21
- xp/cli/utils/error_handlers.py +16 -8
- xp/cli/utils/formatters.py +22 -11
- xp/cli/utils/module_type_choice.py +4 -2
- xp/cli/utils/serial_number_type.py +4 -2
- xp/cli/utils/system_function_choice.py +4 -2
- xp/cli/utils/xp_module_type.py +4 -2
- xp/models/actiontable/actiontable.py +8 -8
- xp/models/actiontable/actiontable_type.py +20 -0
- xp/models/actiontable/msactiontable_xp20.py +8 -4
- xp/models/actiontable/msactiontable_xp24.py +12 -6
- xp/models/actiontable/msactiontable_xp33.py +20 -10
- xp/models/conbus/conbus.py +8 -4
- xp/models/conbus/conbus_autoreport.py +4 -2
- xp/models/conbus/conbus_blink.py +4 -2
- xp/models/conbus/conbus_client_config.py +6 -3
- xp/models/conbus/conbus_connection_status.py +4 -2
- xp/models/conbus/conbus_custom.py +4 -2
- xp/models/conbus/conbus_datapoint.py +4 -2
- xp/models/conbus/conbus_discover.py +6 -3
- xp/models/conbus/conbus_event_list.py +4 -2
- xp/models/conbus/conbus_event_raw.py +4 -2
- xp/models/conbus/conbus_export.py +2 -1
- xp/models/conbus/conbus_lightlevel.py +4 -2
- xp/models/conbus/conbus_linknumber.py +4 -2
- xp/models/conbus/conbus_logger_config.py +8 -4
- xp/models/conbus/conbus_output.py +4 -2
- xp/models/conbus/conbus_raw.py +4 -2
- xp/models/conbus/conbus_receive.py +4 -2
- xp/models/conbus/conbus_writeconfig.py +4 -2
- xp/models/config/conson_module_config.py +8 -4
- xp/models/homekit/homekit_accessory.py +4 -2
- xp/models/homekit/homekit_config.py +12 -6
- xp/models/log_entry.py +16 -8
- xp/models/protocol/conbus_protocol.py +36 -18
- xp/models/response.py +12 -8
- xp/models/telegram/action_type.py +4 -2
- xp/models/telegram/datapoint_type.py +4 -2
- xp/models/telegram/event_telegram.py +14 -7
- xp/models/telegram/event_type.py +2 -1
- xp/models/telegram/input_action_type.py +2 -1
- xp/models/telegram/input_type.py +2 -1
- xp/models/telegram/module_type.py +24 -12
- xp/models/telegram/module_type_code.py +2 -1
- xp/models/telegram/output_telegram.py +16 -10
- xp/models/telegram/reply_telegram.py +24 -13
- xp/models/telegram/system_function.py +6 -3
- xp/models/telegram/system_telegram.py +10 -6
- xp/models/telegram/telegram.py +2 -1
- xp/models/telegram/telegram_type.py +2 -1
- xp/models/telegram/timeparam_type.py +2 -1
- xp/models/term/connection_state.py +4 -2
- xp/models/term/module_state.py +2 -1
- xp/models/term/protocol_keys_config.py +6 -3
- xp/models/term/status_message.py +2 -1
- xp/models/term/telegram_display.py +2 -1
- xp/models/write_config_type.py +4 -2
- xp/services/actiontable/actiontable_serializer.py +34 -41
- xp/services/{conbus/actiontable/actiontable_download_state_machine.py → actiontable/download_state_machine.py} +13 -8
- xp/services/actiontable/msactiontable_xp20_serializer.py +77 -49
- xp/services/actiontable/msactiontable_xp24_serializer.py +78 -53
- xp/services/actiontable/msactiontable_xp33_serializer.py +39 -9
- xp/services/actiontable/serializer_protocol.py +76 -0
- xp/services/conbus/actiontable/actiontable_download_service.py +63 -29
- xp/services/conbus/actiontable/actiontable_list_service.py +17 -4
- xp/services/conbus/actiontable/actiontable_show_service.py +10 -6
- xp/services/conbus/actiontable/actiontable_upload_service.py +17 -9
- xp/services/conbus/conbus_blink_all_service.py +16 -8
- xp/services/conbus/conbus_blink_service.py +14 -7
- xp/services/conbus/conbus_custom_service.py +16 -8
- xp/services/conbus/conbus_datapoint_queryall_service.py +18 -9
- xp/services/conbus/conbus_datapoint_service.py +18 -9
- xp/services/conbus/conbus_discover_service.py +24 -13
- xp/services/conbus/conbus_event_list_service.py +11 -7
- xp/services/conbus/conbus_event_raw_service.py +18 -10
- xp/services/conbus/conbus_export_service.py +28 -14
- xp/services/conbus/conbus_output_service.py +18 -10
- xp/services/conbus/conbus_raw_service.py +16 -8
- xp/services/conbus/conbus_receive_service.py +18 -10
- xp/services/conbus/conbus_scan_service.py +18 -10
- xp/services/conbus/msactiontable/msactiontable_upload_service.py +17 -9
- xp/services/conbus/write_config_service.py +18 -9
- xp/services/homekit/homekit_cache_service.py +12 -6
- xp/services/homekit/homekit_conbus_service.py +12 -6
- xp/services/homekit/homekit_config_validator.py +34 -17
- xp/services/homekit/homekit_conson_validator.py +18 -9
- xp/services/homekit/homekit_dimminglight.py +14 -7
- xp/services/homekit/homekit_dimminglight_service.py +14 -7
- xp/services/homekit/homekit_hap_service.py +18 -9
- xp/services/homekit/homekit_lightbulb.py +10 -5
- xp/services/homekit/homekit_lightbulb_service.py +10 -5
- xp/services/homekit/homekit_module_service.py +8 -4
- xp/services/homekit/homekit_outlet.py +14 -7
- xp/services/homekit/homekit_outlet_service.py +12 -6
- xp/services/homekit/homekit_service.py +24 -12
- xp/services/log_file_service.py +16 -8
- xp/services/module_type_service.py +10 -5
- xp/services/protocol/conbus_event_protocol.py +46 -24
- xp/services/protocol/conbus_protocol.py +36 -19
- xp/services/protocol/protocol_factory.py +12 -6
- xp/services/protocol/telegram_protocol.py +12 -6
- xp/services/reverse_proxy_service.py +26 -14
- xp/services/server/base_server_service.py +42 -23
- xp/services/server/client_buffer_manager.py +12 -7
- xp/services/server/cp20_server_service.py +10 -7
- xp/services/server/device_service_factory.py +12 -8
- xp/services/server/server_service.py +18 -11
- xp/services/server/xp130_server_service.py +11 -8
- xp/services/server/xp20_server_service.py +16 -10
- xp/services/server/xp230_server_service.py +10 -7
- xp/services/server/xp24_server_service.py +22 -13
- xp/services/server/xp33_server_service.py +44 -25
- xp/services/telegram/telegram_blink_service.py +14 -8
- xp/services/telegram/telegram_checksum_service.py +12 -7
- xp/services/telegram/telegram_datapoint_service.py +14 -9
- xp/services/telegram/telegram_discover_service.py +28 -15
- xp/services/telegram/telegram_link_number_service.py +18 -10
- xp/services/telegram/telegram_output_service.py +24 -12
- xp/services/telegram/telegram_service.py +22 -11
- xp/services/telegram/telegram_version_service.py +14 -8
- xp/services/term/protocol_monitor_service.py +30 -16
- xp/services/term/state_monitor_service.py +39 -21
- xp/term/protocol.py +12 -6
- xp/term/state.py +12 -7
- xp/term/widgets/help_menu.py +6 -3
- xp/term/widgets/modules_list.py +20 -10
- xp/term/widgets/protocol_log.py +12 -6
- xp/term/widgets/status_footer.py +10 -5
- xp/utils/checksum.py +6 -3
- xp/utils/dependencies.py +25 -30
- xp/utils/event_helper.py +6 -4
- xp/utils/logging.py +6 -3
- xp/utils/serialization.py +30 -16
- xp/utils/state_machine.py +16 -9
- xp/utils/time_utils.py +6 -3
- conson_xp-1.46.0.dist-info/RECORD +0 -211
- xp/services/conbus/msactiontable/msactiontable_download_service.py +0 -275
- xp/services/conbus/msactiontable/msactiontable_list_service.py +0 -100
- xp/services/conbus/msactiontable/msactiontable_show_service.py +0 -89
- {conson_xp-1.46.0.dist-info → conson_xp-1.47.0.dist-info}/WHEEL +0 -0
- {conson_xp-1.46.0.dist-info → conson_xp-1.47.0.dist-info}/entry_points.txt +0 -0
- {conson_xp-1.46.0.dist-info → conson_xp-1.47.0.dist-info}/licenses/LICENSE +0 -0
xp/services/log_file_service.py
CHANGED
|
@@ -38,7 +38,8 @@ class LogFileService:
|
|
|
38
38
|
)
|
|
39
39
|
|
|
40
40
|
def __init__(self, telegram_service: TelegramService):
|
|
41
|
-
"""
|
|
41
|
+
"""
|
|
42
|
+
Initialize the log file service.
|
|
42
43
|
|
|
43
44
|
Args:
|
|
44
45
|
telegram_service: Telegram service for parsing telegrams.
|
|
@@ -48,7 +49,8 @@ class LogFileService:
|
|
|
48
49
|
def parse_log_file(
|
|
49
50
|
self, file_path: str, base_date: Optional[datetime] = None
|
|
50
51
|
) -> List[LogEntry]:
|
|
51
|
-
"""
|
|
52
|
+
"""
|
|
53
|
+
Parse a console bus log file into LogEntry objects.
|
|
52
54
|
|
|
53
55
|
Args:
|
|
54
56
|
file_path: Path to the log file.
|
|
@@ -79,7 +81,8 @@ class LogFileService:
|
|
|
79
81
|
def parse_log_lines(
|
|
80
82
|
self, lines: List[str], base_date: Optional[datetime] = None
|
|
81
83
|
) -> List[LogEntry]:
|
|
82
|
-
"""
|
|
84
|
+
"""
|
|
85
|
+
Parse log lines into LogEntry objects.
|
|
83
86
|
|
|
84
87
|
Args:
|
|
85
88
|
lines: List of log lines to parse.
|
|
@@ -115,7 +118,8 @@ class LogFileService:
|
|
|
115
118
|
def _parse_log_line(
|
|
116
119
|
self, line: str, line_number: int, base_date: Optional[datetime] = None
|
|
117
120
|
) -> Optional[LogEntry]:
|
|
118
|
-
"""
|
|
121
|
+
"""
|
|
122
|
+
Parse a single log line into a LogEntry.
|
|
119
123
|
|
|
120
124
|
Args:
|
|
121
125
|
line: Log line to parse.
|
|
@@ -157,7 +161,8 @@ class LogFileService:
|
|
|
157
161
|
return entry
|
|
158
162
|
|
|
159
163
|
def validate_log_format(self, file_path: str) -> bool:
|
|
160
|
-
"""
|
|
164
|
+
"""
|
|
165
|
+
Validate that a file follows the expected log format.
|
|
161
166
|
|
|
162
167
|
Args:
|
|
163
168
|
file_path: Path to the log file.
|
|
@@ -174,7 +179,8 @@ class LogFileService:
|
|
|
174
179
|
return False
|
|
175
180
|
|
|
176
181
|
def extract_telegrams(self, file_path: str) -> List[str]:
|
|
177
|
-
"""
|
|
182
|
+
"""
|
|
183
|
+
Extract all telegram strings from a log file.
|
|
178
184
|
|
|
179
185
|
Args:
|
|
180
186
|
file_path: Path to the log file.
|
|
@@ -187,7 +193,8 @@ class LogFileService:
|
|
|
187
193
|
|
|
188
194
|
@staticmethod
|
|
189
195
|
def get_file_statistics(entries: List[LogEntry]) -> Dict[str, Any]:
|
|
190
|
-
"""
|
|
196
|
+
"""
|
|
197
|
+
Generate statistics for a list of log entries.
|
|
191
198
|
|
|
192
199
|
Args:
|
|
193
200
|
entries: List of LogEntry objects.
|
|
@@ -280,7 +287,8 @@ class LogFileService:
|
|
|
280
287
|
start_time: Optional[datetime] = None,
|
|
281
288
|
end_time: Optional[datetime] = None,
|
|
282
289
|
) -> List[LogEntry]:
|
|
283
|
-
"""
|
|
290
|
+
"""
|
|
291
|
+
Filter log entries based on criteria.
|
|
284
292
|
|
|
285
293
|
Args:
|
|
286
294
|
entries: List of LogEntry objects to filter.
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
"""
|
|
1
|
+
"""
|
|
2
|
+
Module Type Service for XP module management.
|
|
2
3
|
|
|
3
|
-
This module provides lookup, validation, and search functionality for XP system module
|
|
4
|
+
This module provides lookup, validation, and search functionality for XP system module
|
|
5
|
+
types.
|
|
4
6
|
"""
|
|
5
7
|
|
|
6
8
|
from typing import Dict, List, Optional, Union
|
|
@@ -199,7 +201,8 @@ class ModuleTypeService:
|
|
|
199
201
|
|
|
200
202
|
@staticmethod
|
|
201
203
|
def _format_module_summary(module_type: ModuleType) -> str:
|
|
202
|
-
"""
|
|
204
|
+
"""
|
|
205
|
+
Format a single module type for display.
|
|
203
206
|
|
|
204
207
|
Args:
|
|
205
208
|
module_type: The module type to format.
|
|
@@ -226,7 +229,8 @@ class ModuleTypeService:
|
|
|
226
229
|
|
|
227
230
|
@staticmethod
|
|
228
231
|
def _format_all_modules() -> str:
|
|
229
|
-
"""
|
|
232
|
+
"""
|
|
233
|
+
Format all modules in a simple list.
|
|
230
234
|
|
|
231
235
|
Returns:
|
|
232
236
|
Formatted string with all modules.
|
|
@@ -241,7 +245,8 @@ class ModuleTypeService:
|
|
|
241
245
|
|
|
242
246
|
@staticmethod
|
|
243
247
|
def _format_modules_by_category() -> str:
|
|
244
|
-
"""
|
|
248
|
+
"""
|
|
249
|
+
Format modules grouped by category.
|
|
245
250
|
|
|
246
251
|
Returns:
|
|
247
252
|
Formatted string with modules grouped by category.
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
"""
|
|
1
|
+
"""
|
|
2
|
+
Conbus Event Protocol for XP telegram communication.
|
|
2
3
|
|
|
3
4
|
This module implements the Twisted protocol for Conbus communication.
|
|
4
5
|
"""
|
|
@@ -34,7 +35,8 @@ CHUNK_HEADER_LENGTH = 2 # data_value format: 2-char counter + actiontable chunk
|
|
|
34
35
|
|
|
35
36
|
|
|
36
37
|
class ConbusEventProtocol(protocol.Protocol, protocol.ClientFactory):
|
|
37
|
-
"""
|
|
38
|
+
"""
|
|
39
|
+
Twisted protocol for XP telegram communication.
|
|
38
40
|
|
|
39
41
|
Attributes:
|
|
40
42
|
buffer: Buffer for incoming telegram data.
|
|
@@ -95,7 +97,8 @@ class ConbusEventProtocol(protocol.Protocol, protocol.ClientFactory):
|
|
|
95
97
|
reactor: PosixReactorBase,
|
|
96
98
|
telegram_service: TelegramService,
|
|
97
99
|
) -> None:
|
|
98
|
-
"""
|
|
100
|
+
"""
|
|
101
|
+
Initialize ConbusProtocol.
|
|
99
102
|
|
|
100
103
|
Args:
|
|
101
104
|
cli_config: Configuration for Conbus client connection.
|
|
@@ -111,10 +114,11 @@ class ConbusEventProtocol(protocol.Protocol, protocol.ClientFactory):
|
|
|
111
114
|
self.telegram_service = telegram_service
|
|
112
115
|
|
|
113
116
|
def connectionMade(self) -> None:
|
|
114
|
-
"""
|
|
117
|
+
"""
|
|
118
|
+
Handle connection established event.
|
|
115
119
|
|
|
116
|
-
Called when TCP connection is successfully established.
|
|
117
|
-
|
|
120
|
+
Called when TCP connection is successfully established. Starts inactivity
|
|
121
|
+
timeout monitoring.
|
|
118
122
|
"""
|
|
119
123
|
self.logger.debug("connectionMade")
|
|
120
124
|
self.on_connection_made.emit()
|
|
@@ -123,7 +127,8 @@ class ConbusEventProtocol(protocol.Protocol, protocol.ClientFactory):
|
|
|
123
127
|
self._reset_timeout()
|
|
124
128
|
|
|
125
129
|
def wait(self, wait_timeout: Optional[float] = None) -> None:
|
|
126
|
-
"""
|
|
130
|
+
"""
|
|
131
|
+
Wait for incoming telegrams with optional timeout override.
|
|
127
132
|
|
|
128
133
|
Args:
|
|
129
134
|
wait_timeout: Optional timeout in seconds to override default.
|
|
@@ -133,7 +138,8 @@ class ConbusEventProtocol(protocol.Protocol, protocol.ClientFactory):
|
|
|
133
138
|
self._reset_timeout()
|
|
134
139
|
|
|
135
140
|
def dataReceived(self, data: bytes) -> None:
|
|
136
|
-
"""
|
|
141
|
+
"""
|
|
142
|
+
Handle received data from TCP connection.
|
|
137
143
|
|
|
138
144
|
Parses incoming telegram frames and dispatches events.
|
|
139
145
|
|
|
@@ -193,7 +199,8 @@ class ConbusEventProtocol(protocol.Protocol, protocol.ClientFactory):
|
|
|
193
199
|
self.emit_telegram_received(telegram_received)
|
|
194
200
|
|
|
195
201
|
def emit_telegram_received(self, telegram_received: TelegramReceivedEvent) -> None:
|
|
196
|
-
"""
|
|
202
|
+
"""
|
|
203
|
+
Handle telegram received event.
|
|
197
204
|
|
|
198
205
|
Args:
|
|
199
206
|
telegram_received: The telegram received event.
|
|
@@ -232,7 +239,8 @@ class ConbusEventProtocol(protocol.Protocol, protocol.ClientFactory):
|
|
|
232
239
|
return
|
|
233
240
|
|
|
234
241
|
def sendFrame(self, data: bytes) -> None:
|
|
235
|
-
"""
|
|
242
|
+
"""
|
|
243
|
+
Send telegram frame.
|
|
236
244
|
|
|
237
245
|
Args:
|
|
238
246
|
data: Raw telegram payload (without checksum/framing).
|
|
@@ -261,7 +269,8 @@ class ConbusEventProtocol(protocol.Protocol, protocol.ClientFactory):
|
|
|
261
269
|
system_function: SystemFunction,
|
|
262
270
|
data_value: str,
|
|
263
271
|
) -> None:
|
|
264
|
-
"""
|
|
272
|
+
"""
|
|
273
|
+
Send telegram with specified parameters.
|
|
265
274
|
|
|
266
275
|
Args:
|
|
267
276
|
telegram_type: Type of telegram to send.
|
|
@@ -280,7 +289,8 @@ class ConbusEventProtocol(protocol.Protocol, protocol.ClientFactory):
|
|
|
280
289
|
def send_event_telegram(
|
|
281
290
|
self, module_type_code: ModuleTypeCode, link_number: int, input_number: int
|
|
282
291
|
) -> None:
|
|
283
|
-
"""
|
|
292
|
+
"""
|
|
293
|
+
Send telegram with specified parameters.
|
|
284
294
|
|
|
285
295
|
Args:
|
|
286
296
|
module_type_code: Type code of module.
|
|
@@ -293,7 +303,8 @@ class ConbusEventProtocol(protocol.Protocol, protocol.ClientFactory):
|
|
|
293
303
|
self.send_raw_telegram(payload)
|
|
294
304
|
|
|
295
305
|
def send_raw_telegram(self, payload: str) -> None:
|
|
296
|
-
"""
|
|
306
|
+
"""
|
|
307
|
+
Send telegram with specified parameters.
|
|
297
308
|
|
|
298
309
|
Args:
|
|
299
310
|
payload: Telegram to send.
|
|
@@ -302,7 +313,8 @@ class ConbusEventProtocol(protocol.Protocol, protocol.ClientFactory):
|
|
|
302
313
|
self.call_later(0.0, self.start_queue_manager)
|
|
303
314
|
|
|
304
315
|
def send_error_status_query(self, serial_number: str) -> None:
|
|
305
|
-
"""
|
|
316
|
+
"""
|
|
317
|
+
Send error status query telegram.
|
|
306
318
|
|
|
307
319
|
Args:
|
|
308
320
|
serial_number: Device serial number.
|
|
@@ -315,7 +327,8 @@ class ConbusEventProtocol(protocol.Protocol, protocol.ClientFactory):
|
|
|
315
327
|
)
|
|
316
328
|
|
|
317
329
|
def send_download_request(self, serial_number: str) -> None:
|
|
318
|
-
"""
|
|
330
|
+
"""
|
|
331
|
+
Send download request telegram.
|
|
319
332
|
|
|
320
333
|
Args:
|
|
321
334
|
serial_number: Device serial number.
|
|
@@ -328,7 +341,8 @@ class ConbusEventProtocol(protocol.Protocol, protocol.ClientFactory):
|
|
|
328
341
|
)
|
|
329
342
|
|
|
330
343
|
def send_ack(self, serial_number: str) -> None:
|
|
331
|
-
"""
|
|
344
|
+
"""
|
|
345
|
+
Send ACK telegram.
|
|
332
346
|
|
|
333
347
|
Args:
|
|
334
348
|
serial_number: Device serial number.
|
|
@@ -347,7 +361,8 @@ class ConbusEventProtocol(protocol.Protocol, protocol.ClientFactory):
|
|
|
347
361
|
*args: object,
|
|
348
362
|
**kw: object,
|
|
349
363
|
) -> DelayedCall:
|
|
350
|
-
"""
|
|
364
|
+
"""
|
|
365
|
+
Schedule a callable to be called later.
|
|
351
366
|
|
|
352
367
|
Args:
|
|
353
368
|
delay: Delay in seconds before calling.
|
|
@@ -361,7 +376,8 @@ class ConbusEventProtocol(protocol.Protocol, protocol.ClientFactory):
|
|
|
361
376
|
return self._reactor.callLater(delay, callable_action, *args, **kw)
|
|
362
377
|
|
|
363
378
|
def buildProtocol(self, addr: IAddress) -> protocol.Protocol:
|
|
364
|
-
"""
|
|
379
|
+
"""
|
|
380
|
+
Build protocol instance for connection.
|
|
365
381
|
|
|
366
382
|
Args:
|
|
367
383
|
addr: Address of the connection.
|
|
@@ -373,7 +389,8 @@ class ConbusEventProtocol(protocol.Protocol, protocol.ClientFactory):
|
|
|
373
389
|
return self
|
|
374
390
|
|
|
375
391
|
def clientConnectionFailed(self, connector: IConnector, reason: Failure) -> None:
|
|
376
|
-
"""
|
|
392
|
+
"""
|
|
393
|
+
Handle client connection failure.
|
|
377
394
|
|
|
378
395
|
Args:
|
|
379
396
|
connector: Connection connector instance.
|
|
@@ -385,7 +402,8 @@ class ConbusEventProtocol(protocol.Protocol, protocol.ClientFactory):
|
|
|
385
402
|
self._cancel_timeout()
|
|
386
403
|
|
|
387
404
|
def clientConnectionLost(self, connector: IConnector, reason: Failure) -> None:
|
|
388
|
-
"""
|
|
405
|
+
"""
|
|
406
|
+
Handle client connection lost event.
|
|
389
407
|
|
|
390
408
|
Args:
|
|
391
409
|
connector: Connection connector instance.
|
|
@@ -401,7 +419,8 @@ class ConbusEventProtocol(protocol.Protocol, protocol.ClientFactory):
|
|
|
401
419
|
self.on_timeout.emit()
|
|
402
420
|
|
|
403
421
|
def connection_failed(self, reason: Failure) -> None:
|
|
404
|
-
"""
|
|
422
|
+
"""
|
|
423
|
+
Handle connection failure.
|
|
405
424
|
|
|
406
425
|
Args:
|
|
407
426
|
reason: Failure reason details.
|
|
@@ -436,7 +455,8 @@ class ConbusEventProtocol(protocol.Protocol, protocol.ClientFactory):
|
|
|
436
455
|
self.logger.debug(f"Reactor stop failed (likely already stopped): {e}")
|
|
437
456
|
|
|
438
457
|
def connect(self) -> None:
|
|
439
|
-
"""
|
|
458
|
+
"""
|
|
459
|
+
Connect to TCP server.
|
|
440
460
|
|
|
441
461
|
Automatically detects and integrates with running asyncio event loop if present.
|
|
442
462
|
"""
|
|
@@ -494,7 +514,8 @@ class ConbusEventProtocol(protocol.Protocol, protocol.ClientFactory):
|
|
|
494
514
|
self.call_later(later, self.process_telegram_queue)
|
|
495
515
|
|
|
496
516
|
def set_event_loop(self, event_loop: asyncio.AbstractEventLoop) -> None:
|
|
497
|
-
"""
|
|
517
|
+
"""
|
|
518
|
+
Change the event loop.
|
|
498
519
|
|
|
499
520
|
Args:
|
|
500
521
|
event_loop: the event loop instance.
|
|
@@ -511,7 +532,8 @@ class ConbusEventProtocol(protocol.Protocol, protocol.ClientFactory):
|
|
|
511
532
|
self.logger.info("Set reactor to running state")
|
|
512
533
|
|
|
513
534
|
def __enter__(self) -> "ConbusEventProtocol":
|
|
514
|
-
"""
|
|
535
|
+
"""
|
|
536
|
+
Enter context manager.
|
|
515
537
|
|
|
516
538
|
Returns:
|
|
517
539
|
Self for context management.
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
"""
|
|
1
|
+
"""
|
|
2
|
+
Conbus Protocol for XP telegram communication.
|
|
2
3
|
|
|
3
4
|
This module implements the Twisted protocol for Conbus communication.
|
|
4
5
|
"""
|
|
@@ -22,7 +23,8 @@ from xp.utils import calculate_checksum
|
|
|
22
23
|
|
|
23
24
|
|
|
24
25
|
class ConbusProtocol(protocol.Protocol, protocol.ClientFactory):
|
|
25
|
-
"""
|
|
26
|
+
"""
|
|
27
|
+
Twisted protocol for XP telegram communication.
|
|
26
28
|
|
|
27
29
|
Attributes:
|
|
28
30
|
buffer: Buffer for incoming telegram data.
|
|
@@ -40,7 +42,8 @@ class ConbusProtocol(protocol.Protocol, protocol.ClientFactory):
|
|
|
40
42
|
cli_config: ConbusClientConfig,
|
|
41
43
|
reactor: PosixReactorBase,
|
|
42
44
|
) -> None:
|
|
43
|
-
"""
|
|
45
|
+
"""
|
|
46
|
+
Initialize ConbusProtocol.
|
|
44
47
|
|
|
45
48
|
Args:
|
|
46
49
|
cli_config: Configuration for Conbus client connection.
|
|
@@ -54,10 +57,11 @@ class ConbusProtocol(protocol.Protocol, protocol.ClientFactory):
|
|
|
54
57
|
self.timeout_call: Optional[DelayedCall] = None
|
|
55
58
|
|
|
56
59
|
def connectionMade(self) -> None:
|
|
57
|
-
"""
|
|
60
|
+
"""
|
|
61
|
+
Handle connection established event.
|
|
58
62
|
|
|
59
|
-
Called when TCP connection is successfully established.
|
|
60
|
-
|
|
63
|
+
Called when TCP connection is successfully established. Starts inactivity
|
|
64
|
+
timeout monitoring.
|
|
61
65
|
"""
|
|
62
66
|
self.logger.debug("connectionMade")
|
|
63
67
|
self.connection_established()
|
|
@@ -65,7 +69,8 @@ class ConbusProtocol(protocol.Protocol, protocol.ClientFactory):
|
|
|
65
69
|
self._reset_timeout()
|
|
66
70
|
|
|
67
71
|
def dataReceived(self, data: bytes) -> None:
|
|
68
|
-
"""
|
|
72
|
+
"""
|
|
73
|
+
Handle received data from TCP connection.
|
|
69
74
|
|
|
70
75
|
Parses incoming telegram frames and dispatches events.
|
|
71
76
|
|
|
@@ -124,7 +129,8 @@ class ConbusProtocol(protocol.Protocol, protocol.ClientFactory):
|
|
|
124
129
|
self.telegram_received(telegram_received)
|
|
125
130
|
|
|
126
131
|
def sendFrame(self, data: bytes) -> None:
|
|
127
|
-
"""
|
|
132
|
+
"""
|
|
133
|
+
Send telegram frame.
|
|
128
134
|
|
|
129
135
|
Args:
|
|
130
136
|
data: Raw telegram payload (without checksum/framing).
|
|
@@ -153,7 +159,8 @@ class ConbusProtocol(protocol.Protocol, protocol.ClientFactory):
|
|
|
153
159
|
system_function: SystemFunction,
|
|
154
160
|
data_value: str,
|
|
155
161
|
) -> None:
|
|
156
|
-
"""
|
|
162
|
+
"""
|
|
163
|
+
Send telegram with specified parameters.
|
|
157
164
|
|
|
158
165
|
Args:
|
|
159
166
|
telegram_type: Type of telegram to send.
|
|
@@ -170,7 +177,8 @@ class ConbusProtocol(protocol.Protocol, protocol.ClientFactory):
|
|
|
170
177
|
self.sendFrame(payload.encode())
|
|
171
178
|
|
|
172
179
|
def buildProtocol(self, addr: IAddress) -> protocol.Protocol:
|
|
173
|
-
"""
|
|
180
|
+
"""
|
|
181
|
+
Build protocol instance for connection.
|
|
174
182
|
|
|
175
183
|
Args:
|
|
176
184
|
addr: Address of the connection.
|
|
@@ -182,7 +190,8 @@ class ConbusProtocol(protocol.Protocol, protocol.ClientFactory):
|
|
|
182
190
|
return self
|
|
183
191
|
|
|
184
192
|
def clientConnectionFailed(self, connector: IConnector, reason: Failure) -> None:
|
|
185
|
-
"""
|
|
193
|
+
"""
|
|
194
|
+
Handle client connection failure.
|
|
186
195
|
|
|
187
196
|
Args:
|
|
188
197
|
connector: Connection connector instance.
|
|
@@ -194,7 +203,8 @@ class ConbusProtocol(protocol.Protocol, protocol.ClientFactory):
|
|
|
194
203
|
self._stop_reactor()
|
|
195
204
|
|
|
196
205
|
def clientConnectionLost(self, connector: IConnector, reason: Failure) -> None:
|
|
197
|
-
"""
|
|
206
|
+
"""
|
|
207
|
+
Handle client connection lost event.
|
|
198
208
|
|
|
199
209
|
Args:
|
|
200
210
|
connector: Connection connector instance.
|
|
@@ -206,7 +216,8 @@ class ConbusProtocol(protocol.Protocol, protocol.ClientFactory):
|
|
|
206
216
|
self._stop_reactor()
|
|
207
217
|
|
|
208
218
|
def timeout(self) -> bool:
|
|
209
|
-
"""
|
|
219
|
+
"""
|
|
220
|
+
Handle timeout event.
|
|
210
221
|
|
|
211
222
|
Returns:
|
|
212
223
|
True to continue waiting for next timeout, False to stop.
|
|
@@ -216,7 +227,8 @@ class ConbusProtocol(protocol.Protocol, protocol.ClientFactory):
|
|
|
216
227
|
return False
|
|
217
228
|
|
|
218
229
|
def connection_failed(self, reason: Failure) -> None:
|
|
219
|
-
"""
|
|
230
|
+
"""
|
|
231
|
+
Handle connection failure.
|
|
220
232
|
|
|
221
233
|
Args:
|
|
222
234
|
reason: Failure reason details.
|
|
@@ -262,7 +274,8 @@ class ConbusProtocol(protocol.Protocol, protocol.ClientFactory):
|
|
|
262
274
|
self.reactor.run()
|
|
263
275
|
|
|
264
276
|
def __enter__(self) -> "ConbusProtocol":
|
|
265
|
-
"""
|
|
277
|
+
"""
|
|
278
|
+
Enter context manager.
|
|
266
279
|
|
|
267
280
|
Returns:
|
|
268
281
|
Self for context management.
|
|
@@ -282,7 +295,8 @@ class ConbusProtocol(protocol.Protocol, protocol.ClientFactory):
|
|
|
282
295
|
"""Override methods."""
|
|
283
296
|
|
|
284
297
|
def telegram_sent(self, telegram_sent: str) -> None:
|
|
285
|
-
"""
|
|
298
|
+
"""
|
|
299
|
+
Override callback when telegram has been sent.
|
|
286
300
|
|
|
287
301
|
Args:
|
|
288
302
|
telegram_sent: The telegram that was sent.
|
|
@@ -290,7 +304,8 @@ class ConbusProtocol(protocol.Protocol, protocol.ClientFactory):
|
|
|
290
304
|
pass
|
|
291
305
|
|
|
292
306
|
def telegram_received(self, telegram_received: TelegramReceivedEvent) -> None:
|
|
293
|
-
"""
|
|
307
|
+
"""
|
|
308
|
+
Override callback when telegram is received.
|
|
294
309
|
|
|
295
310
|
Args:
|
|
296
311
|
telegram_received: Event containing received telegram details.
|
|
@@ -302,7 +317,8 @@ class ConbusProtocol(protocol.Protocol, protocol.ClientFactory):
|
|
|
302
317
|
pass
|
|
303
318
|
|
|
304
319
|
def connection_lost(self, reason: Failure) -> None:
|
|
305
|
-
"""
|
|
320
|
+
"""
|
|
321
|
+
Override callback when connection is lost.
|
|
306
322
|
|
|
307
323
|
Args:
|
|
308
324
|
reason: Reason for connection loss.
|
|
@@ -310,7 +326,8 @@ class ConbusProtocol(protocol.Protocol, protocol.ClientFactory):
|
|
|
310
326
|
pass
|
|
311
327
|
|
|
312
328
|
def failed(self, message: str) -> None:
|
|
313
|
-
"""
|
|
329
|
+
"""
|
|
330
|
+
Override callback when connection failed.
|
|
314
331
|
|
|
315
332
|
Args:
|
|
316
333
|
message: Error message describing the failure.
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
"""
|
|
1
|
+
"""
|
|
2
|
+
Protocol Factory for Twisted protocol creation.
|
|
2
3
|
|
|
3
4
|
This module provides factory classes for protocol instantiation.
|
|
4
5
|
"""
|
|
@@ -18,7 +19,8 @@ from xp.services.protocol import TelegramProtocol
|
|
|
18
19
|
|
|
19
20
|
|
|
20
21
|
class TelegramFactory(protocol.ClientFactory):
|
|
21
|
-
"""
|
|
22
|
+
"""
|
|
23
|
+
Factory for creating Telegram protocol instances.
|
|
22
24
|
|
|
23
25
|
Attributes:
|
|
24
26
|
event_bus: Event bus for dispatching protocol events.
|
|
@@ -33,7 +35,8 @@ class TelegramFactory(protocol.ClientFactory):
|
|
|
33
35
|
telegram_protocol: TelegramProtocol,
|
|
34
36
|
connector: IConnector,
|
|
35
37
|
) -> None:
|
|
36
|
-
"""
|
|
38
|
+
"""
|
|
39
|
+
Initialize TelegramFactory.
|
|
37
40
|
|
|
38
41
|
Args:
|
|
39
42
|
event_bus: Event bus for protocol events.
|
|
@@ -46,7 +49,8 @@ class TelegramFactory(protocol.ClientFactory):
|
|
|
46
49
|
self.logger = logging.getLogger(__name__)
|
|
47
50
|
|
|
48
51
|
def buildProtocol(self, addr: IAddress) -> TelegramProtocol:
|
|
49
|
-
"""
|
|
52
|
+
"""
|
|
53
|
+
Build protocol instance for connection.
|
|
50
54
|
|
|
51
55
|
Args:
|
|
52
56
|
addr: Address of the connection.
|
|
@@ -58,7 +62,8 @@ class TelegramFactory(protocol.ClientFactory):
|
|
|
58
62
|
return self.telegram_protocol
|
|
59
63
|
|
|
60
64
|
def clientConnectionFailed(self, connector: IConnector, reason: Failure) -> None:
|
|
61
|
-
"""
|
|
65
|
+
"""
|
|
66
|
+
Handle connection failure event.
|
|
62
67
|
|
|
63
68
|
Args:
|
|
64
69
|
connector: Connection connector instance.
|
|
@@ -68,7 +73,8 @@ class TelegramFactory(protocol.ClientFactory):
|
|
|
68
73
|
self.connector.stop()
|
|
69
74
|
|
|
70
75
|
def clientConnectionLost(self, connector: IConnector, reason: Failure) -> None:
|
|
71
|
-
"""
|
|
76
|
+
"""
|
|
77
|
+
Handle connection lost event.
|
|
72
78
|
|
|
73
79
|
Args:
|
|
74
80
|
connector: Connection connector instance.
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
"""
|
|
1
|
+
"""
|
|
2
|
+
Telegram Protocol for XP telegram communication.
|
|
2
3
|
|
|
3
4
|
This module provides the protocol implementation for telegram-based communication.
|
|
4
5
|
"""
|
|
@@ -20,7 +21,8 @@ from xp.utils import calculate_checksum
|
|
|
20
21
|
|
|
21
22
|
|
|
22
23
|
class TelegramProtocol(protocol.Protocol):
|
|
23
|
-
"""
|
|
24
|
+
"""
|
|
25
|
+
Twisted protocol for XP telegram communication with built-in debouncing.
|
|
24
26
|
|
|
25
27
|
Automatically deduplicates identical telegram frames sent within a
|
|
26
28
|
configurable time window (default 50ms).
|
|
@@ -38,7 +40,8 @@ class TelegramProtocol(protocol.Protocol):
|
|
|
38
40
|
event_bus: EventBus
|
|
39
41
|
|
|
40
42
|
def __init__(self, event_bus: EventBus, debounce_ms: int = 50) -> None:
|
|
41
|
-
"""
|
|
43
|
+
"""
|
|
44
|
+
Initialize TelegramProtocol.
|
|
42
45
|
|
|
43
46
|
Args:
|
|
44
47
|
event_bus: Event bus for dispatching protocol events.
|
|
@@ -64,7 +67,8 @@ class TelegramProtocol(protocol.Protocol):
|
|
|
64
67
|
self.logger.error(f"Error scheduling async handler: {e}", exc_info=True)
|
|
65
68
|
|
|
66
69
|
def _on_task_done(self, task: asyncio.Task) -> None:
|
|
67
|
-
"""
|
|
70
|
+
"""
|
|
71
|
+
Handle async task completion.
|
|
68
72
|
|
|
69
73
|
Args:
|
|
70
74
|
task: Completed async task.
|
|
@@ -92,7 +96,8 @@ class TelegramProtocol(protocol.Protocol):
|
|
|
92
96
|
)
|
|
93
97
|
|
|
94
98
|
def dataReceived(self, data: bytes) -> None:
|
|
95
|
-
"""
|
|
99
|
+
"""
|
|
100
|
+
Handle received data from Twisted.
|
|
96
101
|
|
|
97
102
|
Args:
|
|
98
103
|
data: Raw bytes received from connection.
|
|
@@ -164,7 +169,8 @@ class TelegramProtocol(protocol.Protocol):
|
|
|
164
169
|
)
|
|
165
170
|
|
|
166
171
|
def sendFrame(self, data: bytes) -> None:
|
|
167
|
-
"""
|
|
172
|
+
"""
|
|
173
|
+
Send telegram frame.
|
|
168
174
|
|
|
169
175
|
Args:
|
|
170
176
|
data: Raw telegram payload (without checksum/framing).
|