conson-xp 1.1.0__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.
Files changed (167) hide show
  1. {conson_xp-1.1.0.dist-info → conson_xp-1.2.0.dist-info}/METADATA +1 -1
  2. conson_xp-1.2.0.dist-info/RECORD +181 -0
  3. xp/__init__.py +4 -3
  4. xp/api/main.py +18 -3
  5. xp/api/models/api.py +13 -2
  6. xp/api/models/discover.py +12 -2
  7. xp/api/routers/conbus_blink.py +18 -6
  8. xp/api/routers/conbus_custom.py +11 -3
  9. xp/api/routers/conbus_datapoint.py +10 -3
  10. xp/api/routers/conbus_output.py +29 -9
  11. xp/api/routers/errors.py +6 -5
  12. xp/cli/__init__.py +1 -1
  13. xp/cli/commands/__init__.py +1 -0
  14. xp/cli/commands/api.py +1 -5
  15. xp/cli/commands/api_start_commands.py +14 -8
  16. xp/cli/commands/conbus/conbus.py +9 -37
  17. xp/cli/commands/conbus/conbus_actiontable_commands.py +21 -1
  18. xp/cli/commands/conbus/conbus_autoreport_commands.py +21 -11
  19. xp/cli/commands/conbus/conbus_blink_commands.py +53 -21
  20. xp/cli/commands/conbus/conbus_config_commands.py +7 -4
  21. xp/cli/commands/conbus/conbus_custom_commands.py +13 -4
  22. xp/cli/commands/conbus/conbus_datapoint_commands.py +28 -8
  23. xp/cli/commands/conbus/conbus_discover_commands.py +15 -4
  24. xp/cli/commands/conbus/conbus_lightlevel_commands.py +50 -11
  25. xp/cli/commands/conbus/conbus_linknumber_commands.py +21 -11
  26. xp/cli/commands/conbus/conbus_msactiontable_commands.py +25 -1
  27. xp/cli/commands/conbus/conbus_output_commands.py +46 -12
  28. xp/cli/commands/conbus/conbus_raw_commands.py +17 -6
  29. xp/cli/commands/conbus/conbus_receive_commands.py +15 -7
  30. xp/cli/commands/conbus/conbus_scan_commands.py +17 -4
  31. xp/cli/commands/file_commands.py +26 -15
  32. xp/cli/commands/homekit/homekit.py +14 -8
  33. xp/cli/commands/homekit/homekit_start_commands.py +5 -5
  34. xp/cli/commands/module_commands.py +26 -19
  35. xp/cli/commands/reverse_proxy_commands.py +24 -18
  36. xp/cli/commands/server/server_commands.py +18 -18
  37. xp/cli/commands/telegram/telegram.py +4 -12
  38. xp/cli/commands/telegram/telegram_blink_commands.py +10 -8
  39. xp/cli/commands/telegram/telegram_checksum_commands.py +19 -8
  40. xp/cli/commands/telegram/telegram_discover_commands.py +2 -4
  41. xp/cli/commands/telegram/telegram_linknumber_commands.py +11 -8
  42. xp/cli/commands/telegram/telegram_parse_commands.py +10 -9
  43. xp/cli/commands/telegram/telegram_version_commands.py +8 -4
  44. xp/cli/main.py +5 -1
  45. xp/cli/utils/click_tree.py +23 -3
  46. xp/cli/utils/datapoint_type_choice.py +20 -0
  47. xp/cli/utils/decorators.py +165 -14
  48. xp/cli/utils/error_handlers.py +49 -18
  49. xp/cli/utils/formatters.py +95 -10
  50. xp/cli/utils/serial_number_type.py +18 -0
  51. xp/cli/utils/system_function_choice.py +20 -0
  52. xp/cli/utils/xp_module_type.py +20 -0
  53. xp/connection/__init__.py +1 -1
  54. xp/connection/exceptions.py +5 -5
  55. xp/models/__init__.py +1 -1
  56. xp/models/actiontable/__init__.py +1 -0
  57. xp/models/actiontable/actiontable.py +17 -1
  58. xp/models/actiontable/msactiontable_xp20.py +10 -0
  59. xp/models/actiontable/msactiontable_xp24.py +20 -3
  60. xp/models/actiontable/msactiontable_xp33.py +27 -4
  61. xp/models/conbus/__init__.py +1 -0
  62. xp/models/conbus/conbus.py +34 -4
  63. xp/models/conbus/conbus_autoreport.py +20 -2
  64. xp/models/conbus/conbus_blink.py +22 -2
  65. xp/models/conbus/conbus_client_config.py +22 -1
  66. xp/models/conbus/conbus_connection_status.py +16 -2
  67. xp/models/conbus/conbus_custom.py +21 -2
  68. xp/models/conbus/conbus_datapoint.py +22 -2
  69. xp/models/conbus/conbus_discover.py +18 -2
  70. xp/models/conbus/conbus_lightlevel.py +20 -2
  71. xp/models/conbus/conbus_linknumber.py +20 -2
  72. xp/models/conbus/conbus_output.py +22 -2
  73. xp/models/conbus/conbus_raw.py +17 -2
  74. xp/models/conbus/conbus_receive.py +16 -2
  75. xp/models/homekit/__init__.py +1 -0
  76. xp/models/homekit/homekit_accessory.py +15 -1
  77. xp/models/homekit/homekit_config.py +52 -0
  78. xp/models/homekit/homekit_conson_config.py +32 -0
  79. xp/models/log_entry.py +49 -9
  80. xp/models/protocol/__init__.py +1 -0
  81. xp/models/protocol/conbus_protocol.py +130 -21
  82. xp/models/telegram/__init__.py +1 -0
  83. xp/models/telegram/action_type.py +16 -2
  84. xp/models/telegram/datapoint_type.py +36 -2
  85. xp/models/telegram/event_telegram.py +46 -10
  86. xp/models/telegram/event_type.py +8 -1
  87. xp/models/telegram/input_action_type.py +34 -2
  88. xp/models/telegram/input_type.py +9 -1
  89. xp/models/telegram/module_type.py +69 -19
  90. xp/models/telegram/module_type_code.py +43 -1
  91. xp/models/telegram/output_telegram.py +30 -6
  92. xp/models/telegram/reply_telegram.py +56 -11
  93. xp/models/telegram/system_function.py +35 -3
  94. xp/models/telegram/system_telegram.py +18 -4
  95. xp/models/telegram/telegram.py +12 -3
  96. xp/models/telegram/telegram_type.py +8 -1
  97. xp/models/telegram/timeparam_type.py +27 -0
  98. xp/models/write_config_type.py +17 -2
  99. xp/services/__init__.py +1 -1
  100. xp/services/conbus/__init__.py +1 -0
  101. xp/services/conbus/actiontable/__init__.py +1 -0
  102. xp/services/conbus/actiontable/actiontable_service.py +33 -2
  103. xp/services/conbus/actiontable/msactiontable_service.py +40 -3
  104. xp/services/conbus/actiontable/msactiontable_xp24_serializer.py +36 -4
  105. xp/services/conbus/actiontable/msactiontable_xp33_serializer.py +45 -5
  106. xp/services/conbus/conbus_autoreport_get_service.py +17 -8
  107. xp/services/conbus/conbus_autoreport_set_service.py +29 -16
  108. xp/services/conbus/conbus_blink_all_service.py +40 -21
  109. xp/services/conbus/conbus_blink_service.py +37 -13
  110. xp/services/conbus/conbus_custom_service.py +29 -13
  111. xp/services/conbus/conbus_datapoint_queryall_service.py +40 -16
  112. xp/services/conbus/conbus_datapoint_service.py +33 -12
  113. xp/services/conbus/conbus_discover_service.py +43 -7
  114. xp/services/conbus/conbus_lightlevel_get_service.py +22 -14
  115. xp/services/conbus/conbus_lightlevel_set_service.py +40 -20
  116. xp/services/conbus/conbus_linknumber_get_service.py +18 -10
  117. xp/services/conbus/conbus_linknumber_set_service.py +34 -8
  118. xp/services/conbus/conbus_output_service.py +33 -13
  119. xp/services/conbus/conbus_raw_service.py +36 -16
  120. xp/services/conbus/conbus_receive_service.py +38 -6
  121. xp/services/conbus/conbus_scan_service.py +44 -18
  122. xp/services/homekit/__init__.py +1 -0
  123. xp/services/homekit/homekit_cache_service.py +31 -6
  124. xp/services/homekit/homekit_conbus_service.py +33 -2
  125. xp/services/homekit/homekit_config_validator.py +97 -15
  126. xp/services/homekit/homekit_conson_validator.py +51 -7
  127. xp/services/homekit/homekit_dimminglight.py +47 -1
  128. xp/services/homekit/homekit_dimminglight_service.py +35 -1
  129. xp/services/homekit/homekit_hap_service.py +71 -18
  130. xp/services/homekit/homekit_lightbulb.py +35 -1
  131. xp/services/homekit/homekit_lightbulb_service.py +30 -2
  132. xp/services/homekit/homekit_module_service.py +23 -1
  133. xp/services/homekit/homekit_outlet.py +47 -1
  134. xp/services/homekit/homekit_outlet_service.py +44 -2
  135. xp/services/homekit/homekit_service.py +113 -19
  136. xp/services/log_file_service.py +37 -41
  137. xp/services/module_type_service.py +26 -5
  138. xp/services/protocol/__init__.py +1 -1
  139. xp/services/protocol/conbus_protocol.py +110 -16
  140. xp/services/protocol/protocol_factory.py +40 -0
  141. xp/services/protocol/telegram_protocol.py +38 -7
  142. xp/services/reverse_proxy_service.py +79 -14
  143. xp/services/server/__init__.py +1 -0
  144. xp/services/server/base_server_service.py +102 -14
  145. xp/services/server/cp20_server_service.py +12 -4
  146. xp/services/server/server_service.py +26 -11
  147. xp/services/server/xp130_server_service.py +11 -3
  148. xp/services/server/xp20_server_service.py +11 -3
  149. xp/services/server/xp230_server_service.py +11 -3
  150. xp/services/server/xp24_server_service.py +33 -6
  151. xp/services/server/xp33_server_service.py +41 -8
  152. xp/services/telegram/__init__.py +1 -0
  153. xp/services/telegram/telegram_blink_service.py +19 -31
  154. xp/services/telegram/telegram_checksum_service.py +10 -10
  155. xp/services/telegram/telegram_discover_service.py +58 -29
  156. xp/services/telegram/telegram_link_number_service.py +27 -40
  157. xp/services/telegram/telegram_output_service.py +46 -49
  158. xp/services/telegram/telegram_service.py +41 -41
  159. xp/services/telegram/telegram_version_service.py +4 -2
  160. xp/utils/__init__.py +1 -1
  161. xp/utils/dependencies.py +0 -1
  162. xp/utils/serialization.py +6 -0
  163. xp/utils/time_utils.py +6 -11
  164. conson_xp-1.1.0.dist-info/RECORD +0 -181
  165. {conson_xp-1.1.0.dist-info → conson_xp-1.2.0.dist-info}/WHEEL +0 -0
  166. {conson_xp-1.1.0.dist-info → conson_xp-1.2.0.dist-info}/entry_points.txt +0 -0
  167. {conson_xp-1.1.0.dist-info → conson_xp-1.2.0.dist-info}/licenses/LICENSE +0 -0
