Skip to content

Commit

Permalink
Fix failure for dishwasher without "OpzProg"
Browse files Browse the repository at this point in the history
  • Loading branch information
dzamlo committed Oct 15, 2021
1 parent 60d3049 commit f376529
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
3 changes: 2 additions & 1 deletion custom_components/candy/client/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down
20 changes: 20 additions & 0 deletions tests/fixtures/dishwasher/wash-no-opzprog.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
16 changes: 16 additions & 0 deletions tests/test_sensor_dishwasher.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down

0 comments on commit f376529

Please sign in to comment.