55import datetime
66import json
77import logging
8- from typing import Any , Callable
8+ from typing import Any , Callable , Union , Dict
99
1010import aiohttp # type: ignore
1111from aiohttp .client_exceptions import ContentTypeError , ServerTimeoutError
@@ -73,7 +73,7 @@ async def process_request(
7373 method : str = "" ,
7474 data : Any = None ,
7575 rapi : Any = None ,
76- ) -> Any :
76+ ) -> dict [ str , str ] | dict [ str , Any ] :
7777 """Return result of processed HTTP request."""
7878 auth = None
7979 if method is None :
@@ -123,7 +123,7 @@ async def process_request(
123123
124124 return message
125125
126- async def send_command (self , command : str ) -> tuple | None :
126+ async def send_command (self , command : str ) -> tuple :
127127 """Send a RAPI command to the charger and parses the response."""
128128 url = f"{ self .url } r"
129129 data = {"json" : 1 , "rapi" : command }
@@ -134,7 +134,7 @@ async def send_command(self, command: str) -> tuple | None:
134134 if "msg" in value :
135135 return False , value ["msg" ]
136136 return False , ""
137- return value ["cmd" ], value ["ret" ]
137+ return ( value ["cmd" ], value ["ret" ])
138138
139139 async def update (self ) -> None :
140140 """Update the values."""
@@ -251,7 +251,7 @@ def ws_state(self) -> Any:
251251 assert self .websocket
252252 return self .websocket .state
253253
254- async def get_schedule (self ) -> list :
254+ async def get_schedule (self ) -> Union [ Dict [ str , str ], Dict [ str , Any ]] :
255255 """Return the current schedule."""
256256 url = f"{ self .url } schedule"
257257
@@ -277,7 +277,9 @@ async def set_charge_mode(self, mode: str = "fast") -> None:
277277 _LOGGER .error ("Problem issuing command: %s" , response ["msg" ])
278278 raise UnknownError
279279
280- async def divert_mode (self , mode : str = "normal" ) -> None :
280+ async def divert_mode (
281+ self , mode : str = "normal"
282+ ) -> Union [Dict [str , str ], Dict [str , Any ]]:
281283 """Set the divert mode to either Normal or Eco modes."""
282284 url = f"{ self .url } divertmode"
283285
@@ -299,7 +301,7 @@ async def divert_mode(self, mode: str = "normal") -> None:
299301 _LOGGER .debug ("divert_mode response: %s" , response )
300302 return response
301303
302- async def get_override (self ) -> None :
304+ async def get_override (self ) -> Union [ Dict [ str , str ], Dict [ str , Any ]] :
303305 """Get the manual override status."""
304306 if not self ._version_check ("4.0.0" ):
305307 _LOGGER .debug ("Feature not supported for older firmware." )
@@ -312,7 +314,7 @@ async def get_override(self) -> None:
312314
313315 async def set_override (
314316 self ,
315- state : str ,
317+ state : str | None = None ,
316318 charge_current : int | None = None ,
317319 max_current : int | None = None ,
318320 energy_limit : int | None = None ,
@@ -325,22 +327,23 @@ async def set_override(
325327 raise UnsupportedFeature
326328 url = f"{ self .url } override"
327329
328- if state not in ["active" , "disabled" ]:
330+ data : dict [str , Any ] = {}
331+
332+ if state not in ["active" , "disabled" , None ]:
329333 _LOGGER .error ("Invalid override state: %s" , state )
330334 raise ValueError
331335
332- data = {
333- "state" : state ,
334- "auto_release" : auto_release ,
335- }
336+ data ["auto_release" ] = auto_release
336337
337- if charge_current :
338+ if state is not None :
339+ data ["state" ] = state
340+ if charge_current is not None :
338341 data ["charge_current" ] = charge_current
339- if max_current :
342+ if max_current is not None :
340343 data ["max_current" ] = max_current
341- if energy_limit :
344+ if energy_limit is not None :
342345 data ["energy_limit" ] = energy_limit
343- if time_limit :
346+ if time_limit is not None :
344347 data ["time_limit" ] = time_limit
345348
346349 _LOGGER .debug ("Override data: %s" , data )
@@ -364,8 +367,8 @@ async def toggle_override(self) -> None:
364367 # Older firmware use RAPI commands
365368 _LOGGER .debug ("Toggling manual override via RAPI" )
366369 command = "$FE" if self ._status ["state" ] == 254 else "$FS"
367- response = await self .send_command (command )
368- _LOGGER .debug ("Toggle response: %s" , response [ 1 ] )
370+ response , msg = await self .send_command (command )
371+ _LOGGER .debug ("Toggle response: %s" , msg )
369372
370373 async def clear_override (self ) -> None :
371374 """Clear the manual override status."""
@@ -400,13 +403,14 @@ async def set_current(self, amps: int = 6) -> None:
400403 response = await self .process_request (
401404 url = url , method = "post" , data = data
402405 ) # noqa: E501
406+ _LOGGER .debug ("Set current response: %s" , response )
403407
404408 else :
405409 # RAPI commands
406410 _LOGGER .debug ("Setting current via RAPI" )
407411 command = f"$SC { amps } N"
408- response = await self .send_command (command )
409- _LOGGER .debug ("Set current response: %s" , response [ 1 ] )
412+ response , msg = await self .send_command (command )
413+ _LOGGER .debug ("Set current response: %s" , msg )
410414
411415 # Restart OpenEVSE WiFi
412416 async def restart_wifi (self ) -> None :
0 commit comments