Skip to content

Commit addf674

Browse files
committed
use RAPI for send_command
* Not ideal but required at this time
1 parent dc4ba3c commit addf674

2 files changed

Lines changed: 16 additions & 13 deletions

File tree

openevsehttp/__init__.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
PROJECT_DIR = Path(__file__).parent.resolve()
77
README_FILE = PROJECT_DIR / "README.md"
8-
VERSION = "0.1.0"
8+
VERSION = "0.1.1"
99

1010

1111
setup(

0 commit comments

Comments
 (0)