Skip to content

Commit dd3e85c

Browse files
authored
fix: url and form data (firstof9#4)
* fix: url and form data * fix tests * formatting
1 parent f682e12 commit dd3e85c

File tree

8 files changed

+27
-11
lines changed

8 files changed

+27
-11
lines changed

openevsehttp/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ def __init__(self, host: str, user: str = None, pwd: str = None) -> None:
4949

5050
def send_command(self, command: str) -> tuple | None:
5151
"""Send a command via HTTP to the charger and prases the response."""
52-
url = f"{self._url}/r?json=1"
53-
data = {"rapi": command}
52+
url = f"{self._url}/r"
53+
data = {"json": 1, "rapi": command}
5454

5555
_LOGGER.debug("Posting data: %s to %s", command, url)
5656
if self._user is not None:

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.4"
8+
VERSION = "0.1.5"
99

1010

1111
setup(
38 Bytes
Binary file not shown.
48 Bytes
Binary file not shown.
Binary file not shown.
Binary file not shown.

tests/conftest.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@ def mock_config_v2(requests_mock):
9191
@pytest.fixture(name="send_command_mock")
9292
def mock_send_command(requests_mock):
9393
"""Mock the command reply."""
94-
value = {"cmd": "OK", "ret": "test"}
94+
value = {"cmd": "OK", "ret": "$OK^20"}
9595
requests_mock.post(
96-
"http://openevse.test.tld/r?json=1",
96+
"http://openevse.test.tld/r",
9797
text=json.dumps(value),
9898
)
9999

@@ -102,7 +102,7 @@ def mock_send_command(requests_mock):
102102
def mock_send_command_parse_err(requests_mock):
103103
"""Mock the command reply parse err."""
104104
requests_mock.post(
105-
"http://openevse.test.tld/r?json=1",
105+
"http://openevse.test.tld/r",
106106
status_code=400,
107107
)
108108

@@ -111,16 +111,26 @@ def mock_send_command_parse_err(requests_mock):
111111
def mock_send_command_auth_err(requests_mock):
112112
"""Mock the command reply auth err."""
113113
requests_mock.post(
114-
"http://openevse.test.tld/r?json=1",
114+
"http://openevse.test.tld/r",
115115
status_code=401,
116116
)
117117

118118

119119
@pytest.fixture(name="send_command_mock_missing")
120120
def mock_send_command_missing(requests_mock):
121121
"""Mock the command reply."""
122-
value = {"cmd": "OK", "what": "test"}
122+
value = {"cmd": "OK", "what": "$NK^21"}
123123
requests_mock.post(
124-
"http://openevse.test.tld/r?json=1",
124+
"http://openevse.test.tld/r",
125+
text=json.dumps(value),
126+
)
127+
128+
129+
@pytest.fixture(name="send_command_mock_failed")
130+
def mock_send_command_failed(requests_mock):
131+
"""Mock the command reply."""
132+
value = {"cmd": "OK", "ret": "$NK^21"}
133+
requests_mock.post(
134+
"http://openevse.test.tld/r",
125135
text=json.dumps(value),
126136
)

tests/test_init.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,13 @@ def test_get_status_auth_err(test_charger_auth_err):
1919
def test_send_command(test_charger, send_command_mock):
2020
"""Test v4 Status reply"""
2121
status = test_charger.send_command("test")
22-
assert status == (True, "test")
22+
assert status == (True, "$OK^20")
23+
24+
25+
def test_send_command(test_charger, send_command_mock_failed):
26+
"""Test v4 Status reply"""
27+
status = test_charger.send_command("test")
28+
assert status == (True, "$NK^21")
2329

2430

2531
def test_send_command_missing(test_charger, send_command_mock_missing):
@@ -31,7 +37,7 @@ def test_send_command_missing(test_charger, send_command_mock_missing):
3137
def test_send_command_auth(test_charger_auth, send_command_mock):
3238
"""Test v4 Status reply"""
3339
status = test_charger_auth.send_command("test")
34-
assert status == (True, "test")
40+
assert status == (True, "$OK^20")
3541

3642

3743
def test_send_command_parse_err(test_charger_auth, send_command_parse_err):

0 commit comments

Comments
 (0)