1919 UnsupportedFeature ,
2020)
2121from tests .common import load_fixture
22+ from openevsehttp .websocket import SIGNAL_CONNECTION_STATE , STATE_CONNECTED
2223
2324pytestmark = pytest .mark .asyncio
2425
3132TEST_URL_LIMIT = "http://openevse.test.tld/limit"
3233TEST_URL_WS = "ws://openevse.test.tld/ws"
3334TEST_URL_CLAIMS = "http://openevse.test.tld/claims"
35+ TEST_URL_CLAIMS_TARGET = "http://openevse.test.tld/claims/target"
3436TEST_URL_GITHUB_v4 = (
3537 "https://api.github.com/repos/OpenEVSE/ESP32_WiFi_V4.x/releases/latest"
3638)
@@ -46,6 +48,20 @@ async def test_get_status_auth(test_charger_auth):
4648 assert status == "sleeping"
4749
4850
51+ async def test_ws_state (test_charger ):
52+ """Test v4 Status reply."""
53+ await test_charger .update ()
54+ value = test_charger .ws_state
55+ assert value == None
56+
57+
58+ async def test_update_status (test_charger ):
59+ """Test v4 Status reply."""
60+ data = json .loads (load_fixture ("v4_json/status.json" ))
61+ await test_charger ._update_status ("data" , data , None )
62+ assert test_charger ._status == data
63+
64+
4965async def test_get_status_auth_err (test_charger_auth_err ):
5066 """Test v4 Status reply."""
5167 with pytest .raises (main .AuthenticationError ):
@@ -110,6 +126,13 @@ async def test_send_command_parse_err(test_charger_auth, mock_aioclient):
110126 status = await test_charger_auth .send_command ("test" )
111127 assert status is None
112128
129+ mock_aioclient .post (
130+ TEST_URL_RAPI , status = 400 , body = '{"error": "Could not parse JSON"}'
131+ )
132+ with pytest .raises (main .ParseJSONError ):
133+ status = await test_charger_auth .send_command ("test" )
134+ assert status is None
135+
113136
114137async def test_send_command_auth_err (test_charger_auth , mock_aioclient ):
115138 """Test v4 Status reply."""
@@ -947,7 +970,7 @@ async def test_test_and_get(test_charger, test_charger_v2, mock_aioclient, caplo
947970 assert "Older firmware detected, missing serial." in caplog .text
948971
949972
950- async def test_restart (test_charger_modified_ver , mock_aioclient , caplog ):
973+ async def test_restart_wifi (test_charger_modified_ver , mock_aioclient , caplog ):
951974 """Test v4 set divert mode."""
952975 await test_charger_modified_ver .update ()
953976 mock_aioclient .post (
@@ -1057,7 +1080,9 @@ async def test_firmware_check(
10571080 assert firmware is None
10581081
10591082
1060- async def test_evse_restart (test_charger_v2 , mock_aioclient , caplog ):
1083+ async def test_evse_restart (
1084+ test_charger_v2 , test_charger_modified_ver , mock_aioclient , caplog
1085+ ):
10611086 """Test EVSE module restart."""
10621087 await test_charger_v2 .update ()
10631088 value = {"cmd" : "OK" , "ret" : "$OK^20" }
@@ -1070,6 +1095,16 @@ async def test_evse_restart(test_charger_v2, mock_aioclient, caplog):
10701095 await test_charger_v2 .restart_evse ()
10711096 assert "EVSE Restart response: $OK^20" in caplog .text
10721097
1098+ await test_charger_modified_ver .update ()
1099+ mock_aioclient .post (
1100+ TEST_URL_RESTART ,
1101+ status = 200 ,
1102+ body = '{"msg": "restart evse"}' ,
1103+ )
1104+ with caplog .at_level (logging .DEBUG ):
1105+ await test_charger_modified_ver .restart_evse ()
1106+ assert "Restarting EVSE module via HTTP" in caplog .text
1107+
10731108
10741109@pytest .mark .parametrize (
10751110 "fixture, expected" , [("test_charger" , True ), ("test_charger_v2" , None )]
@@ -1869,3 +1904,33 @@ async def test_set_led_brightness(
18691904 with caplog .at_level (logging .DEBUG ):
18701905 await test_charger_v2 .set_led_brightness (255 )
18711906 assert "Feature not supported for older firmware." in caplog .text
1907+
1908+
1909+ async def test_async_charge_current (
1910+ test_charger , test_charger_v2 , mock_aioclient , caplog
1911+ ):
1912+ """Test async_charge_current function."""
1913+ await test_charger .update ()
1914+ mock_aioclient .get (
1915+ TEST_URL_CLAIMS_TARGET ,
1916+ status = 200 ,
1917+ body = '{"properties":{"state":"disabled","charge_current":28,"max_current":23,"auto_release":false},"claims":{"state":65540,"charge_current":65537,"max_current":65548}}' ,
1918+ repeat = False ,
1919+ )
1920+
1921+ value = await test_charger .async_charge_current
1922+ assert value == 28
1923+
1924+ mock_aioclient .get (
1925+ TEST_URL_CLAIMS_TARGET ,
1926+ status = 200 ,
1927+ body = '{"properties":{"state":"disabled","max_current":23,"auto_release":false},"claims":{"state":65540,"charge_current":65537,"max_current":65548}}' ,
1928+ repeat = False ,
1929+ )
1930+
1931+ value = await test_charger .async_charge_current
1932+ assert value == 48
1933+
1934+ await test_charger_v2 .update ()
1935+ value = await test_charger_v2 .async_charge_current
1936+ assert value == 25
0 commit comments