From e799fc6a02ccb14743383c45782ff900345a8af5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Damien?= Date: Fri, 15 Oct 2021 22:15:01 +0200 Subject: [PATCH] Fix failure for dishwasher without "OpzProg" (#27) --- custom_components/candy/client/model.py | 3 ++- .../fixtures/dishwasher/wash-no-opzprog.json | 20 +++++++++++++++++++ tests/test_sensor_dishwasher.py | 16 +++++++++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 tests/fixtures/dishwasher/wash-no-opzprog.json diff --git a/custom_components/candy/client/model.py b/custom_components/candy/client/model.py index 2ce32e8..2e56e37 100644 --- a/custom_components/candy/client/model.py +++ b/custom_components/candy/client/model.py @@ -199,7 +199,8 @@ def parse_program(json) -> str: Parse final program label, like P1, P1+, P1- """ program = json["Program"] - option = json["OpzProg"] + # Some dishwasher don't include OpzProg in there answers + option = json.get("OpzProg") if option == "p": return program + "+" elif option == "m": diff --git a/tests/fixtures/dishwasher/wash-no-opzprog.json b/tests/fixtures/dishwasher/wash-no-opzprog.json new file mode 100644 index 0000000..af760ce --- /dev/null +++ b/tests/fixtures/dishwasher/wash-no-opzprog.json @@ -0,0 +1,20 @@ +{ + "statusDWash": { + "StatoWiFi": "0", + "StatoDWash": "2", + "CodiceErrore": "E0", + "StartStop": "0", + "Program": "P2", + "DelayStart": "0", + "RemTime": "68", + "TreinUno": "0", + "Eco": "1", + "MetaCarico": "0", + "ExtraDry": "0", + "MissSalt": "0", + "MissRinse": "0", + "OpenDoor": "0", + "Reset": "0", + "FWver": "L1.12" + } +} \ No newline at end of file diff --git a/tests/test_sensor_dishwasher.py b/tests/test_sensor_dishwasher.py index d2b80ad..a7b7b4a 100644 --- a/tests/test_sensor_dishwasher.py +++ b/tests/test_sensor_dishwasher.py @@ -42,6 +42,22 @@ async def test_main_sensor_wash(hass: HomeAssistant, aioclient_mock: AiohttpClie "icon": "mdi:glass-wine" } +async def test_main_sensor_wash_no_opzprog(hass: HomeAssistant, aioclient_mock: AiohttpClientMocker): + await init_integration(hass, aioclient_mock, load_fixture("dishwasher/wash-no-opzprog.json")) + + state = hass.states.get("sensor.dishwasher") + + assert state + assert state.state == "Wash" + assert state.attributes == { + "program": "P2", + "remaining_minutes": 68, + "eco_mode": True, + "door_open": False, + "remote_control": False, + "friendly_name": "Dishwasher", + "icon": "mdi:glass-wine" + } async def test_remaining_time_sensor_idle(hass: HomeAssistant, aioclient_mock: AiohttpClientMocker): await init_integration(hass, aioclient_mock, load_fixture("dishwasher/idle.json"))