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
32 changes: 32 additions & 0 deletions openevsehttp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,25 @@ async def clear_override(self) -> None:
response = await self.process_request(url=url, method="delete")
_LOGGER.debug("Toggle response: %s", response["msg"])

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"]:
_LOGGER.error("Invalid value for max_current_soft: %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
if response["msg"] != "done":
_LOGGER.error("Problem issuing command: %s", response["msg"])
raise UnknownError


@property
def hostname(self) -> str:
"""Return charger hostname."""
Expand Down Expand Up @@ -597,6 +616,8 @@ def charging_current(self) -> float:
def current_capacity(self) -> int:
"""Return the current capacity."""
assert self._status is not None
if self._config is not None and "max_current_soft" in self._config:
return self._config["max_current_soft"]
return self._status["pilot"]

@property
Expand Down Expand Up @@ -724,14 +745,25 @@ def divert_active(self) -> bool:
assert self._status is not None
return self._status["divert_active"]

@property
def wifi_serial(self) -> str:
"""Return wifi serial."""
if self._config is not None and "wifi_serial" in self._config:
return self._config["wifi_serial"]
return None

# There is currently no min/max amps JSON data
# available via HTTP API methods
@property
def min_amps(self) -> int:
"""Return the minimum amps."""
if self._config is not None and "min_current_hard" in self._config:
return self._config["min_current_hard"]
return MIN_AMPS

@property
def max_amps(self) -> int:
"""Return the maximum amps."""
if self._config is not None and "max_current_hard" in self._config:
return self._config["max_current_hard"]
return MAX_AMPS
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@

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

VERSION = "0.1.16"

setup(
name="python-openevse-http",
Expand Down
4 changes: 4 additions & 0 deletions tests/fixtures/v4_json/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"firmware": "7.1.3",
"protocol": "-",
"espflash": 4194304,
"wifi_serial": "1234567890AB",
"version": "4.0.0",
"diodet": 0,
"gfcit": 0,
Expand All @@ -12,6 +13,9 @@
"service": 2,
"scale": 220,
"offset": 0,
"max_current_soft": 6,
"min_current_hard": 6,
"max_current_hard": 48,
"mqtt_supported_protocols": [
"mqtt",
"mqtts"
Expand Down
39 changes: 38 additions & 1 deletion tests/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

TEST_URL_RAPI = "http://openevse.test.tld/r"
TEST_URL_OVERRIDE = "http://openevse.test.tld/override"
TEST_URL_CONFIG = "http://openevse.test.tld/config"


async def test_get_status_auth(test_charger_auth):
Expand Down Expand Up @@ -307,7 +308,7 @@ async def test_get_charging_current(fixture, expected, request):


@pytest.mark.parametrize(
"fixture, expected", [("test_charger", 48), ("test_charger_v2", 25)]
"fixture, expected", [("test_charger", 6), ("test_charger_v2", 25)]
)
async def test_get_current_capacity(fixture, expected, request):
"""Test v4 Status reply"""
Expand Down Expand Up @@ -610,3 +611,39 @@ async def test_toggle_override_v2(test_charger_v2, mock_aioclient, caplog):
with caplog.at_level(logging.DEBUG):
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)]
)
async def test_wifi_serial(fixture, expected, request):
"""Test wifi_serial reply"""
charger = request.getfixturevalue(fixture)
await charger.update()
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()
value = {"msg": "done"}
mock_aioclient.post(
TEST_URL_CONFIG,
status=200,
body=json.dumps(value),
)
with caplog.at_level(logging.DEBUG):
await test_charger.set_current(12)
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"""
await test_charger.update()
mock_aioclient.post(
TEST_URL_CONFIG,
status=200,
body="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