@@ -641,18 +641,6 @@ async def test_get_relayt(fixture, expected, request):
641641 await charger .ws_disconnect ()
642642
643643
644- @pytest .mark .parametrize (
645- "fixture, expected" , [("test_charger" , "eco" ), ("test_charger_v2" , "normal" )]
646- )
647- async def test_get_divertmode (fixture , expected , request ):
648- """Test v4 Status reply."""
649- charger = request .getfixturevalue (fixture )
650- await charger .update ()
651- status = charger .divertmode
652- assert status == expected
653- await charger .ws_disconnect ()
654-
655-
656644@pytest .mark .parametrize (
657645 "fixture, expected" , [("test_charger" , 0 ), ("test_charger_v2" , 0 )]
658646)
@@ -2159,3 +2147,62 @@ async def test_get_status(test_charger_timeout, caplog):
21592147 assert "Updating data from http://openevse.test.tld/status" in caplog .text
21602148 assert "Status update:" not in caplog .text
21612149 assert "Config update:" not in caplog .text
2150+
2151+
2152+ @pytest .mark .parametrize (
2153+ "fixture, expected" ,
2154+ [
2155+ ("test_charger" , "eco" ),
2156+ ("test_charger_v2" , "fast" ),
2157+ ("test_charger_broken" , "eco" ),
2158+ ("test_charger_new" , "fast" ),
2159+ ],
2160+ )
2161+ async def test_divertmode (fixture , expected , request ):
2162+ """Test divertmode property."""
2163+ charger = request .getfixturevalue (fixture )
2164+ await charger .update ()
2165+ status = charger .divertmode
2166+ assert status == expected
2167+ await charger .ws_disconnect ()
2168+
2169+
2170+ async def test_set_divert_mode (
2171+ test_charger_new , test_charger_v2 , mock_aioclient , caplog
2172+ ):
2173+ """Test set_divert_mode reply."""
2174+ await test_charger_new .update ()
2175+ value = "Divert Mode changed"
2176+ mock_aioclient .get (
2177+ TEST_URL_DIVERT ,
2178+ status = 200 ,
2179+ body = value ,
2180+ )
2181+ with caplog .at_level (logging .DEBUG ):
2182+ await test_charger_new .set_divert_mode ("fast" )
2183+ assert "Setting divert mode to fast" in caplog .text
2184+
2185+ mock_aioclient .get (
2186+ TEST_URL_DIVERT ,
2187+ status = 200 ,
2188+ body = value ,
2189+ )
2190+ await test_charger_v2 .update ()
2191+ with caplog .at_level (logging .DEBUG ):
2192+ await test_charger_v2 .set_divert_mode ("eco" )
2193+ assert "Setting divert mode to eco" in caplog .text
2194+
2195+ with pytest .raises (ValueError ):
2196+ with caplog .at_level (logging .DEBUG ):
2197+ await test_charger_new .set_divert_mode ("test" )
2198+ assert "Invalid value for charge_mode: test" in caplog .text
2199+
2200+ mock_aioclient .get (
2201+ TEST_URL_DIVERT ,
2202+ status = 200 ,
2203+ body = "error" ,
2204+ )
2205+ with pytest .raises (UnknownError ):
2206+ with caplog .at_level (logging .DEBUG ):
2207+ await test_charger_new .set_divert_mode ("fast" )
2208+ assert "Problem issuing command: error" in caplog .text
0 commit comments