Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Use http api for EVSE restart on firmware 5.x+ #331

Merged
merged 11 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions openevsehttp/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@
value = await self.process_request(url=url, method="post", rapi=data)
if "ret" not in value:
if "msg" in value:
return False, value["msg"]
return False, ""
return (False, value["msg"])
return (False, "")
return (value["cmd"], value["ret"])

async def update(self) -> None:
Expand Down Expand Up @@ -474,19 +474,26 @@
async def restart_wifi(self) -> None:
"""Restart OpenEVSE WiFi module."""
url = f"{self.url}restart"
data = {"device": "gateway"}

response = await self.process_request(url=url, method="get")
_LOGGER.debug("WiFi Restart response: %s", response)
response = await self.process_request(url=url, method="post", data=data)
_LOGGER.debug("WiFi Restart response: %s", response["msg"])

# Restart EVSE module
async def restart_evse(self) -> None:
"""Restart EVSE module."""
_LOGGER.debug("Restarting EVSE module via RAPI")
command = "$FR"
if self._version_check("5.0.0"):
_LOGGER.debug("Restarting EVSE module via HTTP")
url = f"{self.url}restart"
data = {"device": "evse"}
reply = await self.process_request(url=url, method="post", data=data)
response = reply["msg"]

Check warning on line 490 in openevsehttp/__main__.py

View check run for this annotation

Codecov / codecov/patch

openevsehttp/__main__.py#L486-L490

Added lines #L486 - L490 were not covered by tests

else:
_LOGGER.debug("Restarting EVSE module via RAPI")
command = "$FR"
reply, response = await self.send_command(command)

response = await self.send_command(command)
if isinstance(response, tuple):
response = response[1]
_LOGGER.debug("EVSE Restart response: %s", response)

# Firmwave version
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

PROJECT_DIR = Path(__file__).parent.resolve()
README_FILE = PROJECT_DIR / "README.md"
VERSION = "0.1.59"
VERSION = "0.1.60"

setup(
name="python-openevse-http",
Expand Down
11 changes: 6 additions & 5 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -947,16 +947,17 @@ async def test_test_and_get(test_charger, test_charger_v2, mock_aioclient, caplo
assert "Older firmware detected, missing serial." in caplog.text


async def test_restart(test_charger_v2, mock_aioclient, caplog):
async def test_restart(test_charger_modified_ver, mock_aioclient, caplog):
"""Test v4 set divert mode."""
mock_aioclient.get(
await test_charger_modified_ver.update()
mock_aioclient.post(
TEST_URL_RESTART,
status=200,
body="1",
body='{"msg": "restart gateway"}',
)
with caplog.at_level(logging.DEBUG):
await test_charger_v2.restart_wifi()
assert "Restart response: 1" in caplog.text
await test_charger_modified_ver.restart_wifi()
assert "Restart response: restart gateway" in caplog.text


async def test_firmware_check(
Expand Down
Loading