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 existing override and limits when setting new ones #406

Merged
merged 2 commits into from
Feb 3, 2025
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
6 changes: 2 additions & 4 deletions openevsehttp/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ async def set_override(
raise UnsupportedFeature
url = f"{self.url}override"

data: dict[str, Any] = {}
data: dict[str, Any] = await self.get_override()

if state not in ["active", "disabled", None]:
_LOGGER.error("Invalid override state: %s", state)
Expand Down Expand Up @@ -644,7 +644,6 @@ def _version_check(self, min_version: str, max_version: str = "") -> bool:
return False

# HTTP Posting of grid voltage

async def grid_voltage(self, voltage: int | None = None) -> None:
"""Send pushed sensor data to grid voltage."""
if not self._version_check("4.0.0"):
Expand All @@ -665,7 +664,6 @@ async def grid_voltage(self, voltage: int | None = None) -> None:
_LOGGER.debug("Voltage posting response: %s", response)

# Self production HTTP Posting

async def self_production(
self,
grid: int | None = None,
Expand Down Expand Up @@ -743,7 +741,7 @@ async def set_limit(
raise UnsupportedFeature

url = f"{self.url}limit"
data: Dict[str, Any] = {}
data: Dict[str, Any] = await self.get_limit()
valid_types = ["time", "energy", "soc", "range"]

if limit_type not in valid_types:
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.70"
VERSION = "0.1.71"

setup(
name="python_openevse_http",
Expand Down
76 changes: 70 additions & 6 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -860,6 +860,19 @@ 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 = {
"state": "active",
"charge_current": 0,
"max_current": 0,
"energy_limit": 0,
"time_limit": 0,
"auto_release": True,
}
mock_aioclient.get(
TEST_URL_OVERRIDE,
status=200,
body=json.dumps(value),
)
mock_aioclient.post(
TEST_URL_OVERRIDE,
status=200,
Expand All @@ -875,6 +888,20 @@ async def test_set_current_error(
):
"""Test v4 Status reply."""
await test_charger.update()
value = {
"state": "active",
"charge_current": 0,
"max_current": 0,
"energy_limit": 0,
"time_limit": 0,
"auto_release": True,
}
mock_aioclient.get(
TEST_URL_OVERRIDE,
status=200,
body=json.dumps(value),
repeat=True,
)
mock_aioclient.post(
TEST_URL_OVERRIDE,
status=200,
Expand Down Expand Up @@ -913,6 +940,19 @@ async def test_set_current_v2(

await test_charger_dev.update()
value = {"msg": "OK"}
value = {
"state": "active",
"charge_current": 0,
"max_current": 0,
"energy_limit": 0,
"time_limit": 0,
"auto_release": True,
}
mock_aioclient.get(
TEST_URL_OVERRIDE,
status=200,
body=json.dumps(value),
)
mock_aioclient.post(
TEST_URL_OVERRIDE,
status=200,
Expand Down Expand Up @@ -1257,6 +1297,20 @@ async def test_set_override(
):
"""Test set override function."""
await test_charger.update()
value = {
"state": "active",
"charge_current": 0,
"max_current": 0,
"energy_limit": 0,
"time_limit": 0,
"auto_release": True,
}
mock_aioclient.get(
TEST_URL_OVERRIDE,
status=200,
body=json.dumps(value),
repeat=True,
)
mock_aioclient.post(
TEST_URL_OVERRIDE,
status=200,
Expand All @@ -1265,7 +1319,10 @@ async def test_set_override(
with caplog.at_level(logging.DEBUG):
status = await test_charger.set_override("active")
assert status == {"msg": "OK"}
assert "Override data: {'auto_release': True, 'state': 'active'}" in caplog.text
assert (
"Override data: {'state': 'active', 'charge_current': 0, 'max_current': 0, 'energy_limit': 0, 'time_limit': 0, 'auto_release': True}"
in caplog.text
)

mock_aioclient.post(
TEST_URL_OVERRIDE,
Expand All @@ -1274,7 +1331,7 @@ async def test_set_override(
)
status = await test_charger.set_override("active", 30)
assert (
"Override data: {'auto_release': True, 'state': 'active', 'charge_current': 30}"
"Override data: {'state': 'active', 'charge_current': 30, 'max_current': 0, 'energy_limit': 0, 'time_limit': 0, 'auto_release': True}"
in caplog.text
)
mock_aioclient.post(
Expand All @@ -1284,7 +1341,8 @@ async def test_set_override(
)
status = await test_charger.set_override(charge_current=30)
assert (
"Override data: {'auto_release': True, 'charge_current': 30}" in caplog.text
"Override data: {'state': 'active', 'charge_current': 30, 'max_current': 0, 'energy_limit': 0, 'time_limit': 0, 'auto_release': True}"
in caplog.text
)
mock_aioclient.post(
TEST_URL_OVERRIDE,
Expand All @@ -1293,7 +1351,7 @@ async def test_set_override(
)
status = await test_charger.set_override("active", 30, 32)
assert (
"Override data: {'auto_release': True, 'state': 'active', 'charge_current': 30, 'max_current': 32}"
"Override data: {'state': 'active', 'charge_current': 30, 'max_current': 32, 'energy_limit': 0, 'time_limit': 0, 'auto_release': True}"
in caplog.text
)
mock_aioclient.post(
Expand All @@ -1303,7 +1361,7 @@ async def test_set_override(
)
status = await test_charger.set_override("active", 30, 32, 2000)
assert (
"Override data: {'auto_release': True, 'state': 'active', 'charge_current': 30, 'max_current': 32, 'energy_limit': 2000}"
"Override data: {'state': 'active', 'charge_current': 30, 'max_current': 32, 'energy_limit': 2000, 'time_limit': 0, 'auto_release': True}"
in caplog.text
)
mock_aioclient.post(
Expand All @@ -1313,7 +1371,7 @@ async def test_set_override(
)
status = await test_charger.set_override("active", 30, 32, 2000, 5000)
assert (
"Override data: {'auto_release': True, 'state': 'active', 'charge_current': 30, 'max_current': 32, 'energy_limit': 2000, 'time_limit': 5000}"
"Override data: {'state': 'active', 'charge_current': 30, 'max_current': 32, 'energy_limit': 2000, 'time_limit': 5000, 'auto_release': True}"
in caplog.text
)

Expand Down Expand Up @@ -1697,6 +1755,12 @@ async def test_set_limit(
):
"""Test set limit."""
await test_charger_modified_ver.update()
mock_aioclient.get(
TEST_URL_LIMIT,
status=200,
body='{"type": "energy", "value": 10}',
repeat=True,
)
mock_aioclient.post(
TEST_URL_LIMIT,
status=200,
Expand Down
Loading