@@ -41,37 +41,40 @@ class OpenEVSE:
4141
4242 def __init__ (self , host : str , user : str = None , pwd : str = None ) -> None :
4343 """Connect to an OpenEVSE charger equipped with a wifi or ethernet."""
44- self ._username = user
45- self ._password = pwd
44+ self ._user = user
45+ self ._pwd = pwd
4646 self ._url = f"http://{ host } "
4747 self ._status = self .update (mode = "status" )
4848 self ._config = self .update (mode = "config" )
4949
50- async def send_command (
51- self , command : str , cmd_type : str
52- ) -> Optional [Dict [Any , Any ]] | None :
50+ async def send_command (self , command : str ) -> tuple | None :
5351 """Send a command via HTTP to the charger and prases the response."""
54- url = f"{ self ._url } /{ cmd_type } "
52+ url = f"{ self ._url } /r?json=1"
53+ data = {"rapi" : command }
5554
5655 _LOGGER .debug ("Posting data: %s to %s" , command , url )
57- if self ._username is not None :
58- value = requests .get (url , auth = (self ._username , self ._password ))
56+ if self ._user is not None :
57+ value = requests .get (url , data = data , auth = (self ._user , self ._pwd ))
5958 else :
60- value = requests .get (url )
59+ value = requests .get (url , data = data )
6160
6261 if value .status_code == 400 :
6362 raise ParseJSONError
6463 if value .status_code == 401 :
6564 raise AuthenticationError
66- return value .json ()
65+
66+ if "ret" not in value .json ():
67+ return False , ""
68+ resp = value .json ()
69+ return resp [0 ] == "OK" , resp [1 :]
6770
6871 def update (self , mode : str ) -> Optional [Dict [Any , Any ]] | None :
6972 """Update the values."""
7073 url = f"{ self ._url } /{ mode } "
7174
7275 _LOGGER .debug ("Updating data from %s" , url )
73- if self ._username is not None :
74- value = requests .get (url , auth = (self ._username , self ._password ))
76+ if self ._user is not None :
77+ value = requests .get (url , auth = (self ._user , self ._pwd ))
7578 else :
7679 value = requests .get (url )
7780
0 commit comments