Skip to content

Commit 16ce86c

Browse files
committed
fix: rollback more of the pydantic-xml changes
1 parent 3039252 commit 16ce86c

8 files changed

Lines changed: 161 additions & 176 deletions

File tree

pyomnilogic_local/api/protocol.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ async def _receive_file(self) -> str:
363363
# If the response is too large, the controller will send a LeadMessage indicating how many follow-up messages will be sent
364364
if message.type is MessageType.MSP_LEADMESSAGE:
365365
try:
366-
leadmsg = LeadMessage.from_xml(message.payload[:-1])
366+
leadmsg = LeadMessage.model_validate(ET.fromstring(message.payload[:-1]))
367367
except Exception as exc:
368368
raise OmniFragmentationException(f"Failed to parse LeadMessage: {exc}") from exc
369369

pyomnilogic_local/cli/pcap_utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
from __future__ import annotations
99

10+
import xml.etree.ElementTree as ET
1011
import zlib
1112
from collections import defaultdict
1213
from typing import Any
@@ -146,7 +147,7 @@ def process_pcap_messages(packets: Any) -> list[tuple[str, str, OmniLogicMessage
146147

147148
# Check if we have all the blocks
148149
lead_msg = message_sequences[matching_seq][0]
149-
lead_data = LeadMessage.from_xml(lead_msg.payload[:-1])
150+
lead_data = LeadMessage.model_validate(ET.fromstring(lead_msg.payload[:-1]))
150151

151152
# We have LeadMessage + all BlockMessages
152153
if len(message_sequences[matching_seq]) == lead_data.msg_block_count + 1:

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ dependencies = [
1414
"pydantic >=2.0.0,<3.0.0",
1515
"click >=8.0.0,<8.4.0",
1616
"xmltodict >=1.0.2,<2.0.0",
17-
"pydantic-xml>=2.18.0",
1817
]
1918

2019
[project.scripts]

tests/test_chlorinator_bitmask.py

Lines changed: 61 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,17 @@ def test_chlorinator_status_decoding() -> None:
1313
# Bit 7: K2_ACTIVE (128)
1414
# Total: 2 + 4 + 128 = 134
1515
data = {
16-
"system_id": 5,
17-
"status_raw": 134,
18-
"instant_salt_level": 4082,
19-
"avg_salt_level": 4042,
20-
"chlr_alert_raw": 0,
21-
"chlr_error_raw": 0,
22-
"sc_mode": 0,
23-
"operating_state": 1,
24-
"timed_percent": 70,
25-
"operating_mode": 1,
26-
"enable": True,
16+
"@systemId": 5,
17+
"@status": 134,
18+
"@instantSaltLevel": 4082,
19+
"@avgSaltLevel": 4042,
20+
"@chlrAlert": 0,
21+
"@chlrError": 0,
22+
"@scMode": 0,
23+
"@operatingState": 1,
24+
"@Timed-Percent": 70,
25+
"@operatingMode": 1,
26+
"@enable": True,
2727
}
2828

2929
chlorinator = TelemetryChlorinator.model_validate(data)
@@ -47,16 +47,16 @@ def test_chlorinator_alert_decoding() -> None:
4747
# Create a chlorinator with chlrAlert = 32 (0b00100000)
4848
# Bit 5: CELL_TEMP_SCALEBACK (32)
4949
data = {
50-
"system_id": 5,
51-
"status_raw": 2, # ALERT_PRESENT
52-
"instant_salt_level": 4082,
53-
"avg_salt_level": 4042,
54-
"chlr_alert_raw": 32,
55-
"chlr_error_raw": 0,
56-
"sc_mode": 0,
57-
"operating_state": 1,
58-
"operating_mode": 1,
59-
"enable": True,
50+
"@systemId": 5,
51+
"@status": 2, # ALERT_PRESENT
52+
"@instantSaltLevel": 4082,
53+
"@avgSaltLevel": 4042,
54+
"@chlrAlert": 32,
55+
"@chlrError": 0,
56+
"@scMode": 0,
57+
"@operatingState": 1,
58+
"@operatingMode": 1,
59+
"@enable": True,
6060
}
6161

6262
chlorinator = TelemetryChlorinator.model_validate(data)
@@ -77,16 +77,16 @@ def test_chlorinator_error_decoding() -> None:
7777
# Bit 8: K1_RELAY_SHORT (256)
7878
# Total: 1 + 256 = 257
7979
data = {
80-
"system_id": 5,
81-
"status_raw": 1, # ERROR_PRESENT
82-
"instant_salt_level": 4082,
83-
"avg_salt_level": 4042,
84-
"chlr_alert_raw": 0,
85-
"chlr_error_raw": 257,
86-
"sc_mode": 0,
87-
"operating_state": 1,
88-
"operating_mode": 1,
89-
"enable": True,
80+
"@systemId": 5,
81+
"@status": 1, # ERROR_PRESENT
82+
"@instantSaltLevel": 4082,
83+
"@avgSaltLevel": 4042,
84+
"@chlrAlert": 0,
85+
"@chlrError": 257,
86+
"@scMode": 0,
87+
"@operatingState": 1,
88+
"@operatingMode": 1,
89+
"@enable": True,
9090
}
9191

9292
chlorinator = TelemetryChlorinator.model_validate(data)
@@ -104,16 +104,16 @@ def test_chlorinator_error_decoding() -> None:
104104
def test_chlorinator_no_flags() -> None:
105105
"""Test chlorinator with no status/alert/error flags set."""
106106
data = {
107-
"system_id": 5,
108-
"status_raw": 0,
109-
"instant_salt_level": 4082,
110-
"avg_salt_level": 4042,
111-
"chlr_alert_raw": 0,
112-
"chlr_error_raw": 0,
113-
"sc_mode": 0,
114-
"operating_state": 1,
115-
"operating_mode": 1,
116-
"enable": True,
107+
"@systemId": 5,
108+
"@status": 0,
109+
"@instantSaltLevel": 4082,
110+
"@avgSaltLevel": 4042,
111+
"@chlrAlert": 0,
112+
"@chlrError": 0,
113+
"@scMode": 0,
114+
"@operatingState": 1,
115+
"@operatingMode": 1,
116+
"@enable": True,
117117
}
118118

119119
chlorinator = TelemetryChlorinator.model_validate(data)
@@ -133,16 +133,16 @@ def test_chlorinator_complex_alerts() -> None:
133133
# Bit 6: BOARD_TEMP_HIGH (64)
134134
# Total: 1 + 2 + 64 = 67
135135
data = {
136-
"system_id": 5,
137-
"status_raw": 2,
138-
"instant_salt_level": 4082,
139-
"avg_salt_level": 4042,
140-
"chlr_alert_raw": 67,
141-
"chlr_error_raw": 0,
142-
"sc_mode": 0,
143-
"operating_state": 1,
144-
"operating_mode": 1,
145-
"enable": True,
136+
"@systemId": 5,
137+
"@status": 2,
138+
"@instantSaltLevel": 4082,
139+
"@avgSaltLevel": 4042,
140+
"@chlrAlert": 67,
141+
"@chlrError": 0,
142+
"@scMode": 0,
143+
"@operatingState": 1,
144+
"@operatingMode": 1,
145+
"@enable": True,
146146
}
147147

148148
chlorinator = TelemetryChlorinator.model_validate(data)
@@ -158,16 +158,16 @@ def test_chlorinator_all_status_flags() -> None:
158158
"""Test chlorinator with all status flags set."""
159159
# status = 255 (0b11111111) - all 8 bits set
160160
data = {
161-
"system_id": 5,
162-
"status_raw": 255,
163-
"instant_salt_level": 4082,
164-
"avg_salt_level": 4042,
165-
"chlr_alert_raw": 0,
166-
"chlr_error_raw": 0,
167-
"sc_mode": 0,
168-
"operating_state": 1,
169-
"operating_mode": 1,
170-
"enable": True,
161+
"@systemId": 5,
162+
"@status": 255,
163+
"@instantSaltLevel": 4082,
164+
"@avgSaltLevel": 4042,
165+
"@chlrAlert": 0,
166+
"@chlrError": 0,
167+
"@scMode": 0,
168+
"@operatingState": 1,
169+
"@operatingMode": 1,
170+
"@enable": True,
171171
}
172172

173173
chlorinator = TelemetryChlorinator.model_validate(data)

0 commit comments

Comments
 (0)