@@ -11,7 +11,7 @@ from xp.utils.checksum import calculate_checksum
11
11
 
12
12
 
13
13
  class BlinkError(Exception):
14
- """Raised when blink/unblink operations fail"""
14
+ """Raised when blink/unblink operations fail."""
15
15
 
16
16
  pass
17
17
 
@@ -26,24 +26,22 @@ class TelegramBlinkService:
26
26
  """
27
27
 
28
28
  def __init__(self) -> None:
29
- """Initialize the blink service"""
29
+ """Initialize the blink service."""
30
30
  pass
31
31
 
32
32
  @staticmethod
33
33
  def generate_blink_telegram(serial_number: str, on_or_off: str) -> str:
34
- """
35
- Generate a telegram to start blinking a module's LED.
34
+ """Generate a telegram to start blinking a module's LED.
36
35
 
37
36
  Args:
38
- serial_number: The 10-digit module serial number
37
+ serial_number: The 10-digit module serial number.
38
+ on_or_off: The action to perform ('on' for blink, 'off' for unblink).
39
39
 
40
40
  Returns:
41
- Formatted telegram string (e.g., "<S0012345008F05D00FN>")
41
+ Formatted telegram string (e.g., "<S0012345008F05D00FN>").
42
42
 
43
43
  Raises:
44
- BlinkError: If parameters are invalid
45
- :param serial_number:
46
- :param on_or_off:
44
+ BlinkError: If parameters are invalid.
47
45
  """
