Skip to content

Commit b958fb5

Browse files
authored
feat: change set_current to call set_override (#180)
* feat: chage `set_current` to call `set_override` * formatting * cleanup unused variable
1 parent 2cea250 commit b958fb5

File tree

3 files changed

+12
-19
lines changed

3 files changed

+12
-19
lines changed

openevsehttp/__main__.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -388,21 +388,15 @@ async def set_current(self, amps: int = 6) -> None:
388388
amps = int(amps)
389389

390390
if self._version_check("4.1.2"):
391-
url = f"{self.url}config"
392-
393391
if (
394392
amps < self._config["min_current_hard"]
395393
or amps > self._config["max_current_hard"]
396394
):
397-
_LOGGER.error("Invalid value for max_current_soft: %s", amps)
395+
_LOGGER.error("Invalid value for current limit: %s", amps)
398396
raise ValueError
399397

400-
data = {"max_current_soft": amps}
401-
402-
_LOGGER.debug("Setting max_current_soft to %s", amps)
403-
response = await self.process_request(
404-
url=url, method="post", data=data
405-
) # noqa: E501
398+
_LOGGER.debug("Setting current limit to %s", amps)
399+
response = await self.set_override(charge_current=amps)
406400
_LOGGER.debug("Set current response: %s", response)
407401

408402
else:

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.36"
8+
VERSION = "0.1.37"
99

1010
setup(
1111
name="python-openevse-http",

tests/test_main.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -699,29 +699,28 @@ async def test_wifi_serial(fixture, expected, request):
699699
async def test_set_current(test_charger, mock_aioclient, caplog):
700700
"""Test v4 Status reply."""
701701
await test_charger.update()
702-
value = {"msg": "done"}
703702
mock_aioclient.post(
704-
TEST_URL_CONFIG,
703+
TEST_URL_OVERRIDE,
705704
status=200,
706-
body=json.dumps(value),
705+
body='{"msg": "OK"}',
707706
)
708707
with caplog.at_level(logging.DEBUG):
709708
await test_charger.set_current(12)
710-
assert "Setting max_current_soft to 12" in caplog.text
709+
assert "Setting current limit to 12" in caplog.text
711710

712711

713712
async def test_set_current_error(test_charger, mock_aioclient, caplog):
714713
"""Test v4 Status reply."""
715714
await test_charger.update()
716715
mock_aioclient.post(
717-
TEST_URL_CONFIG,
716+
TEST_URL_OVERRIDE,
718717
status=200,
719-
body="OK",
718+
body='{"msg": "OK"}',
720719
)
721720
with caplog.at_level(logging.DEBUG):
722721
with pytest.raises(ValueError):
723722
await test_charger.set_current(60)
724-
assert "Invalid value for max_current_soft: 60" in caplog.text
723+
assert "Invalid value for current limit: 60" in caplog.text
725724

726725

727726
async def test_set_current_v2(
@@ -742,9 +741,9 @@ async def test_set_current_v2(
742741
await test_charger_dev.update()
743742
value = {"msg": "OK"}
744743
mock_aioclient.post(
745-
TEST_URL_CONFIG,
744+
TEST_URL_OVERRIDE,
746745
status=200,
747-
body=json.dumps(value),
746+
body='{"msg": "OK"}',
748747
)
749748
with caplog.at_level(logging.DEBUG):
750749
await test_charger_dev.set_current(12)

0 commit comments

Comments
 (0)