Skip to content

Commit

Permalink
feat: change set_current to call set_override (#180)
Browse files Browse the repository at this point in the history
* feat: chage `set_current` to call `set_override`

* formatting

* cleanup unused variable
  • Loading branch information
firstof9 committed Feb 5, 2023
1 parent 2cea250 commit b958fb5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 19 deletions.
12 changes: 3 additions & 9 deletions openevsehttp/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,21 +388,15 @@ async def set_current(self, amps: int = 6) -> None:
amps = int(amps)

if self._version_check("4.1.2"):
url = f"{self.url}config"

if (
amps < self._config["min_current_hard"]
or amps > self._config["max_current_hard"]
):
_LOGGER.error("Invalid value for max_current_soft: %s", amps)
_LOGGER.error("Invalid value for current limit: %s", amps)
raise ValueError

data = {"max_current_soft": amps}

_LOGGER.debug("Setting max_current_soft to %s", amps)
response = await self.process_request(
url=url, method="post", data=data
) # noqa: E501
_LOGGER.debug("Setting current limit to %s", amps)
response = await self.set_override(charge_current=amps)
_LOGGER.debug("Set current response: %s", response)

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

PROJECT_DIR = Path(__file__).parent.resolve()
README_FILE = PROJECT_DIR / "README.md"
VERSION = "0.1.36"
VERSION = "0.1.37"

setup(
name="python-openevse-http",
Expand Down
17 changes: 8 additions & 9 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -699,29 +699,28 @@ async def test_wifi_serial(fixture, expected, request):
async def test_set_current(test_charger, mock_aioclient, caplog):
"""Test v4 Status reply."""
await test_charger.update()
value = {"msg": "done"}
mock_aioclient.post(
TEST_URL_CONFIG,
TEST_URL_OVERRIDE,
status=200,
body=json.dumps(value),
body='{"msg": "OK"}',
)
with caplog.at_level(logging.DEBUG):
await test_charger.set_current(12)
assert "Setting max_current_soft to 12" in caplog.text
assert "Setting current limit to 12" in caplog.text


async def test_set_current_error(test_charger, mock_aioclient, caplog):
"""Test v4 Status reply."""
await test_charger.update()
mock_aioclient.post(
TEST_URL_CONFIG,
TEST_URL_OVERRIDE,
status=200,
body="OK",
body='{"msg": "OK"}',
)
with caplog.at_level(logging.DEBUG):
with pytest.raises(ValueError):
await test_charger.set_current(60)
assert "Invalid value for max_current_soft: 60" in caplog.text
assert "Invalid value for current limit: 60" in caplog.text


async def test_set_current_v2(
Expand All @@ -742,9 +741,9 @@ async def test_set_current_v2(
await test_charger_dev.update()
value = {"msg": "OK"}
mock_aioclient.post(
TEST_URL_CONFIG,
TEST_URL_OVERRIDE,
status=200,
body=json.dumps(value),
body='{"msg": "OK"}',
)
with caplog.at_level(logging.DEBUG):
await test_charger_dev.set_current(12)
Expand Down

0 comments on commit b958fb5

Please sign in to comment.