48
46
  # Validate serial number
49
47
  if not serial_number or len(serial_number) != 10:
@@ -68,17 +66,13 @@ class TelegramBlinkService:
68
66
  return telegram
69
67
 
70
68
  def create_blink_telegram_object(self, serial_number: str) -> SystemTelegram:
71
- """
72
- Create a SystemTelegram object for blinking LED.
69
+ """Create a SystemTelegram object for blinking LED.
73
70
 
74
71
  Args:
75
- serial_number: The 10-digit module serial number
72
+ serial_number: The 10-digit module serial number.
76
73
 
77
74
  Returns:
78
- SystemTelegram object representing the blink command
79
-
80
- Raises:
81
- BlinkError: If parameters are invalid
75
+ SystemTelegram object representing the blink command.
82
76
  """
83
77
  raw_telegram = self.generate_blink_telegram(serial_number, "on")
84
78
 
@@ -96,17 +90,13 @@ class TelegramBlinkService:
96
90
  return telegram
97
91
 
98
92
  def create_unblink_telegram_object(self, serial_number: str) -> SystemTelegram:
99
- """
100
- Create a SystemTelegram object for unblink LED.
93
+ """Create a SystemTelegram object for unblink LED.
101
94
 
102
95
  Args:
103
- serial_number: The 10-digit module serial number
96
+ serial_number: The 10-digit module serial number.
104
97
 
105
98
  Returns:
106
- SystemTelegram object representing the unblink command
107
-
108
- Raises:
109
- BlinkError: If parameters are invalid
99
+ SystemTelegram object representing the unblink command.
110
100
  """
