Skip to content
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
10 changes: 6 additions & 4 deletions openevsehttp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,10 @@ async def set_current(self, amps: int = 6) -> None:
"""Set the soft current limit."""
url = f"{self.url}config"

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

Expand All @@ -458,8 +461,7 @@ async def set_current(self, amps: int = 6) -> None:
) # noqa: E501
if response["msg"] != "done":
_LOGGER.error("Problem issuing command: %s", response["msg"])
raise UnknownError

raise UnknownError

@property
def hostname(self) -> str:
Expand Down Expand Up @@ -746,7 +748,7 @@ def divert_active(self) -> bool:
return self._status["divert_active"]

@property
def wifi_serial(self) -> str:
def wifi_serial(self) -> str | None:
"""Return wifi serial."""
if self._config is not None and "wifi_serial" in self._config:
return self._config["wifi_serial"]
Expand Down
7 changes: 5 additions & 2 deletions tests/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,7 @@ async def test_toggle_override_v2(test_charger_v2, mock_aioclient, caplog):
await test_charger_v2.toggle_override()
assert "Toggling manual override via RAPI" in caplog.text


@pytest.mark.parametrize(
"fixture, expected", [("test_charger", "1234567890AB"), ("test_charger_v2", None)]
)
Expand All @@ -622,6 +623,7 @@ async def test_wifi_serial(fixture, expected, request):
status = charger.wifi_serial
assert status == expected


async def test_set_current(test_charger, mock_aioclient, caplog):
"""Test v4 Status reply"""
await test_charger.update()
Expand All @@ -633,7 +635,8 @@ async def test_set_current(test_charger, mock_aioclient, caplog):
)
with caplog.at_level(logging.DEBUG):
await test_charger.set_current(12)
assert "Setting max_current_soft to 12" in caplog.text
assert "Setting max_current_soft to 12" in caplog.text


async def test_set_current_error(test_charger, mock_aioclient, caplog):
"""Test v4 Status reply"""
Expand All @@ -646,4 +649,4 @@ async def test_set_current_error(test_charger, mock_aioclient, caplog):
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 max_current_soft: 60" in caplog.text