conson-xp 1.0.1__py3-none-any.whl → 1.2.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.0.1.dist-info → conson_xp-1.2.0.dist-info}/METADATA +1 -1
- conson_xp-1.2.0.dist-info/RECORD +181 -0
- xp/__init__.py +4 -3
- xp/api/main.py +18 -3
- xp/api/models/api.py +13 -2
- xp/api/models/discover.py +12 -2
- xp/api/routers/conbus_blink.py +18 -6
- xp/api/routers/conbus_custom.py +11 -3
- xp/api/routers/conbus_datapoint.py +10 -3
- xp/api/routers/conbus_output.py +29 -9
- xp/api/routers/errors.py +6 -5
- xp/cli/__init__.py +1 -1
- xp/cli/commands/__init__.py +1 -0
- xp/cli/commands/api.py +1 -5
- xp/cli/commands/api_start_commands.py +14 -8
- xp/cli/commands/conbus/conbus.py +9 -37
- xp/cli/commands/conbus/conbus_actiontable_commands.py +21 -1
- xp/cli/commands/conbus/conbus_autoreport_commands.py +21 -11
- xp/cli/commands/conbus/conbus_blink_commands.py +53 -21
- xp/cli/commands/conbus/conbus_config_commands.py +7 -4
- xp/cli/commands/conbus/conbus_custom_commands.py +13 -4
- xp/cli/commands/conbus/conbus_datapoint_commands.py +28 -8
- xp/cli/commands/conbus/conbus_discover_commands.py +15 -4
- xp/cli/commands/conbus/conbus_lightlevel_commands.py +50 -11
- xp/cli/commands/conbus/conbus_linknumber_commands.py +21 -11
- xp/cli/commands/conbus/conbus_msactiontable_commands.py +25 -1
- xp/cli/commands/conbus/conbus_output_commands.py +46 -12
- xp/cli/commands/conbus/conbus_raw_commands.py +17 -6
- xp/cli/commands/conbus/conbus_receive_commands.py +15 -7
- xp/cli/commands/conbus/conbus_scan_commands.py +35 -102
- xp/cli/commands/file_commands.py +26 -15
- xp/cli/commands/homekit/homekit.py +14 -8
- xp/cli/commands/homekit/homekit_start_commands.py +5 -5
- xp/cli/commands/module_commands.py +26 -19
- xp/cli/commands/reverse_proxy_commands.py +24 -18
- xp/cli/commands/server/server_commands.py +18 -18
- xp/cli/commands/telegram/telegram.py +4 -12
- xp/cli/commands/telegram/telegram_blink_commands.py +10 -8
- xp/cli/commands/telegram/telegram_checksum_commands.py +19 -8
- xp/cli/commands/telegram/telegram_discover_commands.py +2 -4
- xp/cli/commands/telegram/telegram_linknumber_commands.py +11 -8
- xp/cli/commands/telegram/telegram_parse_commands.py +10 -9
- xp/cli/commands/telegram/telegram_version_commands.py +8 -4
- xp/cli/main.py +5 -1
- xp/cli/utils/click_tree.py +23 -3
- xp/cli/utils/datapoint_type_choice.py +20 -0
- xp/cli/utils/decorators.py +165 -14
- xp/cli/utils/error_handlers.py +49 -18
- xp/cli/utils/formatters.py +95 -10
- xp/cli/utils/serial_number_type.py +18 -0
- xp/cli/utils/system_function_choice.py +20 -0
- xp/cli/utils/xp_module_type.py +20 -0
- xp/connection/__init__.py +1 -1
- xp/connection/exceptions.py +5 -5
- xp/models/__init__.py +1 -1
- xp/models/actiontable/__init__.py +1 -0
- xp/models/actiontable/actiontable.py +17 -1
- xp/models/actiontable/msactiontable_xp20.py +10 -0
- xp/models/actiontable/msactiontable_xp24.py +20 -3
- xp/models/actiontable/msactiontable_xp33.py +27 -4
- xp/models/conbus/__init__.py +1 -0
- xp/models/conbus/conbus.py +34 -4
- xp/models/conbus/conbus_autoreport.py +20 -2
- xp/models/conbus/conbus_blink.py +22 -2
- xp/models/conbus/conbus_client_config.py +22 -1
- xp/models/conbus/conbus_connection_status.py +16 -2
- xp/models/conbus/conbus_custom.py +21 -2
- xp/models/conbus/conbus_datapoint.py +22 -2
- xp/models/conbus/conbus_discover.py +18 -2
- xp/models/conbus/conbus_lightlevel.py +20 -2
- xp/models/conbus/conbus_linknumber.py +20 -2
- xp/models/conbus/conbus_output.py +22 -2
- xp/models/conbus/conbus_raw.py +17 -2
- xp/models/conbus/conbus_receive.py +16 -2
- xp/models/homekit/__init__.py +1 -0
- xp/models/homekit/homekit_accessory.py +15 -1
- xp/models/homekit/homekit_config.py +52 -0
- xp/models/homekit/homekit_conson_config.py +32 -0
- xp/models/log_entry.py +49 -9
- xp/models/protocol/__init__.py +1 -0
- xp/models/protocol/conbus_protocol.py +130 -21
- xp/models/telegram/__init__.py +1 -0
- xp/models/telegram/action_type.py +16 -2
- xp/models/telegram/datapoint_type.py +36 -2
- xp/models/telegram/event_telegram.py +46 -10
- xp/models/telegram/event_type.py +8 -1
- xp/models/telegram/input_action_type.py +34 -2
- xp/models/telegram/input_type.py +9 -1
- xp/models/telegram/module_type.py +69 -19
- xp/models/telegram/module_type_code.py +43 -1
- xp/models/telegram/output_telegram.py +30 -6
- xp/models/telegram/reply_telegram.py +56 -11
- xp/models/telegram/system_function.py +35 -3
- xp/models/telegram/system_telegram.py +18 -4
- xp/models/telegram/telegram.py +12 -3
- xp/models/telegram/telegram_type.py +8 -1
- xp/models/telegram/timeparam_type.py +27 -0
- xp/models/write_config_type.py +17 -2
- xp/services/__init__.py +1 -1
- xp/services/conbus/__init__.py +1 -0
- xp/services/conbus/actiontable/__init__.py +1 -0
- xp/services/conbus/actiontable/actiontable_service.py +33 -2
- xp/services/conbus/actiontable/msactiontable_service.py +40 -3
- xp/services/conbus/actiontable/msactiontable_xp24_serializer.py +36 -4
- xp/services/conbus/actiontable/msactiontable_xp33_serializer.py +45 -5
- xp/services/conbus/conbus_autoreport_get_service.py +17 -8
- xp/services/conbus/conbus_autoreport_set_service.py +29 -16
- xp/services/conbus/conbus_blink_all_service.py +40 -21
- xp/services/conbus/conbus_blink_service.py +37 -13
- xp/services/conbus/conbus_custom_service.py +29 -13
- xp/services/conbus/conbus_datapoint_queryall_service.py +40 -16
- xp/services/conbus/conbus_datapoint_service.py +33 -12
- xp/services/conbus/conbus_discover_service.py +43 -7
- xp/services/conbus/conbus_lightlevel_get_service.py +22 -14
- xp/services/conbus/conbus_lightlevel_set_service.py +40 -20
- xp/services/conbus/conbus_linknumber_get_service.py +18 -10
- xp/services/conbus/conbus_linknumber_set_service.py +34 -8
- xp/services/conbus/conbus_output_service.py +33 -13
- xp/services/conbus/conbus_raw_service.py +36 -16
- xp/services/conbus/conbus_receive_service.py +38 -6
- xp/services/conbus/conbus_scan_service.py +45 -19
- xp/services/homekit/__init__.py +1 -0
- xp/services/homekit/homekit_cache_service.py +31 -6
- xp/services/homekit/homekit_conbus_service.py +33 -2
- xp/services/homekit/homekit_config_validator.py +97 -15
- xp/services/homekit/homekit_conson_validator.py +51 -7
- xp/services/homekit/homekit_dimminglight.py +47 -1
- xp/services/homekit/homekit_dimminglight_service.py +35 -1
- xp/services/homekit/homekit_hap_service.py +71 -18
- xp/services/homekit/homekit_lightbulb.py +35 -1
- xp/services/homekit/homekit_lightbulb_service.py +30 -2
- xp/services/homekit/homekit_module_service.py +23 -1
- xp/services/homekit/homekit_outlet.py +47 -1
- xp/services/homekit/homekit_outlet_service.py +44 -2
- xp/services/homekit/homekit_service.py +113 -19
- xp/services/log_file_service.py +37 -41
- xp/services/module_type_service.py +26 -5
- xp/services/protocol/__init__.py +1 -1
- xp/services/protocol/conbus_protocol.py +115 -20
- xp/services/protocol/protocol_factory.py +40 -0
- xp/services/protocol/telegram_protocol.py +38 -7
- xp/services/reverse_proxy_service.py +79 -14
- xp/services/server/__init__.py +1 -0
- xp/services/server/base_server_service.py +102 -14
- xp/services/server/cp20_server_service.py +12 -4
- xp/services/server/server_service.py +26 -11
- xp/services/server/xp130_server_service.py +11 -3
- xp/services/server/xp20_server_service.py +11 -3
- xp/services/server/xp230_server_service.py +11 -3
- xp/services/server/xp24_server_service.py +33 -6
- xp/services/server/xp33_server_service.py +41 -8
- xp/services/telegram/__init__.py +1 -0
- xp/services/telegram/telegram_blink_service.py +19 -31
- xp/services/telegram/telegram_checksum_service.py +10 -10
- xp/services/telegram/telegram_discover_service.py +58 -29
- xp/services/telegram/telegram_link_number_service.py +27 -40
- xp/services/telegram/telegram_output_service.py +46 -49
- xp/services/telegram/telegram_service.py +41 -41
- xp/services/telegram/telegram_version_service.py +4 -2
- xp/utils/__init__.py +1 -1
- xp/utils/dependencies.py +0 -1
- xp/utils/serialization.py +6 -0
- xp/utils/time_utils.py +6 -11
- conson_xp-1.0.1.dist-info/RECORD +0 -181
- {conson_xp-1.0.1.dist-info → conson_xp-1.2.0.dist-info}/WHEEL +0 -0
- {conson_xp-1.0.1.dist-info → conson_xp-1.2.0.dist-info}/entry_points.txt +0 -0
- {conson_xp-1.0.1.dist-info → conson_xp-1.2.0.dist-info}/licenses/LICENSE +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
"""Conbus
|
|
1
|
+
"""Conbus Blink Service for TCP communication with Conbus servers.
|
|
2
2
|
|
|
3
3
|
This service implements a TCP client that connects to Conbus servers and sends
|
|
4
|
-
|
|
4
|
+
blink/unblink telegrams to control module LED indicators.
|
|
5
5
|
"""
|
|
6
6
|
|
|
7
7
|
import logging
|
|
@@ -21,10 +21,10 @@ from xp.services.telegram.telegram_service import TelegramService
|
|
|
21
21
|
|
|
22
22
|
class ConbusBlinkService(ConbusProtocol):
|
|
23
23
|
"""
|
|
24
|
-
Service for
|
|
24
|
+
Service for blinking module LEDs on Conbus servers.
|
|
25
25
|
|
|
26
|
-
Uses
|
|
27
|
-
for
|
|
26
|
+
Uses ConbusProtocol to provide blink/unblink functionality
|
|
27
|
+
for controlling module LED indicators.
|
|
28
28
|
"""
|
|
29
29
|
|
|
30
30
|
def __init__(
|
|
@@ -33,7 +33,13 @@ class ConbusBlinkService(ConbusProtocol):
|
|
|
33
33
|
cli_config: ConbusClientConfig,
|
|
34
34
|
reactor: PosixReactorBase,
|
|
35
35
|
) -> None:
|
|
36
|
-
"""Initialize the Conbus
|
|
36
|
+
"""Initialize the Conbus blink service.
|
|
37
|
+
|
|
38
|
+
Args:
|
|
39
|
+
telegram_service: Service for parsing telegrams.
|
|
40
|
+
cli_config: Configuration for Conbus client connection.
|
|
41
|
+
reactor: Twisted reactor for event loop.
|
|
42
|
+
"""
|
|
37
43
|
super().__init__(cli_config, reactor)
|
|
38
44
|
self.telegram_service = telegram_service
|
|
39
45
|
self.serial_number: str = ""
|
|
@@ -50,7 +56,8 @@ class ConbusBlinkService(ConbusProtocol):
|
|
|
50
56
|
self.logger = logging.getLogger(__name__)
|
|
51
57
|
|
|
52
58
|
def connection_established(self) -> None:
|
|
53
|
-
|
|
59
|
+
"""Handle connection established event."""
|
|
60
|
+
self.logger.debug("Connection established, sending blink command.")
|
|
54
61
|
# Blink is 05, Unblink is 06
|
|
55
62
|
system_function = SystemFunction.UNBLINK
|
|
56
63
|
if self.on_or_off.lower() == "on":
|
|
@@ -66,11 +73,20 @@ class ConbusBlinkService(ConbusProtocol):
|
|
|
66
73
|
self.service_response.operation = self.on_or_off
|
|
67
74
|
|
|
68
75
|
def telegram_sent(self, telegram_sent: str) -> None:
|
|
76
|
+
"""Handle telegram sent event.
|
|
77
|
+
|
|
78
|
+
Args:
|
|
79
|
+
telegram_sent: The telegram that was sent.
|
|
80
|
+
"""
|
|
69
81
|
system_telegram = self.telegram_service.parse_system_telegram(telegram_sent)
|
|
70
82
|
self.service_response.sent_telegram = system_telegram
|
|
71
83
|
|
|
72
84
|
def telegram_received(self, telegram_received: TelegramReceivedEvent) -> None:
|
|
85
|
+
"""Handle telegram received event.
|
|
73
86
|
|
|
87
|
+
Args:
|
|
88
|
+
telegram_received: The telegram received event.
|
|
89
|
+
"""
|
|
74
90
|
self.logger.debug(f"Telegram received: {telegram_received}")
|
|
75
91
|
if not self.service_response.received_telegrams:
|
|
76
92
|
self.service_response.received_telegrams = []
|
|
@@ -101,6 +117,11 @@ class ConbusBlinkService(ConbusProtocol):
|
|
|
101
117
|
self.finish_callback(self.service_response)
|
|
102
118
|
|
|
103
119
|
def failed(self, message: str) -> None:
|
|
120
|
+
"""Handle failed connection event.
|
|
121
|
+
|
|
122
|
+
Args:
|
|
123
|
+
message: Failure message.
|
|
124
|
+
"""
|
|
104
125
|
self.logger.debug(f"Failed with message: {message}")
|
|
105
126
|
self.service_response.success = False
|
|
106
127
|
self.service_response.timestamp = datetime.now()
|
|
@@ -115,17 +136,20 @@ class ConbusBlinkService(ConbusProtocol):
|
|
|
115
136
|
finish_callback: Callable[[ConbusBlinkResponse], None],
|
|
116
137
|
timeout_seconds: Optional[float] = None,
|
|
117
138
|
) -> None:
|
|
118
|
-
"""
|
|
119
|
-
Send blink command to start blinking module LED.
|
|
139
|
+
r"""Send blink command to start blinking module LED.
|
|
120
140
|
|
|
121
|
-
|
|
141
|
+
Args:
|
|
142
|
+
serial_number: 10-digit module serial number.
|
|
143
|
+
on_or_off: "on" to blink or "off" to unblink.
|
|
144
|
+
finish_callback: Callback function to call when the reply is received.
|
|
145
|
+
timeout_seconds: Timeout in seconds.
|
|
122
146
|
|
|
123
|
-
|
|
147
|
+
Examples:
|
|
148
|
+
\b
|
|
124
149
|
xp conbus blink 0012345008 on
|
|
125
150
|
xp conbus blink 0012345008 off
|
|
126
151
|
"""
|
|
127
|
-
|
|
128
|
-
self.logger.info("Starting get_autoreport_status")
|
|
152
|
+
self.logger.info("Starting send_blink_telegram")
|
|
129
153
|
if timeout_seconds:
|
|
130
154
|
self.timeout_seconds = timeout_seconds
|
|
131
155
|
self.finish_callback = finish_callback
|
|
@@ -33,7 +33,13 @@ class ConbusCustomService(ConbusProtocol):
|
|
|
33
33
|
cli_config: ConbusClientConfig,
|
|
34
34
|
reactor: PosixReactorBase,
|
|
35
35
|
) -> None:
|
|
36
|
-
"""Initialize the Conbus custom service
|
|
36
|
+
"""Initialize the Conbus custom service.
|
|
37
|
+
|
|
38
|
+
Args:
|
|
39
|
+
telegram_service: Service for parsing telegrams.
|
|
40
|
+
cli_config: Configuration for Conbus client connection.
|
|
41
|
+
reactor: Twisted reactor for event loop.
|
|
42
|
+
"""
|
|
37
43
|
super().__init__(cli_config, reactor)
|
|
38
44
|
self.telegram_service = telegram_service
|
|
39
45
|
self.serial_number: str = ""
|
|
@@ -49,8 +55,9 @@ class ConbusCustomService(ConbusProtocol):
|
|
|
49
55
|
self.logger = logging.getLogger(__name__)
|
|
50
56
|
|
|
51
57
|
def connection_established(self) -> None:
|
|
58
|
+
"""Handle connection established event."""
|
|
52
59
|
self.logger.debug(
|
|
53
|
-
f"Connection established, sending custom telegram F{self.function_code}D{self.data}
|
|
60
|
+
f"Connection established, sending custom telegram F{self.function_code}D{self.data}."
|
|
54
61
|
)
|
|
55
62
|
system_function = SystemFunction.from_code(self.function_code)
|
|
56
63
|
if not system_function:
|
|
@@ -66,10 +73,19 @@ class ConbusCustomService(ConbusProtocol):
|
|
|
66
73
|
)
|
|
67
74
|
|
|
68
75
|
def telegram_sent(self, telegram_sent: str) -> None:
|
|
76
|
+
"""Handle telegram sent event.
|
|
77
|
+
|
|
78
|
+
Args:
|
|
79
|
+
telegram_sent: The telegram that was sent.
|
|
80
|
+
"""
|
|
69
81
|
self.service_response.sent_telegram = telegram_sent
|
|
70
82
|
|
|
71
83
|
def telegram_received(self, telegram_received: TelegramReceivedEvent) -> None:
|
|
84
|
+
"""Handle telegram received event.
|
|
72
85
|
|
|
86
|
+
Args:
|
|
87
|
+
telegram_received: The telegram received event.
|
|
88
|
+
"""
|
|
73
89
|
self.logger.debug(f"Telegram received: {telegram_received}")
|
|
74
90
|
if not self.service_response.received_telegrams:
|
|
75
91
|
self.service_response.received_telegrams = []
|
|
@@ -101,6 +117,11 @@ class ConbusCustomService(ConbusProtocol):
|
|
|
101
117
|
self.finish_callback(self.service_response)
|
|
102
118
|
|
|
103
119
|
def failed(self, message: str) -> None:
|
|
120
|
+
"""Handle failed connection event.
|
|
121
|
+
|
|
122
|
+
Args:
|
|
123
|
+
message: Failure message.
|
|
124
|
+
"""
|
|
104
125
|
self.logger.debug(f"Failed with message: {message}")
|
|
105
126
|
self.service_response.success = False
|
|
106
127
|
self.service_response.timestamp = datetime.now()
|
|
@@ -116,20 +137,15 @@ class ConbusCustomService(ConbusProtocol):
|
|
|
116
137
|
finish_callback: Callable[[ConbusCustomResponse], None],
|
|
117
138
|
timeout_seconds: Optional[float] = None,
|
|
118
139
|
) -> None:
|
|
119
|
-
"""
|
|
120
|
-
Send a custom telegram to a module.
|
|
140
|
+
"""Send a custom telegram to a module.
|
|
121
141
|
|
|
122
142
|
Args:
|
|
123
|
-
serial_number: 10-digit module serial number
|
|
124
|
-
function_code: Function code (e.g., "02", "17")
|
|
125
|
-
data: Data code (e.g., "E2", "AA")
|
|
126
|
-
finish_callback:
|
|
127
|
-
timeout_seconds:
|
|
128
|
-
|
|
129
|
-
Returns:
|
|
130
|
-
ConbusCustomResponse with operation result
|
|
143
|
+
serial_number: 10-digit module serial number.
|
|
144
|
+
function_code: Function code (e.g., "02", "17").
|
|
145
|
+
data: Data code (e.g., "E2", "AA").
|
|
146
|
+
finish_callback: Callback function to call when the reply is received.
|
|
147
|
+
timeout_seconds: Timeout in seconds.
|
|
131
148
|
"""
|
|
132
|
-
|
|
133
149
|
self.logger.info("Starting send_custom_telegram")
|
|
134
150
|
if timeout_seconds:
|
|
135
151
|
self.timeout_seconds = timeout_seconds
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
"""Conbus DataPoint Query All Service.
|
|
2
|
+
|
|
3
|
+
This module provides service for querying all datapoint types from a module.
|
|
4
|
+
"""
|
|
5
|
+
|
|
1
6
|
import logging
|
|
2
7
|
from datetime import datetime
|
|
3
8
|
from typing import Callable, Optional
|
|
@@ -28,12 +33,12 @@ class ConbusDatapointQueryAllService(ConbusProtocol):
|
|
|
28
33
|
cli_config: ConbusClientConfig,
|
|
29
34
|
reactor: PosixReactorBase,
|
|
30
35
|
) -> None:
|
|
31
|
-
"""Initialize the query all service
|
|
36
|
+
"""Initialize the query all service.
|
|
32
37
|
|
|
33
38
|
Args:
|
|
34
|
-
telegram_service: TelegramService for dependency injection
|
|
35
|
-
cli_config: ConbusClientConfig for connection settings
|
|
36
|
-
reactor: PosixReactorBase for async operations
|
|
39
|
+
telegram_service: TelegramService for dependency injection.
|
|
40
|
+
cli_config: ConbusClientConfig for connection settings.
|
|
41
|
+
reactor: PosixReactorBase for async operations.
|
|
37
42
|
"""
|
|
38
43
|
super().__init__(cli_config, reactor)
|
|
39
44
|
self.telegram_service = telegram_service
|
|
@@ -51,11 +56,16 @@ class ConbusDatapointQueryAllService(ConbusProtocol):
|
|
|
51
56
|
self.logger = logging.getLogger(__name__)
|
|
52
57
|
|
|
53
58
|
def connection_established(self) -> None:
|
|
54
|
-
|
|
59
|
+
"""Handle connection established event."""
|
|
60
|
+
self.logger.debug("Connection established, querying datapoints.")
|
|
55
61
|
self.next_datapoint()
|
|
56
62
|
|
|
57
63
|
def next_datapoint(self) -> bool:
|
|
64
|
+
"""Query the next datapoint type.
|
|
58
65
|
|
|
66
|
+
Returns:
|
|
67
|
+
True if there are more datapoints to query, False otherwise.
|
|
68
|
+
"""
|
|
59
69
|
self.logger.debug("Querying next datapoint")
|
|
60
70
|
|
|
61
71
|
if self.current_index >= len(self.datapoint_types):
|
|
@@ -75,6 +85,11 @@ class ConbusDatapointQueryAllService(ConbusProtocol):
|
|
|
75
85
|
return True
|
|
76
86
|
|
|
77
87
|
def timeout(self) -> bool:
|
|
88
|
+
"""Handle timeout event by querying next datapoint.
|
|
89
|
+
|
|
90
|
+
Returns:
|
|
91
|
+
True to continue, False to stop the reactor.
|
|
92
|
+
"""
|
|
78
93
|
self.logger.debug("Timeout, querying next datapoint")
|
|
79
94
|
query_next_datapoint = self.next_datapoint()
|
|
80
95
|
if not query_next_datapoint:
|
|
@@ -89,10 +104,19 @@ class ConbusDatapointQueryAllService(ConbusProtocol):
|
|
|
89
104
|
return True
|
|
90
105
|
|
|
91
106
|
def telegram_sent(self, telegram_sent: str) -> None:
|
|
107
|
+
"""Handle telegram sent event.
|
|
108
|
+
|
|
109
|
+
Args:
|
|
110
|
+
telegram_sent: The telegram that was sent.
|
|
111
|
+
"""
|
|
92
112
|
self.service_response.sent_telegram = telegram_sent
|
|
93
113
|
|
|
94
114
|
def telegram_received(self, telegram_received: TelegramReceivedEvent) -> None:
|
|
115
|
+
"""Handle telegram received event.
|
|
95
116
|
|
|
117
|
+
Args:
|
|
118
|
+
telegram_received: The telegram received event.
|
|
119
|
+
"""
|
|
96
120
|
self.logger.debug(f"Telegram received: {telegram_received}")
|
|
97
121
|
if not self.service_response.received_telegrams:
|
|
98
122
|
self.service_response.received_telegrams = []
|
|
@@ -122,6 +146,11 @@ class ConbusDatapointQueryAllService(ConbusProtocol):
|
|
|
122
146
|
self.progress_callback(datapoint_telegram)
|
|
123
147
|
|
|
124
148
|
def failed(self, message: str) -> None:
|
|
149
|
+
"""Handle failed connection event.
|
|
150
|
+
|
|
151
|
+
Args:
|
|
152
|
+
message: Failure message.
|
|
153
|
+
"""
|
|
125
154
|
self.logger.debug(f"Failed with message: {message}")
|
|
126
155
|
self.service_response.success = False
|
|
127
156
|
self.service_response.timestamp = datetime.now()
|
|
@@ -136,20 +165,15 @@ class ConbusDatapointQueryAllService(ConbusProtocol):
|
|
|
136
165
|
progress_callback: Callable[[ReplyTelegram], None],
|
|
137
166
|
timeout_seconds: Optional[float] = None,
|
|
138
167
|
) -> None:
|
|
139
|
-
"""
|
|
140
|
-
Query a specific datapoint from a module.
|
|
168
|
+
"""Query all datapoints from a module.
|
|
141
169
|
|
|
142
170
|
Args:
|
|
143
|
-
serial_number: 10-digit module serial number
|
|
144
|
-
finish_callback:
|
|
145
|
-
progress_callback:
|
|
146
|
-
timeout_seconds:
|
|
147
|
-
|
|
148
|
-
Returns:
|
|
149
|
-
ConbusDatapointResponse with operation result and datapoint value
|
|
171
|
+
serial_number: 10-digit module serial number.
|
|
172
|
+
finish_callback: Callback function to call when all datapoints are received.
|
|
173
|
+
progress_callback: Callback function to call when each datapoint is received.
|
|
174
|
+
timeout_seconds: Timeout in seconds.
|
|
150
175
|
"""
|
|
151
|
-
|
|
152
|
-
self.logger.info("Starting query_datapoint")
|
|
176
|
+
self.logger.info("Starting query_all_datapoints")
|
|
153
177
|
if timeout_seconds:
|
|
154
178
|
self.timeout_seconds = timeout_seconds
|
|
155
179
|
self.finish_callback = finish_callback
|
|
@@ -33,7 +33,13 @@ class ConbusDatapointService(ConbusProtocol):
|
|
|
33
33
|
cli_config: ConbusClientConfig,
|
|
34
34
|
reactor: PosixReactorBase,
|
|
35
35
|
) -> None:
|
|
36
|
-
"""Initialize the Conbus datapoint service
|
|
36
|
+
"""Initialize the Conbus datapoint service.
|
|
37
|
+
|
|
38
|
+
Args:
|
|
39
|
+
telegram_service: Service for parsing telegrams.
|
|
40
|
+
cli_config: Configuration for Conbus client connection.
|
|
41
|
+
reactor: Twisted reactor for event loop.
|
|
42
|
+
"""
|
|
37
43
|
super().__init__(cli_config, reactor)
|
|
38
44
|
self.telegram_service = telegram_service
|
|
39
45
|
self.serial_number: str = ""
|
|
@@ -48,8 +54,9 @@ class ConbusDatapointService(ConbusProtocol):
|
|
|
48
54
|
self.logger = logging.getLogger(__name__)
|
|
49
55
|
|
|
50
56
|
def connection_established(self) -> None:
|
|
57
|
+
"""Handle connection established event."""
|
|
51
58
|
self.logger.debug(
|
|
52
|
-
f"Connection established, querying datapoint {self.datapoint_type}
|
|
59
|
+
f"Connection established, querying datapoint {self.datapoint_type}."
|
|
53
60
|
)
|
|
54
61
|
if self.datapoint_type is None:
|
|
55
62
|
self.failed("Datapoint type not set")
|
|
@@ -63,10 +70,19 @@ class ConbusDatapointService(ConbusProtocol):
|
|
|
63
70
|
)
|
|
64
71
|
|
|
65
72
|
def telegram_sent(self, telegram_sent: str) -> None:
|
|
73
|
+
"""Handle telegram sent event.
|
|
74
|
+
|
|
75
|
+
Args:
|
|
76
|
+
telegram_sent: The telegram that was sent.
|
|
77
|
+
"""
|
|
66
78
|
self.service_response.sent_telegram = telegram_sent
|
|
67
79
|
|
|
68
80
|
def telegram_received(self, telegram_received: TelegramReceivedEvent) -> None:
|
|
81
|
+
"""Handle telegram received event.
|
|
69
82
|
|
|
83
|
+
Args:
|
|
84
|
+
telegram_received: The telegram received event.
|
|
85
|
+
"""
|
|
70
86
|
self.logger.debug(f"Telegram received: {telegram_received}")
|
|
71
87
|
if not self.service_response.received_telegrams:
|
|
72
88
|
self.service_response.received_telegrams = []
|
|
@@ -97,6 +113,11 @@ class ConbusDatapointService(ConbusProtocol):
|
|
|
97
113
|
self.succeed(datapoint_telegram)
|
|
98
114
|
|
|
99
115
|
def succeed(self, datapoint_telegram: ReplyTelegram) -> None:
|
|
116
|
+
"""Handle successful datapoint query.
|
|
117
|
+
|
|
118
|
+
Args:
|
|
119
|
+
datapoint_telegram: The parsed datapoint telegram.
|
|
120
|
+
"""
|
|
100
121
|
self.logger.debug("Succeed querying datapoint")
|
|
101
122
|
self.service_response.success = True
|
|
102
123
|
self.service_response.timestamp = datetime.now()
|
|
@@ -108,6 +129,11 @@ class ConbusDatapointService(ConbusProtocol):
|
|
|
108
129
|
self.finish_callback(self.service_response)
|
|
109
130
|
|
|
110
131
|
def failed(self, message: str) -> None:
|
|
132
|
+
"""Handle failed connection event.
|
|
133
|
+
|
|
134
|
+
Args:
|
|
135
|
+
message: Failure message.
|
|
136
|
+
"""
|
|
111
137
|
self.logger.debug(f"Failed with message: {message}")
|
|
112
138
|
self.service_response.success = False
|
|
113
139
|
self.service_response.timestamp = datetime.now()
|
|
@@ -123,19 +149,14 @@ class ConbusDatapointService(ConbusProtocol):
|
|
|
123
149
|
finish_callback: Callable[[ConbusDatapointResponse], None],
|
|
124
150
|
timeout_seconds: Optional[float] = None,
|
|
125
151
|
) -> None:
|
|
126
|
-
"""
|
|
127
|
-
Query a specific datapoint from a module.
|
|
152
|
+
"""Query a specific datapoint from a module.
|
|
128
153
|
|
|
129
154
|
Args:
|
|
130
|
-
serial_number: 10-digit module serial number
|
|
131
|
-
datapoint_type: Type of datapoint to query
|
|
132
|
-
finish_callback:
|
|
133
|
-
timeout_seconds:
|
|
134
|
-
|
|
135
|
-
Returns:
|
|
136
|
-
ConbusDatapointResponse with operation result and datapoint value
|
|
155
|
+
serial_number: 10-digit module serial number.
|
|
156
|
+
datapoint_type: Type of datapoint to query.
|
|
157
|
+
finish_callback: Callback function to call when the datapoint is received.
|
|
158
|
+
timeout_seconds: Timeout in seconds.
|
|
137
159
|
"""
|
|
138
|
-
|
|
139
160
|
self.logger.info("Starting query_datapoint")
|
|
140
161
|
if timeout_seconds:
|
|
141
162
|
self.timeout_seconds = timeout_seconds
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
"""Conbus
|
|
1
|
+
"""Conbus Discover Service for TCP communication with Conbus servers.
|
|
2
2
|
|
|
3
3
|
This service implements a TCP client that connects to Conbus servers and sends
|
|
4
|
-
|
|
4
|
+
discover telegrams to find modules on the network.
|
|
5
5
|
"""
|
|
6
6
|
|
|
7
7
|
import logging
|
|
@@ -18,10 +18,10 @@ from xp.services.protocol.conbus_protocol import ConbusProtocol
|
|
|
18
18
|
|
|
19
19
|
class ConbusDiscoverService(ConbusProtocol):
|
|
20
20
|
"""
|
|
21
|
-
|
|
21
|
+
Service for discovering modules on Conbus servers.
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
Uses ConbusProtocol to provide discovery functionality for finding
|
|
24
|
+
modules connected to the Conbus network.
|
|
25
25
|
"""
|
|
26
26
|
|
|
27
27
|
def __init__(
|
|
@@ -29,7 +29,12 @@ class ConbusDiscoverService(ConbusProtocol):
|
|
|
29
29
|
cli_config: ConbusClientConfig,
|
|
30
30
|
reactor: PosixReactorBase,
|
|
31
31
|
) -> None:
|
|
32
|
-
"""Initialize the Conbus
|
|
32
|
+
"""Initialize the Conbus discover service.
|
|
33
|
+
|
|
34
|
+
Args:
|
|
35
|
+
cli_config: Conbus client configuration.
|
|
36
|
+
reactor: Twisted reactor instance.
|
|
37
|
+
"""
|
|
33
38
|
super().__init__(cli_config, reactor)
|
|
34
39
|
self.progress_callback: Optional[Callable[[str], None]] = None
|
|
35
40
|
self.finish_callback: Optional[Callable[[ConbusDiscoverResponse], None]] = None
|
|
@@ -39,6 +44,7 @@ class ConbusDiscoverService(ConbusProtocol):
|
|
|
39
44
|
self.logger = logging.getLogger(__name__)
|
|
40
45
|
|
|
41
46
|
def connection_established(self) -> None:
|
|
47
|
+
"""Handle connection established event."""
|
|
42
48
|
self.logger.debug("Connection established, sending discover telegram")
|
|
43
49
|
self.send_telegram(
|
|
44
50
|
telegram_type=TelegramType.SYSTEM,
|
|
@@ -48,11 +54,20 @@ class ConbusDiscoverService(ConbusProtocol):
|
|
|
48
54
|
)
|
|
49
55
|
|
|
50
56
|
def telegram_sent(self, telegram_sent: str) -> None:
|
|
57
|
+
"""Handle telegram sent event.
|
|
58
|
+
|
|
59
|
+
Args:
|
|
60
|
+
telegram_sent: The telegram that was sent.
|
|
61
|
+
"""
|
|
51
62
|
self.logger.debug(f"Telegram sent: {telegram_sent}")
|
|
52
63
|
self.discovered_device_result.sent_telegram = telegram_sent
|
|
53
64
|
|
|
54
65
|
def telegram_received(self, telegram_received: TelegramReceivedEvent) -> None:
|
|
66
|
+
"""Handle telegram received event.
|
|
55
67
|
|
|
68
|
+
Args:
|
|
69
|
+
telegram_received: The telegram received event.
|
|
70
|
+
"""
|
|
56
71
|
self.logger.debug(f"Telegram received: {telegram_received}")
|
|
57
72
|
if not self.discovered_device_result.received_telegrams:
|
|
58
73
|
self.discovered_device_result.received_telegrams = []
|
|
@@ -69,6 +84,11 @@ class ConbusDiscoverService(ConbusProtocol):
|
|
|
69
84
|
self.logger.debug("Not a discover response")
|
|
70
85
|
|
|
71
86
|
def discovered_device(self, serial_number: str) -> None:
|
|
87
|
+
"""Handle discovered device event.
|
|
88
|
+
|
|
89
|
+
Args:
|
|
90
|
+
serial_number: Serial number of the discovered device.
|
|
91
|
+
"""
|
|
72
92
|
self.logger.info("discovered_device: %s", serial_number)
|
|
73
93
|
if not self.discovered_device_result.discovered_devices:
|
|
74
94
|
self.discovered_device_result.discovered_devices = []
|
|
@@ -77,6 +97,11 @@ class ConbusDiscoverService(ConbusProtocol):
|
|
|
77
97
|
self.progress_callback(serial_number)
|
|
78
98
|
|
|
79
99
|
def timeout(self) -> bool:
|
|
100
|
+
"""Handle timeout event to stop discovery.
|
|
101
|
+
|
|
102
|
+
Returns:
|
|
103
|
+
False to stop the reactor.
|
|
104
|
+
"""
|
|
80
105
|
self.logger.info("Discovery stopped after: %ss", self.timeout_seconds)
|
|
81
106
|
self.discovered_device_result.success = True
|
|
82
107
|
if self.finish_callback:
|
|
@@ -84,6 +109,11 @@ class ConbusDiscoverService(ConbusProtocol):
|
|
|
84
109
|
return False
|
|
85
110
|
|
|
86
111
|
def failed(self, message: str) -> None:
|
|
112
|
+
"""Handle failed connection event.
|
|
113
|
+
|
|
114
|
+
Args:
|
|
115
|
+
message: Failure message.
|
|
116
|
+
"""
|
|
87
117
|
self.logger.debug(f"Failed: {message}")
|
|
88
118
|
self.discovered_device_result.success = False
|
|
89
119
|
self.discovered_device_result.error = message
|
|
@@ -96,7 +126,13 @@ class ConbusDiscoverService(ConbusProtocol):
|
|
|
96
126
|
finish_callback: Callable[[ConbusDiscoverResponse], None],
|
|
97
127
|
timeout_seconds: Optional[float] = None,
|
|
98
128
|
) -> None:
|
|
99
|
-
"""Run reactor in dedicated thread with its own event loop
|
|
129
|
+
"""Run reactor in dedicated thread with its own event loop.
|
|
130
|
+
|
|
131
|
+
Args:
|
|
132
|
+
progress_callback: Callback for each discovered device.
|
|
133
|
+
finish_callback: Callback when discovery completes.
|
|
134
|
+
timeout_seconds: Optional timeout in seconds.
|
|
135
|
+
"""
|
|
100
136
|
self.logger.info("Starting discovery")
|
|
101
137
|
if timeout_seconds:
|
|
102
138
|
self.timeout_seconds = timeout_seconds
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
"""Conbus
|
|
1
|
+
"""Conbus Lightlevel Get Service for getting module light levels.
|
|
2
2
|
|
|
3
|
-
This service handles
|
|
3
|
+
This service handles light level query operations for modules through Conbus telegrams.
|
|
4
4
|
"""
|
|
5
5
|
|
|
6
6
|
import logging
|
|
@@ -18,10 +18,10 @@ from xp.services.telegram.telegram_service import TelegramService
|
|
|
18
18
|
|
|
19
19
|
class ConbusLightlevelGetService(ConbusDatapointService):
|
|
20
20
|
"""
|
|
21
|
-
Service for
|
|
21
|
+
Service for getting light levels from Conbus modules.
|
|
22
22
|
|
|
23
|
-
Uses
|
|
24
|
-
for
|
|
23
|
+
Uses ConbusProtocol to provide light level query functionality
|
|
24
|
+
for reading the current light level configuration from module outputs.
|
|
25
25
|
"""
|
|
26
26
|
|
|
27
27
|
def __init__(
|
|
@@ -30,7 +30,13 @@ class ConbusLightlevelGetService(ConbusDatapointService):
|
|
|
30
30
|
cli_config: ConbusClientConfig,
|
|
31
31
|
reactor: PosixReactorBase,
|
|
32
32
|
) -> None:
|
|
33
|
-
"""Initialize the Conbus
|
|
33
|
+
"""Initialize the Conbus lightlevel get service.
|
|
34
|
+
|
|
35
|
+
Args:
|
|
36
|
+
telegram_service: Service for parsing telegrams.
|
|
37
|
+
cli_config: Configuration for Conbus client connection.
|
|
38
|
+
reactor: Twisted reactor for event loop.
|
|
39
|
+
"""
|
|
34
40
|
super().__init__(telegram_service, cli_config, reactor)
|
|
35
41
|
self.output_number: int = 0
|
|
36
42
|
self.service_callback: Optional[Callable[[ConbusLightlevelResponse], None]] = (
|
|
@@ -43,7 +49,11 @@ class ConbusLightlevelGetService(ConbusDatapointService):
|
|
|
43
49
|
def finish_service_callback(
|
|
44
50
|
self, datapoint_response: ConbusDatapointResponse
|
|
45
51
|
) -> None:
|
|
52
|
+
"""Process datapoint response and extract light level.
|
|
46
53
|
|
|
54
|
+
Args:
|
|
55
|
+
datapoint_response: The datapoint response from the module.
|
|
56
|
+
"""
|
|
47
57
|
self.logger.debug("Parsing datapoint response")
|
|
48
58
|
|
|
49
59
|
level = 0
|
|
@@ -79,17 +89,15 @@ class ConbusLightlevelGetService(ConbusDatapointService):
|
|
|
79
89
|
finish_callback: Callable[[ConbusLightlevelResponse], None],
|
|
80
90
|
timeout_seconds: Optional[float] = None,
|
|
81
91
|
) -> None:
|
|
82
|
-
"""
|
|
83
|
-
Get the current auto report status for a specific module.
|
|
92
|
+
"""Get the current light level for a specific module output.
|
|
84
93
|
|
|
85
94
|
Args:
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
95
|
+
serial_number: 10-digit module serial number.
|
|
96
|
+
output_number: Output module number.
|
|
97
|
+
finish_callback: Callback function to call when the light level is received.
|
|
98
|
+
timeout_seconds: Timeout in seconds.
|
|
91
99
|
"""
|
|
92
|
-
self.logger.info("Starting
|
|
100
|
+
self.logger.info("Starting get_light_level")
|
|
93
101
|
if timeout_seconds:
|
|
94
102
|
self.timeout_seconds = timeout_seconds
|
|
95
103
|
self.serial_number = serial_number
|