111
101
  raw_telegram = self.generate_blink_telegram(serial_number, "off")
112
102
 
@@ -125,26 +115,24 @@ class TelegramBlinkService:
125
115
 
126
116
  @staticmethod
127
117
  def is_ack_response(reply_telegram: ReplyTelegram) -> bool:
128
- """
129
- Check if a reply telegram is an ACK response.
118
+ """Check if a reply telegram is an ACK response.
130
119
 
131
120
  Args:
132
- reply_telegram: Reply telegram to check
121
+ reply_telegram: Reply telegram to check.
133
122
 
134
123
  Returns:
135
- True if this is an ACK response (F18D), False otherwise
124
+ True if this is an ACK response (F18D), False otherwise.
136
125
  """
137
126
  return reply_telegram.system_function == SystemFunction.ACK
138
127
 
139
128
  @staticmethod
140
129
  def is_nak_response(reply_telegram: ReplyTelegram) -> bool:
141
- """
142
- Check if a reply telegram is a NAK response.
130
+ """Check if a reply telegram is a NAK response.
143
131
 
144
132
  Args:
145
- reply_telegram: Reply telegram to check
133
+ reply_telegram: Reply telegram to check.
146
134
 
147
135
  Returns:
148
- True if this is a NAK response (F19D), False otherwise
136
+ True if this is a NAK response (F19D), False otherwise.
149
137
  """
