conson-xp 1.50.0__py3-none-any.whl → 1.50.1__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.50.0.dist-info → conson_xp-1.50.1.dist-info}/METADATA +2 -1
- {conson_xp-1.50.0.dist-info → conson_xp-1.50.1.dist-info}/RECORD +10 -9
- xp/__init__.py +1 -1
- xp/cli/commands/conbus/conbus_export_commands.py +86 -0
- xp/services/conbus/conbus_export_actiontable_service.py +308 -0
- xp/services/conbus/conbus_export_service.py +5 -2
- xp/utils/dependencies.py +2 -1
- {conson_xp-1.50.0.dist-info → conson_xp-1.50.1.dist-info}/WHEEL +0 -0
- {conson_xp-1.50.0.dist-info → conson_xp-1.50.1.dist-info}/entry_points.txt +0 -0
- {conson_xp-1.50.0.dist-info → conson_xp-1.50.1.dist-info}/licenses/LICENSE +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: conson-xp
|
|
3
|
-
Version: 1.50.
|
|
3
|
+
Version: 1.50.1
|
|
4
4
|
Summary: XP Protocol Communication Tools
|
|
5
5
|
Author-Email: ldvchosal <ldvchosal@github.com>
|
|
6
6
|
License: MIT License
|
|
@@ -353,6 +353,7 @@ xp conbus event raw
|
|
|
353
353
|
|
|
354
354
|
|
|
355
355
|
xp conbus export
|
|
356
|
+
xp conbus export actiontable
|
|
356
357
|
xp conbus export config
|
|
357
358
|
|
|
358
359
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
conson_xp-1.50.
|
|
2
|
-
conson_xp-1.50.
|
|
3
|
-
conson_xp-1.50.
|
|
4
|
-
conson_xp-1.50.
|
|
5
|
-
xp/__init__.py,sha256=
|
|
1
|
+
conson_xp-1.50.1.dist-info/METADATA,sha256=bCbYqnE9XZK73a4laFt68XxyWDTPC-MlmxJa99Y7JTc,11432
|
|
2
|
+
conson_xp-1.50.1.dist-info/WHEEL,sha256=tsUv_t7BDeJeRHaSrczbGeuK-TtDpGsWi_JfpzD255I,90
|
|
3
|
+
conson_xp-1.50.1.dist-info/entry_points.txt,sha256=1OcdIcDM1hz3ljCXgybaPUh1IOFEwkaTgLIW9u9zGeg,50
|
|
4
|
+
conson_xp-1.50.1.dist-info/licenses/LICENSE,sha256=rxj6woMM-r3YCyGq_UHFtbh7kHTAJgrccH6O-33IDE4,1419
|
|
5
|
+
xp/__init__.py,sha256=hEOsOLZ2VP2s9c4Fqe0rpmfu56_wnujnc7Wf3f0xDGI,182
|
|
6
6
|
xp/cli/__init__.py,sha256=QjnKB1KaI2aIyKlzrnvCwfbBuUj8HNgwNMvNJVQofbI,81
|
|
7
7
|
xp/cli/__main__.py,sha256=l2iKwMdat5rTGd3JWs-uGksnYYDDffp_Npz05QdKEeU,117
|
|
8
8
|
xp/cli/commands/__init__.py,sha256=G7A1KFRSV0CEeDTqr_khu-K9_sc01CTI2KSfkFcaBRM,4949
|
|
@@ -16,7 +16,7 @@ xp/cli/commands/conbus/conbus_custom_commands.py,sha256=TqWo45yqEp_ezmKZ0tymQ0C4
|
|
|
16
16
|
xp/cli/commands/conbus/conbus_datapoint_commands.py,sha256=uYsvi37vl2od2XJB0semAF0sH3UrRWTt_qHnBmUBR-w,3788
|
|
17
17
|
xp/cli/commands/conbus/conbus_discover_commands.py,sha256=gSK5Y4lespNKFNgGtp7VkqStGe4fWxDNNfyPPuJiwXQ,1931
|
|
18
18
|
xp/cli/commands/conbus/conbus_event_commands.py,sha256=faaSGRNtJCttk-0VO5Z4m4Zz37aOsSgmbuzWbTOUZIQ,3103
|
|
19
|
-
xp/cli/commands/conbus/conbus_export_commands.py,sha256
|
|
19
|
+
xp/cli/commands/conbus/conbus_export_commands.py,sha256=epfoIC1C32IT7SMVxolUDm1xm2q7hz_kvs7Jct4W9FQ,5819
|
|
20
20
|
xp/cli/commands/conbus/conbus_lightlevel_commands.py,sha256=WH4ZQHxSbquPlAqd0uRxq8VR-sO4_AnfseMqaoPoGoA,7092
|
|
21
21
|
xp/cli/commands/conbus/conbus_linknumber_commands.py,sha256=3bkik8nHXY89XfzeUnKWmvKA70r4qJJ79j8FfLL4sL0,3556
|
|
22
22
|
xp/cli/commands/conbus/conbus_modulenumber_commands.py,sha256=fOIO0f85iDJBfGnRCEN8zK6j4i43uuF_9YKQc_nQ39A,3628
|
|
@@ -135,7 +135,8 @@ xp/services/conbus/conbus_datapoint_service.py,sha256=WBQC42-6xuPWhMKKRtHtRzwEmV
|
|
|
135
135
|
xp/services/conbus/conbus_discover_service.py,sha256=mvqjHFMmEkQjHD9YDIk9gE8MowPMkOIJRmyjX96G5pw,12868
|
|
136
136
|
xp/services/conbus/conbus_event_list_service.py,sha256=-jl3WHpyidbh-h4NMK2gERqu48mTNFD6rpPo2EyGxeg,3641
|
|
137
137
|
xp/services/conbus/conbus_event_raw_service.py,sha256=viXuEXw165-RytdqC76wQShJLD7Yd0rtURxWZZ8hyKA,7060
|
|
138
|
-
xp/services/conbus/
|
|
138
|
+
xp/services/conbus/conbus_export_actiontable_service.py,sha256=_2bxmDVSpkGtepuQVbdYX2nwEnSm91GX9P9UzB_INDQ,11043
|
|
139
|
+
xp/services/conbus/conbus_export_service.py,sha256=RP8nADTIs4FGUf_BFLRZMtEJZdXV94zg3QrlWaDnhKA,17536
|
|
139
140
|
xp/services/conbus/conbus_output_service.py,sha256=e57bRkLgPnJuB8hkllNh0kgGkjPt9IK75tuBxd_bOkE,9361
|
|
140
141
|
xp/services/conbus/conbus_raw_service.py,sha256=OQuV521VOQraf2PGF2B9868vh7sDgmfc19YebrkZnyw,5844
|
|
141
142
|
xp/services/conbus/conbus_receive_service.py,sha256=TFf3W65brGsy6QZICpIs0Xy9bgqyL1vgQuhS_eHuIZs,5416
|
|
@@ -197,10 +198,10 @@ xp/term/widgets/protocol_log.py,sha256=E68QmSMpOFrvrPTo_gOQVfyiDqY5c_y8fkNKnQw6V
|
|
|
197
198
|
xp/term/widgets/status_footer.py,sha256=YYAT0431p6jmrzzpVgaPhu7yGkRroWGv4e99t2XlkHI,3297
|
|
198
199
|
xp/utils/__init__.py,sha256=_avMF_UOkfR3tNeDIPqQ5odmbq5raKkaq1rZ9Cn1CJs,332
|
|
199
200
|
xp/utils/checksum.py,sha256=Px1S3dFGA-_plavBxrq3IqmprNlgtNDunE3whg6Otwg,1722
|
|
200
|
-
xp/utils/dependencies.py,sha256=
|
|
201
|
+
xp/utils/dependencies.py,sha256=dlSuKVmuA7AZlqINrQkZxfHuU8mzSHDZnMRRDzqjRAI,24067
|
|
201
202
|
xp/utils/event_helper.py,sha256=zD0K3TPfGEThU9vUNlDtglTai3Cmm30727iwjDZy6Dk,1007
|
|
202
203
|
xp/utils/logging.py,sha256=wJ1d-yg97NiZUrt2F8iDMcmnHVwC-PErcI-7dpyiRDc,3777
|
|
203
204
|
xp/utils/serialization.py,sha256=TS1OwpTOemSvXsCGw3js4JkYYFEqkzrPe8V9QYQefdw,4684
|
|
204
205
|
xp/utils/state_machine.py,sha256=W9AY4ntRZnFeHAa5d43hm37j53uJPlqkRvWTPiBhJ_0,2464
|
|
205
206
|
xp/utils/time_utils.py,sha256=K17godWpL18VEypbTlvNOEDG6R3huYnf29yjkcnwRpU,3796
|
|
206
|
-
conson_xp-1.50.
|
|
207
|
+
conson_xp-1.50.1.dist-info/RECORD,,
|
xp/__init__.py
CHANGED
|
@@ -6,8 +6,12 @@ import click
|
|
|
6
6
|
|
|
7
7
|
from xp.cli.commands.conbus.conbus import conbus_export
|
|
8
8
|
from xp.cli.utils.decorators import connection_command
|
|
9
|
+
from xp.models.actiontable.actiontable_type import ActionTableType
|
|
9
10
|
from xp.models.conbus.conbus_export import ConbusExportResponse
|
|
10
11
|
from xp.models.config.conson_module_config import ConsonModuleConfig
|
|
12
|
+
from xp.services.conbus.conbus_export_actiontable_service import (
|
|
13
|
+
ConbusActiontableExportService,
|
|
14
|
+
)
|
|
11
15
|
from xp.services.conbus.conbus_export_service import ConbusExportService
|
|
12
16
|
|
|
13
17
|
|
|
@@ -91,3 +95,85 @@ def export_conbus_config(ctx: click.Context) -> None:
|
|
|
91
95
|
service.on_finish.connect(on_finish)
|
|
92
96
|
service.set_timeout(5)
|
|
93
97
|
service.start_reactor()
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
@conbus_export.command("actiontable")
|
|
101
|
+
@click.pass_context
|
|
102
|
+
@connection_command()
|
|
103
|
+
def export_conbus_actiontable(ctx: click.Context) -> None:
|
|
104
|
+
r"""
|
|
105
|
+
Export Conbus device actiontable to YAML file.
|
|
106
|
+
|
|
107
|
+
Read device list from conson.yml
|
|
108
|
+
Export export.yml file in conson.yml format.
|
|
109
|
+
|
|
110
|
+
Args:
|
|
111
|
+
ctx: Click context object.
|
|
112
|
+
|
|
113
|
+
Examples:
|
|
114
|
+
\b
|
|
115
|
+
# Export device metadata to export.yml
|
|
116
|
+
xp conbus export
|
|
117
|
+
xp conbus export actiontable
|
|
118
|
+
"""
|
|
119
|
+
|
|
120
|
+
def on_progress(serial_number: str, current: int, total: int) -> None:
|
|
121
|
+
"""
|
|
122
|
+
Handle progress updates during export.
|
|
123
|
+
|
|
124
|
+
Args:
|
|
125
|
+
serial_number: Serial number of discovered device.
|
|
126
|
+
current: Current device number.
|
|
127
|
+
total: Total devices discovered.
|
|
128
|
+
"""
|
|
129
|
+
click.echo(f"Querying device {current}/{total}: {serial_number}...")
|
|
130
|
+
|
|
131
|
+
def on_device_actiontable_exported(
|
|
132
|
+
module: ConsonModuleConfig,
|
|
133
|
+
actiontable_type: ActionTableType,
|
|
134
|
+
actiontable_short: str,
|
|
135
|
+
) -> None:
|
|
136
|
+
"""
|
|
137
|
+
Handle device export completion.
|
|
138
|
+
|
|
139
|
+
Args:
|
|
140
|
+
module: Exported module configuration.
|
|
141
|
+
actiontable_type: Type of action table exported.
|
|
142
|
+
actiontable_short: Short representation of the action table.
|
|
143
|
+
"""
|
|
144
|
+
serial_number = module.serial_number or "UNKNOWN"
|
|
145
|
+
click.echo(f" ✓ Module: {serial_number})")
|
|
146
|
+
click.echo(f" ✓ Action type: {actiontable_type}")
|
|
147
|
+
click.echo(f" ✓ Action table: {actiontable_short}")
|
|
148
|
+
|
|
149
|
+
def on_finish(result: ConbusExportResponse) -> None:
|
|
150
|
+
"""
|
|
151
|
+
Handle export completion.
|
|
152
|
+
|
|
153
|
+
Args:
|
|
154
|
+
result: Export result.
|
|
155
|
+
|
|
156
|
+
Raises:
|
|
157
|
+
ClickException: When export fails with error message from result.
|
|
158
|
+
"""
|
|
159
|
+
# Try to stop reactor (may already be stopped)
|
|
160
|
+
with suppress(Exception):
|
|
161
|
+
service.stop_reactor()
|
|
162
|
+
|
|
163
|
+
if result.success:
|
|
164
|
+
click.echo(
|
|
165
|
+
f"\nExport complete: {result.output_file} ({result.device_count} devices)"
|
|
166
|
+
)
|
|
167
|
+
else:
|
|
168
|
+
click.echo(f"Error: {result.error}", err=True)
|
|
169
|
+
raise click.ClickException(result.error or "Export failed")
|
|
170
|
+
|
|
171
|
+
service: ConbusActiontableExportService = (
|
|
172
|
+
ctx.obj.get("container").get_container().resolve(ConbusActiontableExportService)
|
|
173
|
+
)
|
|
174
|
+
with service:
|
|
175
|
+
service.on_progress.connect(on_progress)
|
|
176
|
+
service.on_device_actiontable_exported.connect(on_device_actiontable_exported)
|
|
177
|
+
service.on_finish.connect(on_finish)
|
|
178
|
+
service.set_timeout(5)
|
|
179
|
+
service.start_reactor()
|
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
"""Conbus export service for exporting device configurations."""
|
|
2
|
+
|
|
3
|
+
import asyncio
|
|
4
|
+
import logging
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
from queue import SimpleQueue
|
|
7
|
+
from typing import Any, Optional, Tuple
|
|
8
|
+
|
|
9
|
+
import yaml
|
|
10
|
+
from psygnal import Signal
|
|
11
|
+
|
|
12
|
+
from xp.models.actiontable.actiontable_type import ActionTableType, ActionTableType2
|
|
13
|
+
from xp.models.conbus.conbus_export import ConbusExportResponse
|
|
14
|
+
from xp.models.config.conson_module_config import (
|
|
15
|
+
ConsonModuleConfig,
|
|
16
|
+
ConsonModuleListConfig,
|
|
17
|
+
)
|
|
18
|
+
from xp.services.conbus.actiontable.actiontable_download_service import (
|
|
19
|
+
ActionTableDownloadService,
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class ConbusActiontableExportService:
|
|
24
|
+
"""
|
|
25
|
+
Service for exporting Conbus device configurations.
|
|
26
|
+
|
|
27
|
+
Discovers all devices on the Conbus network and queries their configuration
|
|
28
|
+
datapoints to generate a structured export file compatible with conson.yml format.
|
|
29
|
+
|
|
30
|
+
Attributes:
|
|
31
|
+
download_service: Download service for exporting device configurations.
|
|
32
|
+
export_result: Final export result.
|
|
33
|
+
export_status: Export status (OK, FAILED_TIMEOUT, etc.).
|
|
34
|
+
on_progress: Signal emitted on device discovery (serial, current, total).
|
|
35
|
+
on_device_actiontable_exported: Signal emitted when device export completes.
|
|
36
|
+
on_finish: Signal emitted when export finishes.
|
|
37
|
+
ACTIONTABLE_SEQUENCE: Sequence of actiontable to query for each device.
|
|
38
|
+
"""
|
|
39
|
+
|
|
40
|
+
# Signals (class attributes)
|
|
41
|
+
on_progress: Signal = Signal(str, int, int) # serial, current, total
|
|
42
|
+
on_device_actiontable_exported: Signal = Signal(
|
|
43
|
+
ConsonModuleConfig, ActionTableType, str
|
|
44
|
+
)
|
|
45
|
+
on_finish: Signal = Signal(ConbusExportResponse)
|
|
46
|
+
|
|
47
|
+
ACTIONTABLE_SEQUENCE = [
|
|
48
|
+
ActionTableType2.ACTIONTABLE,
|
|
49
|
+
ActionTableType2.MSACTIONTABLE,
|
|
50
|
+
]
|
|
51
|
+
|
|
52
|
+
def __init__(
|
|
53
|
+
self,
|
|
54
|
+
download_service: ActionTableDownloadService,
|
|
55
|
+
module_list: ConsonModuleListConfig,
|
|
56
|
+
) -> None:
|
|
57
|
+
"""
|
|
58
|
+
Initialize the Conbus export service.
|
|
59
|
+
|
|
60
|
+
Args:
|
|
61
|
+
download_service: Protocol for downloading actiontables.
|
|
62
|
+
module_list: module to export.
|
|
63
|
+
"""
|
|
64
|
+
self.logger = logging.getLogger(__name__)
|
|
65
|
+
self.download_service = download_service
|
|
66
|
+
self._module_list: ConsonModuleListConfig = module_list
|
|
67
|
+
# State management
|
|
68
|
+
self.device_queue: SimpleQueue[Tuple[ConsonModuleConfig, ActionTableType]] = (
|
|
69
|
+
SimpleQueue()
|
|
70
|
+
) # FIFO
|
|
71
|
+
for module in self._module_list.root:
|
|
72
|
+
self.device_queue.put((module, ActionTableType.ACTIONTABLE))
|
|
73
|
+
if module.module_type == "xp20":
|
|
74
|
+
self.device_queue.put((module, ActionTableType.MSACTIONTABLE_XP20))
|
|
75
|
+
if module.module_type == "xp24":
|
|
76
|
+
self.device_queue.put((module, ActionTableType.MSACTIONTABLE_XP24))
|
|
77
|
+
if module.module_type == "xp33":
|
|
78
|
+
self.device_queue.put((module, ActionTableType.MSACTIONTABLE_XP33))
|
|
79
|
+
|
|
80
|
+
self.current_module: Optional[ConsonModuleConfig] = None
|
|
81
|
+
self.curent_actiontable_type: Optional[ActionTableType] = None
|
|
82
|
+
self.export_result = ConbusExportResponse(success=False)
|
|
83
|
+
self.export_status = "OK"
|
|
84
|
+
# Connect protocol signals
|
|
85
|
+
self._connect_signals()
|
|
86
|
+
|
|
87
|
+
def on_module_actiontable_received(
|
|
88
|
+
self, actiontable: Any, short_actiontable: list[str]
|
|
89
|
+
) -> None:
|
|
90
|
+
"""
|
|
91
|
+
Handle actiontable received event.
|
|
92
|
+
|
|
93
|
+
Args:
|
|
94
|
+
actiontable: Full actiontable data.
|
|
95
|
+
short_actiontable: Short representation of the actiontable.
|
|
96
|
+
"""
|
|
97
|
+
if not self.curent_actiontable_type:
|
|
98
|
+
self._fail("Invalid state (curent_actiontable_type)")
|
|
99
|
+
return
|
|
100
|
+
|
|
101
|
+
if not self.current_module:
|
|
102
|
+
self._fail("Invalid state (current_module)")
|
|
103
|
+
return
|
|
104
|
+
|
|
105
|
+
if self.curent_actiontable_type == ActionTableType.ACTIONTABLE:
|
|
106
|
+
self.current_module.action_table = short_actiontable
|
|
107
|
+
elif self.curent_actiontable_type == ActionTableType.MSACTIONTABLE_XP20:
|
|
108
|
+
self.current_module.xp20_msaction_table = short_actiontable
|
|
109
|
+
elif self.curent_actiontable_type == ActionTableType.MSACTIONTABLE_XP24:
|
|
110
|
+
self.current_module.xp24_msaction_table = short_actiontable
|
|
111
|
+
elif self.curent_actiontable_type == ActionTableType.MSACTIONTABLE_XP33:
|
|
112
|
+
self.current_module.xp33_msaction_table = short_actiontable
|
|
113
|
+
|
|
114
|
+
self.on_device_actiontable_exported.emit(
|
|
115
|
+
self.current_module, self.curent_actiontable_type, actiontable
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
def on_module_finish(self) -> None:
|
|
119
|
+
"""Handle module export completion."""
|
|
120
|
+
self._save_action_table()
|
|
121
|
+
has_next_module = self.configure()
|
|
122
|
+
if not has_next_module:
|
|
123
|
+
self._succeed()
|
|
124
|
+
|
|
125
|
+
def on_module_progress(self) -> None:
|
|
126
|
+
"""Handle module progress event and emit progress signal."""
|
|
127
|
+
serial_number = (
|
|
128
|
+
self.current_module.serial_number if self.current_module else "UNKNOWN"
|
|
129
|
+
)
|
|
130
|
+
total_modules = len(self._module_list.root)
|
|
131
|
+
current_index = total_modules - self.device_queue.qsize()
|
|
132
|
+
|
|
133
|
+
self.on_progress.emit(serial_number, current_index, total_modules)
|
|
134
|
+
|
|
135
|
+
def on_module_error(self, error_message: str) -> None:
|
|
136
|
+
"""
|
|
137
|
+
Handle module error event.
|
|
138
|
+
|
|
139
|
+
Args:
|
|
140
|
+
error_message: Error message from module.
|
|
141
|
+
"""
|
|
142
|
+
self._fail(error_message)
|
|
143
|
+
|
|
144
|
+
def _save_action_table(self) -> None:
|
|
145
|
+
"""Write export to YAML file."""
|
|
146
|
+
self.logger.info("Saving action table")
|
|
147
|
+
|
|
148
|
+
if not self._module_list:
|
|
149
|
+
self._fail("FAILED_NO_DEVICES")
|
|
150
|
+
return
|
|
151
|
+
|
|
152
|
+
try:
|
|
153
|
+
# Write to file
|
|
154
|
+
path = "export.yml"
|
|
155
|
+
output_path = Path(path)
|
|
156
|
+
|
|
157
|
+
# Use Pydantic's model_dump to serialize, excluding only internal fields
|
|
158
|
+
data = self._module_list.model_dump(
|
|
159
|
+
exclude={
|
|
160
|
+
"root": {
|
|
161
|
+
"__all__": {
|
|
162
|
+
"enabled",
|
|
163
|
+
"conbus_ip",
|
|
164
|
+
"conbus_port",
|
|
165
|
+
"action_table",
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
},
|
|
169
|
+
exclude_none=True,
|
|
170
|
+
)
|
|
171
|
+
|
|
172
|
+
# Export as list at root level (not wrapped in 'root:' key)
|
|
173
|
+
modules_list = data.get("root", [])
|
|
174
|
+
|
|
175
|
+
with output_path.open("w") as f:
|
|
176
|
+
# Dump each module separately with blank lines between them
|
|
177
|
+
for i, module in enumerate(modules_list):
|
|
178
|
+
# Add blank line before each module except the first
|
|
179
|
+
if i > 0:
|
|
180
|
+
f.write("\n")
|
|
181
|
+
|
|
182
|
+
# Dump single item as list element
|
|
183
|
+
yaml_str = yaml.safe_dump(
|
|
184
|
+
[module],
|
|
185
|
+
default_flow_style=False,
|
|
186
|
+
sort_keys=False,
|
|
187
|
+
allow_unicode=True,
|
|
188
|
+
)
|
|
189
|
+
# Remove the trailing newline and write
|
|
190
|
+
f.write(yaml_str.rstrip("\n") + "\n")
|
|
191
|
+
|
|
192
|
+
self.logger.info(f"Export written to {path}")
|
|
193
|
+
self.export_result.output_file = path
|
|
194
|
+
|
|
195
|
+
except Exception as e:
|
|
196
|
+
self._fail(f"Failed to create export: {e}")
|
|
197
|
+
|
|
198
|
+
def configure(self) -> bool:
|
|
199
|
+
"""
|
|
200
|
+
Configure export service.
|
|
201
|
+
|
|
202
|
+
Returns:
|
|
203
|
+
True if there is a module to export, False otherwise.
|
|
204
|
+
"""
|
|
205
|
+
self.download_service.reset()
|
|
206
|
+
(self.current_module, self.curent_actiontable_type) = (
|
|
207
|
+
self.device_queue.get_nowait()
|
|
208
|
+
)
|
|
209
|
+
if not (self.current_module or self.curent_actiontable_type):
|
|
210
|
+
self.logger.error("No module to export")
|
|
211
|
+
return False
|
|
212
|
+
|
|
213
|
+
self.download_service.configure(
|
|
214
|
+
self.current_module.serial_number,
|
|
215
|
+
self.curent_actiontable_type,
|
|
216
|
+
)
|
|
217
|
+
self.download_service.do_connect()
|
|
218
|
+
return True
|
|
219
|
+
|
|
220
|
+
def set_event_loop(self, event_loop: asyncio.AbstractEventLoop) -> None:
|
|
221
|
+
"""
|
|
222
|
+
Set event loop for async operations.
|
|
223
|
+
|
|
224
|
+
Args:
|
|
225
|
+
event_loop: Event loop to use.
|
|
226
|
+
"""
|
|
227
|
+
self.logger.debug("Set event loop")
|
|
228
|
+
self.download_service.set_event_loop(event_loop)
|
|
229
|
+
|
|
230
|
+
def set_timeout(self, timeout_seconds: float) -> None:
|
|
231
|
+
"""
|
|
232
|
+
Set timeout.
|
|
233
|
+
|
|
234
|
+
Args:
|
|
235
|
+
timeout_seconds: Timeout in seconds.
|
|
236
|
+
"""
|
|
237
|
+
self.download_service.set_timeout(timeout_seconds)
|
|
238
|
+
|
|
239
|
+
def start_reactor(self) -> None:
|
|
240
|
+
"""Start the reactor."""
|
|
241
|
+
self.download_service.start_reactor()
|
|
242
|
+
|
|
243
|
+
def stop_reactor(self) -> None:
|
|
244
|
+
"""Stop the reactor."""
|
|
245
|
+
self.download_service.stop_reactor()
|
|
246
|
+
|
|
247
|
+
def __enter__(self) -> "ConbusActiontableExportService":
|
|
248
|
+
"""
|
|
249
|
+
Enter context manager.
|
|
250
|
+
|
|
251
|
+
Returns:
|
|
252
|
+
Self for context manager protocol.
|
|
253
|
+
"""
|
|
254
|
+
# Reset state for reuse
|
|
255
|
+
self.export_result = ConbusExportResponse(success=False)
|
|
256
|
+
self.export_status = "OK"
|
|
257
|
+
self._connect_signals()
|
|
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
|
+
self._disconnect_signals()
|
|
265
|
+
self.stop_reactor()
|
|
266
|
+
|
|
267
|
+
def _connect_signals(self) -> None:
|
|
268
|
+
"""Connect download service signals to handlers."""
|
|
269
|
+
self.download_service.on_actiontable_received.connect(
|
|
270
|
+
self.on_module_actiontable_received
|
|
271
|
+
)
|
|
272
|
+
self.download_service.on_finish.connect(self.on_module_finish)
|
|
273
|
+
self.download_service.on_progress.connect(self.on_module_progress)
|
|
274
|
+
self.download_service.on_error.connect(self.on_module_error)
|
|
275
|
+
|
|
276
|
+
def _disconnect_signals(self) -> None:
|
|
277
|
+
"""Disconnect download service signals from handlers."""
|
|
278
|
+
self.download_service.on_actiontable_received.connect(
|
|
279
|
+
self.on_module_actiontable_received
|
|
280
|
+
)
|
|
281
|
+
self.download_service.on_finish.disconnect(self.on_module_finish)
|
|
282
|
+
self.download_service.on_progress.disconnect(self.on_module_progress)
|
|
283
|
+
self.download_service.on_error.disconnect(self.on_module_error)
|
|
284
|
+
|
|
285
|
+
self.on_progress.disconnect()
|
|
286
|
+
self.on_device_actiontable_exported.disconnect()
|
|
287
|
+
self.on_finish.disconnect()
|
|
288
|
+
|
|
289
|
+
def _fail(self, error: str) -> None:
|
|
290
|
+
"""
|
|
291
|
+
Handle export failure.
|
|
292
|
+
|
|
293
|
+
Args:
|
|
294
|
+
error: Error message.
|
|
295
|
+
"""
|
|
296
|
+
self.logger.error(error)
|
|
297
|
+
self.export_result.success = False
|
|
298
|
+
self.export_result.error = error
|
|
299
|
+
self.export_result.export_status = "FAILED"
|
|
300
|
+
self.on_finish.emit(self.export_result)
|
|
301
|
+
|
|
302
|
+
def _succeed(self) -> None:
|
|
303
|
+
"""Handle export success."""
|
|
304
|
+
self.logger.info("Export succeed")
|
|
305
|
+
self.export_result.success = True
|
|
306
|
+
self.export_result.error = None
|
|
307
|
+
self.export_result.export_status = "OK"
|
|
308
|
+
self.on_finish.emit(self.export_result)
|
|
@@ -57,16 +57,19 @@ class ConbusExportService:
|
|
|
57
57
|
DataPointType.AUTO_REPORT_STATUS,
|
|
58
58
|
]
|
|
59
59
|
|
|
60
|
-
def __init__(
|
|
60
|
+
def __init__(
|
|
61
|
+
self, conbus_protocol: ConbusEventProtocol, telegram_service: TelegramService
|
|
62
|
+
) -> None:
|
|
61
63
|
"""
|
|
62
64
|
Initialize the Conbus export service.
|
|
63
65
|
|
|
64
66
|
Args:
|
|
65
67
|
conbus_protocol: Protocol for Conbus communication.
|
|
68
|
+
telegram_service: TelegramService for telegram parsing.
|
|
66
69
|
"""
|
|
67
70
|
self.logger = logging.getLogger(__name__)
|
|
68
71
|
self.conbus_protocol = conbus_protocol
|
|
69
|
-
self.telegram_service =
|
|
72
|
+
self.telegram_service = telegram_service
|
|
70
73
|
|
|
71
74
|
# State management
|
|
72
75
|
self.discovered_devices: list[str] = []
|
xp/utils/dependencies.py
CHANGED
|
@@ -211,7 +211,8 @@ class ServiceContainer:
|
|
|
211
211
|
self.container.register(
|
|
212
212
|
ConbusExportService,
|
|
213
213
|
factory=lambda: ConbusExportService(
|
|
214
|
-
conbus_protocol=self.container.resolve(ConbusEventProtocol)
|
|
214
|
+
conbus_protocol=self.container.resolve(ConbusEventProtocol),
|
|
215
|
+
telegram_service=self.container.resolve(TelegramService),
|
|
215
216
|
),
|
|
216
217
|
scope=punq.Scope.singleton,
|
|
217
218
|
)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|