|
9 | 9 | from aiohttp.client_exceptions import ContentTypeError, ServerTimeoutError
|
10 | 10 |
|
11 | 11 | import openevsehttp.__main__ as main
|
| 12 | +from openevsehttp.exceptions import MissingSerial, UnknownError, UnsupportedFeature |
12 | 13 | from tests.common import load_fixture
|
13 |
| -from openevsehttp.exceptions import MissingSerial, UnsupportedFeature |
14 | 14 |
|
15 | 15 | pytestmark = pytest.mark.asyncio
|
16 | 16 |
|
| 17 | +TEST_URL_STATUS = "http://openevse.test.tld/status" |
17 | 18 | TEST_URL_RAPI = "http://openevse.test.tld/r"
|
18 | 19 | TEST_URL_OVERRIDE = "http://openevse.test.tld/override"
|
19 | 20 | TEST_URL_CONFIG = "http://openevse.test.tld/config"
|
@@ -1203,3 +1204,55 @@ async def test_version_check(test_charger_new, mock_aioclient, caplog):
|
1203 | 1204 |
|
1204 | 1205 | result = test_charger_new._version_check("4.0.0", "4.1.7")
|
1205 | 1206 | assert not result
|
| 1207 | + |
| 1208 | + |
| 1209 | +async def test_set_charge_mode(test_charger, mock_aioclient, caplog): |
| 1210 | + """Test v4 Status reply.""" |
| 1211 | + await test_charger.update() |
| 1212 | + value = {"msg": "done"} |
| 1213 | + mock_aioclient.post( |
| 1214 | + TEST_URL_CONFIG, |
| 1215 | + status=200, |
| 1216 | + body=json.dumps(value), |
| 1217 | + ) |
| 1218 | + with caplog.at_level(logging.DEBUG): |
| 1219 | + await test_charger.set_charge_mode("eco") |
| 1220 | + |
| 1221 | + mock_aioclient.get( |
| 1222 | + TEST_URL_STATUS, |
| 1223 | + status=200, |
| 1224 | + body=load_fixture("v4_json/status.json"), |
| 1225 | + ) |
| 1226 | + mock_aioclient.get( |
| 1227 | + TEST_URL_CONFIG, |
| 1228 | + status=200, |
| 1229 | + body=load_fixture("v4_json/config.json"), |
| 1230 | + ) |
| 1231 | + value = {"config_version": 2, "msg": "done"} |
| 1232 | + mock_aioclient.post( |
| 1233 | + TEST_URL_CONFIG, |
| 1234 | + status=200, |
| 1235 | + body=json.dumps(value), |
| 1236 | + ) |
| 1237 | + with caplog.at_level(logging.DEBUG): |
| 1238 | + await test_charger.set_charge_mode("fast") |
| 1239 | + |
| 1240 | + value = {"msg": "error"} |
| 1241 | + mock_aioclient.post( |
| 1242 | + TEST_URL_CONFIG, |
| 1243 | + status=200, |
| 1244 | + body=json.dumps(value), |
| 1245 | + ) |
| 1246 | + with caplog.at_level(logging.DEBUG): |
| 1247 | + with pytest.raises(UnknownError): |
| 1248 | + await test_charger.set_charge_mode("fast") |
| 1249 | + assert "Problem issuing command: error" in caplog.text |
| 1250 | + |
| 1251 | + value = {"msg": "done"} |
| 1252 | + mock_aioclient.post( |
| 1253 | + TEST_URL_CONFIG, |
| 1254 | + status=200, |
| 1255 | + body=json.dumps(value), |
| 1256 | + ) |
| 1257 | + with pytest.raises(ValueError): |
| 1258 | + await test_charger.set_charge_mode("test") |
0 commit comments