150
138
  return reply_telegram.system_function == SystemFunction.NAK
@@ -22,10 +22,10 @@ class TelegramChecksumService:
22
22
  """Calculate simple XOR checksum for string data.
23
23
 
24
24
  Args:
25
- data: String data to calculate checksum for
25
+ data: String data to calculate checksum for.
26
26
 
27
27
  Returns:
28
- Response object with checksum result
28
+ Response object with checksum result.
29
29
  """
30
30
  try:
31
31
  checksum = calculate_checksum(data)
@@ -45,10 +45,10 @@ class TelegramChecksumService:
45
45
  """Calculate CRC32 checksum for data.
46
46
 
47
47
  Args:
48
- data: String or bytes data to calculate checksum for
48
+ data: String or bytes data to calculate checksum for.
49
49
 
50
50
  Returns:
51
- Response object with checksum result
51
+ Response object with checksum result.
52
52
  """
53
53
  try:
54
54
  # Convert string to bytes if needed
@@ -82,11 +82,11 @@ class TelegramChecksumService:
82
82
  """Validate data against expected simple checksum.
83
83
 
84
84
  Args:
85
- data: Original data
86
- expected_checksum: Expected checksum value
85
+ data: Original data.
86
+ expected_checksum: Expected checksum value.
87
87
 
88
88
  Returns:
89
- Response object with validation result
89
+ Response object with validation result.
90
90
  """
91
91
  try:
92
92
  calculated_checksum = calculate_checksum(data)
@@ -114,11 +114,11 @@ class TelegramChecksumService:
114
114
  """Validate data against expected CRC32 checksum.
115
115
 
116
116
  Args:
117
- data: Original data (string or bytes)
118
- expected_checksum: Expected CRC32 checksum value
117
+ data: Original data (string or bytes).
118
+ expected_checksum: Expected CRC32 checksum value.
119
119
 
120
120
  Returns:
121
- Response object with validation result
121
+ Response object with validation result.
122
122
  """
123
123
  try:
124
124
  # Convert string to bytes if needed
@@ -13,30 +13,51 @@ from xp.utils.checksum import calculate_checksum
13
13
 
14
14
 
15
15
  class DiscoverError(Exception):
16
- """Raised when discover operations fail"""
16
+ """Raised when discover operations fail."""
17
17
 
18
18
  pass
19
19
 
20
20
 
21
21
  class DeviceInfo:
22
- """Information about a discovered device"""
22
+ """Information about a discovered device."""
23
23
 
24
24
  def __init__(
25
25
  self, serial_number: str, checksum_valid: bool = True, raw_telegram: str = ""
26
26
  ):
27
+ """Initialize device info.
28
+
29
+ Args:
30
+ serial_number: 10-digit module serial number.
31
+ checksum_valid: Whether the telegram checksum is valid.
32
+ raw_telegram: Raw telegram string.
33
+ """
27
34
  self.serial_number = serial_number
28
35
  self.checksum_valid = checksum_valid
29
36
  self.raw_telegram = raw_telegram
30
37
 
31
38
  def __str__(self) -> str:
39
+ """Return string representation of device.
40
+
41
+ Returns:
42
+ String with serial number and checksum status.
43
+ """
32
44
  status = "✓" if self.checksum_valid else "✗"
33
45
  return f"Device {self.serial_number} ({status})"
34
46
 
35
47
  def __repr__(self) -> str:
48
+ """Return repr representation of device.
49
+
50
+ Returns:
51
+ DeviceInfo constructor representation.
52
+ """
36
53
  return f"DeviceInfo(serial='{self.serial_number}', checksum_valid={self.checksum_valid})"
37
54
 
38
55
  def to_dict(self) -> dict:
