66import xml .etree .ElementTree as ET
77from typing import Literal , overload
88
9- from .models .filter_diagnostics import FilterDiagnostics
10- from .models .mspconfig import MSPConfig
11- from .models .telemetry import Telemetry
12- from . models . util import to_pydantic
13- from .omnitypes import (
9+ from pyomnilogic_local .models .filter_diagnostics import FilterDiagnostics
10+ from pyomnilogic_local .models .mspconfig import MSPConfig
11+ from pyomnilogic_local .models .telemetry import Telemetry
12+
13+ from .. omnitypes import (
1414 ColorLogicBrightness ,
15- ColorLogicShow ,
15+ ColorLogicShow25 ,
16+ ColorLogicShow40 ,
17+ ColorLogicShowUCL ,
18+ ColorLogicShowUCLV2 ,
1619 ColorLogicSpeed ,
1720 HeaterMode ,
1821 MessageType ,
2326
2427
2528class OmniLogicAPI :
26- def __init__ (self , controller_ip : str , controller_port : int , response_timeout : float ) -> None :
29+ def __init__ (self , controller_ip : str , controller_port : int , response_timeout : float = 5.0 ) -> None :
2730 self .controller_ip = controller_ip
2831 self .controller_port = controller_port
2932 self .response_timeout = response_timeout
30- self ._loop = asyncio .get_running_loop ()
31- self ._protocol_factory = OmniLogicProtocol
33+ # self._loop = asyncio.get_running_loop()
34+ # self._protocol_factory = OmniLogicProtocol
3235
3336 @overload
3437 async def async_send_message (self , message_type : MessageType , message : str | None , need_response : Literal [True ]) -> str : ...
@@ -61,8 +64,13 @@ async def async_send_message(self, message_type: MessageType, message: str | Non
6164
6265 return resp
6366
64- @to_pydantic (pydantic_type = MSPConfig )
65- async def async_get_config (self ) -> str :
67+ @overload
68+ async def async_get_mspconfig (self , raw : Literal [True ]) -> str : ...
69+ @overload
70+ async def async_get_mspconfig (self , raw : Literal [False ]) -> MSPConfig : ...
71+ @overload
72+ async def async_get_mspconfig (self ) -> MSPConfig : ...
73+ async def async_get_mspconfig (self , raw : bool = False ) -> MSPConfig | str :
6674 """Retrieve the MSPConfig from the Omni, optionally parse it into a pydantic model.
6775
6876 Args:
@@ -78,14 +86,21 @@ async def async_get_config(self) -> str:
7886
7987 req_body = ET .tostring (body_element , xml_declaration = True , encoding = "unicode" )
8088
81- return await self .async_send_message (MessageType .REQUEST_CONFIGURATION , req_body , True )
89+ resp = await self .async_send_message (MessageType .REQUEST_CONFIGURATION , req_body , True )
8290
83- @to_pydantic (pydantic_type = FilterDiagnostics )
84- async def async_get_filter_diagnostics (
85- self ,
86- pool_id : int ,
87- equipment_id : int ,
88- ) -> str :
91+ if raw :
92+ return resp
93+ return MSPConfig .load_xml (resp )
94+
95+ @overload
96+ async def async_get_filter_diagnostics (self , pool_id : int , equipment_id : int , raw : Literal [True ]) -> str : ...
97+ @overload
98+ async def async_get_filter_diagnostics (self , pool_id : int , equipment_id : int , raw : Literal [False ]) -> FilterDiagnostics : ...
99+ @overload
100+ async def async_get_filter_diagnostics (self , pool_id : int , equipment_id : int ) -> FilterDiagnostics : ...
101+ @overload
102+ async def async_get_filter_diagnostics (self , pool_id : int , equipment_id : int , raw : bool ) -> FilterDiagnostics | str : ...
103+ async def async_get_filter_diagnostics (self , pool_id : int , equipment_id : int , raw : bool = False ) -> FilterDiagnostics | str :
89104 """Retrieve filter diagnostics from the Omni, optionally parse it into a pydantic model.
90105
91106 Args:
@@ -108,10 +123,19 @@ async def async_get_filter_diagnostics(
108123
109124 req_body = ET .tostring (body_element , xml_declaration = True , encoding = "unicode" )
110125
111- return await self .async_send_message (MessageType .GET_FILTER_DIAGNOSTIC_INFO , req_body , True )
126+ resp = await self .async_send_message (MessageType .GET_FILTER_DIAGNOSTIC_INFO , req_body , True )
127+
128+ if raw :
129+ return resp
130+ return FilterDiagnostics .load_xml (resp )
112131
113- @to_pydantic (pydantic_type = Telemetry )
114- async def async_get_telemetry (self ) -> str :
132+ @overload
133+ async def async_get_telemetry (self , raw : Literal [True ]) -> str : ...
134+ @overload
135+ async def async_get_telemetry (self , raw : Literal [False ]) -> Telemetry : ...
136+ @overload
137+ async def async_get_telemetry (self ) -> Telemetry : ...
138+ async def async_get_telemetry (self , raw : bool = False ) -> Telemetry | str :
115139 """Retrieve the current telemetry data from the Omni, optionally parse it into a pydantic model.
116140
117141 Returns:
@@ -124,7 +148,11 @@ async def async_get_telemetry(self) -> str:
124148
125149 req_body = ET .tostring (body_element , xml_declaration = True , encoding = "unicode" )
126150
127- return await self .async_send_message (MessageType .GET_TELEMETRY , req_body , True )
151+ resp = await self .async_send_message (MessageType .GET_TELEMETRY , req_body , True )
152+
153+ if raw :
154+ return resp
155+ return Telemetry .load_xml (resp )
128156
129157 async def async_set_heater (
130158 self ,
@@ -352,7 +380,7 @@ async def async_set_light_show(
352380 self ,
353381 pool_id : int ,
354382 equipment_id : int ,
355- show : ColorLogicShow ,
383+ show : ColorLogicShow25 | ColorLogicShow40 | ColorLogicShowUCL | ColorLogicShowUCLV2 ,
356384 speed : ColorLogicSpeed = ColorLogicSpeed .ONE_TIMES ,
357385 brightness : ColorLogicBrightness = ColorLogicBrightness .ONE_HUNDRED_PERCENT ,
358386 reserved : int = 0 ,
0 commit comments