39
- """Convert to dictionary for JSON serialization"""
56
+ """Convert to dictionary for JSON serialization.
57
+
58
+ Returns:
59
+ Dictionary with device information.
60
+ """
40
61
  return {
41
62
  "serial_number": self.serial_number,
42
63
  "checksum_valid": self.checksum_valid,
@@ -54,7 +75,7 @@ class TelegramDiscoverService:
54
75
  """
55
76
 
56
77
  def __init__(self) -> None:
57
- """Initialize the discover service"""
78
+ """Initialize the discover service."""
58
79
  pass
59
80
 
60
81
  @staticmethod
@@ -78,11 +99,10 @@ class TelegramDiscoverService:
78
99
  return telegram
79
100
 
80
101
  def create_discover_telegram_object(self) -> SystemTelegram:
81
- """
82
- Create a SystemTelegram object for discover broadcast.
102
+ """Create a SystemTelegram object for discover broadcast.
83
103
 
84
104
  Returns:
85
- SystemTelegram object representing the discover command
105
+ SystemTelegram object representing the discover command.
86
106
  """
87
107
  raw_telegram = self.generate_discover_telegram()
88
108
 
@@ -101,20 +121,26 @@ class TelegramDiscoverService:
101
121
 
102
122
  @staticmethod
103
123
  def is_discover_response(reply_telegram: ReplyTelegram) -> bool:
104
- """
105
- Check if a reply telegram is a discover response.
124
+ """Check if a reply telegram is a discover response.
106
125
 
107
126
  Args:
108
- reply_telegram: Reply telegram to check
127
+ reply_telegram: Reply telegram to check.
109
128
 
110
129
  Returns:
111
- True if this is a discover response, False otherwise
130
+ True if this is a discover response, False otherwise.
112
131
  """
113
132
  return reply_telegram.system_function == SystemFunction.DISCOVERY
114
133
 
115
134
  @staticmethod
116
135
  def _generate_discover_response(serial_number: str) -> str:
117
- """Generate discover response telegram for a device"""
136
+ """Generate discover response telegram for a device.
137
+
138
+ Args:
139
+ serial_number: 10-digit module serial number.
140
+
141
+ Returns:
142
+ Formatted discover response telegram.
143
+ """
118
144
  # Format: <R{serial}F01D{checksum}>
119
145
  data_part = f"R{serial_number}F01D"
120
146
  checksum = calculate_checksum(data_part)
@@ -123,14 +149,13 @@ class TelegramDiscoverService:
123
149
 
124
150
  @staticmethod
125
151
  def get_unique_devices(devices: List[DeviceInfo]) -> List[DeviceInfo]:
126
- """
127
- Filter out duplicate devices based on serial number.
152
+ """Filter out duplicate devices based on serial number.
128
153
 
129
154
  Args:
130
- devices: List of discovered devices
155
+ devices: List of discovered devices.
131
156
 
132
157
  Returns:
133
- List of unique devices (first occurrence of each serial number)
158
+ List of unique devices (first occurrence of each serial number).
134
159
  """
135
160
  seen_serials: Set[str] = set()
136
161
  unique_devices = []
@@ -144,14 +169,13 @@ class TelegramDiscoverService:
144
169
 
145
170
  @staticmethod
146
171
  def validate_discover_response_format(raw_telegram: str) -> bool:
147
- """
148
- Validate if a raw telegram matches discover response format.
172
+ """Validate if a raw telegram matches discover response format.
149
173
 
150
174
  Args:
151
- raw_telegram: Raw telegram string to validate
175
+ raw_telegram: Raw telegram string to validate.
152
176
 
153
177
  Returns:
154
- True if format matches discover response pattern
178
+ True if format matches discover response pattern.
155
179
  """
156
180
  # Discover response format: <R{10-digit-serial}F01D{2-char-checksum}>
157
181
  import re
@@ -163,14 +187,13 @@ class TelegramDiscoverService:
163
187
  return match is not None
164
188
 
165
189
  def generate_discover_summary(self, devices: List[DeviceInfo]) -> dict:
166
- """
167
- Generate a summary of a discover results.
190
+ """Generate a summary of a discover results.
168
191
 
169
192
  Args:
170
- devices: List of discovered devices
193
+ devices: List of discovered devices.
171
194
 
172
195
  Returns:
173
- Dictionary with discover statistics
196
+ Dictionary with discover statistics.
174
197
  """
175
198
  unique_devices = self.get_unique_devices(devices)
176
199
  valid_devices = [d for d in unique_devices if d.checksum_valid]
@@ -200,14 +223,13 @@ class TelegramDiscoverService:
200
223
  }
201
224
 
202
225
  def format_discover_results(self, devices: List[DeviceInfo]) -> str:
203
- """
204
- Format discover results for human-readable output.
226
+ """Format discover results for human-readable output.
205
227
 
206
228
  Args:
207
- devices: List of discovered devices
229
+ devices: List of discovered devices.
208
230
 
209
231
  Returns:
210
- Formatted string summary
232
+ Formatted string summary.
211
233
  """
212
234
  if not devices:
213
235
  return "No devices discovered"
@@ -241,7 +263,14 @@ class TelegramDiscoverService:
241
263
 
242
264
  @staticmethod
243
265
  def is_discover_request(telegram: SystemTelegram) -> bool:
244
- """Check if telegram is a discover request"""
266
+ """Check if telegram is a discover request.
267
+
268
+ Args:
269
+ telegram: System telegram to check.
270
+
271
+ Returns:
272
+ True if this is a discover request, False otherwise.
273
+ """
245
274
  return (
246
275
  telegram.system_function == SystemFunction.DISCOVERY
247
276
  and telegram.serial_number == "0000000000"
@@ -15,7 +15,7 @@ from xp.utils.checksum import calculate_checksum
15
15
 
16
16
 
17
17
  class LinkNumberError(Exception):
18
- """Raised when link number operations fail"""
18
+ """Raised when link number operations fail."""
19
19
 
20
20
  pass
21
21
 
@@ -29,23 +29,22 @@ class LinkNumberService:
29
29
  """
30
30
 
31
31
  def __init__(self) -> None:
32
- """Initialize the link number service"""
32
+ """Initialize the link number service."""
33
33
  pass
34
34
 
35
35
  @staticmethod
36
36
  def generate_set_link_number_telegram(serial_number: str, link_number: int) -> str:
37
- """
38
- Generate a telegram to set a module's link number.
37
+ """Generate a telegram to set a module's link number.
39
38
 
40
39
  Args:
41
- serial_number: The 10-digit module serial number
42
- link_number: The link number to set (0-99)
40
+ serial_number: The 10-digit module serial number.
41
+ link_number: The link number to set (0-99).
43
42
 
44
43
  Returns:
45
- Formatted telegram string (e.g., "<S0012345005F04D0425FO>")
44
+ Formatted telegram string (e.g., "<S0012345005F04D0425FO>").
46
45
 
47
46
  Raises:
48
- LinkNumberError: If parameters are invalid
47
+ LinkNumberError: If parameters are invalid.
49
48
  """
50
49
  # Validate serial number
51
50
  if not serial_number or len(serial_number) != 10:
@@ -80,17 +79,16 @@ class LinkNumberService:
80
79
 
81
80
  @staticmethod
82
81
  def generate_read_link_number_telegram(serial_number: str) -> str:
83
- """
84
- Generate a telegram to read a module's current link number.
82
+ """Generate a telegram to read a module's current link number.
85
83
 
86
84
  Args:
87
- serial_number: The 10-digit module serial number
85
+ serial_number: The 10-digit module serial number.
88
86
 
89
87
  Returns:
90
- Formatted telegram string for reading link number
88
+ Formatted telegram string for reading link number.
91
89
 
92
90
  Raises:
93
- LinkNumberError: If serial number is invalid
91
+ LinkNumberError: If serial number is invalid.
94
92
  """
95
93
  # Validate serial number
96
94
  if not serial_number or len(serial_number) != 10:
@@ -117,18 +115,14 @@ class LinkNumberService:
117
115
  def create_set_link_number_telegram_object(
118
116
  self, serial_number: str, link_number: int
119
117
  ) -> SystemTelegram:
120
- """
121
- Create a SystemTelegram object for setting link number.
118
+ """Create a SystemTelegram object for setting link number.
122
119
 
123
120
  Args:
124
- serial_number: The 10-digit module serial number
125
- link_number: The link number to set (0-99)
121
+ serial_number: The 10-digit module serial number.
122
+ link_number: The link number to set (0-99).
126
123
 
127
124
  Returns:
128
- SystemTelegram object representing the set link number command
129
-
130
- Raises:
131
- LinkNumberError: If parameters are invalid
125
+ SystemTelegram object representing the set link number command.
132
126
  """
133
127
  raw_telegram = self.generate_set_link_number_telegram(
134
128
  serial_number, link_number
@@ -150,17 +144,13 @@ class LinkNumberService:
150
144
  def create_read_link_number_telegram_object(
151
145
  self, serial_number: str
152
146
  ) -> SystemTelegram:
153
- """
154
- Create a SystemTelegram object for reading link number.
147
+ """Create a SystemTelegram object for reading link number.
155
148
 
156
149
  Args:
157
- serial_number: The 10-digit module serial number
150
+ serial_number: The 10-digit module serial number.
158
151
 
159
152
  Returns:
160
- SystemTelegram object representing the read link number command
161
-
162
- Raises:
163
- LinkNumberError: If serial number is invalid
153
+ SystemTelegram object representing the read link number command.
164
154
  """
165
155
  raw_telegram = self.generate_read_link_number_telegram(serial_number)
166
156
 
@@ -179,14 +169,13 @@ class LinkNumberService:
179
169
 
180
170
  @staticmethod
181
171
  def parse_link_number_from_reply(reply_telegram: ReplyTelegram) -> Optional[int]:
182
- """
183
- Parse the link number value from a reply telegram.
172
+ """Parse the link number value from a reply telegram.
184
173
 
185
174
  Args:
186
- reply_telegram: Reply telegram containing link number data
175
+ reply_telegram: Reply telegram containing link number data.
187
176
 
188
177
  Returns:
189
- Link number if successfully parsed, None otherwise
178
+ Link number if successfully parsed, None otherwise.
190
179
  """
191
180
  if (
192
181
  reply_telegram.datapoint_type != DataPointType.LINK_NUMBER
@@ -204,26 +193,24 @@ class LinkNumberService:
204
193
 
205
194
  @staticmethod
206
195
  def is_ack_response(reply_telegram: ReplyTelegram) -> bool:
207
- """
208
- Check if a reply telegram is an ACK response.
196
+ """Check if a reply telegram is an ACK response.
209
197
 
210
198
  Args:
211
- reply_telegram: Reply telegram to check
199
+ reply_telegram: Reply telegram to check.
212
200
 
213
201
  Returns:
214
- True if this is an ACK response (F18D), False otherwise
202
+ True if this is an ACK response (F18D), False otherwise.
215
203
  """
216
204
  return reply_telegram.system_function == SystemFunction.ACK
217
205
 
218
206
  @staticmethod
219
207
  def is_nak_response(reply_telegram: ReplyTelegram) -> bool:
220
- """
221
- Check if a reply telegram is a NAK response.
208
+ """Check if a reply telegram is a NAK response.
222
209
 
223
210
  Args:
224
- reply_telegram: Reply telegram to check
211
+ reply_telegram: Reply telegram to check.
225
212
 
226
213
  Returns:
227
- True if this is a NAK response (F19D), False otherwise
214
+ True if this is a NAK response (F19D), False otherwise.
228
215
  """
229
216
  return reply_telegram.system_function == SystemFunction.NAK