Skip to content

Commit

Permalink
Fix program number parsing for some models (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
ofalvai authored Nov 22, 2021
1 parent e82dd7d commit 1e00c57
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 1 deletion.
2 changes: 1 addition & 1 deletion custom_components/candy/client/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def from_json(cls, json):
return cls(
machine_state=MachineState(int(json["MachMd"])),
program_state=WashProgramState(int(json["PrPh"])),
program=int(json["Pr"]),
program=int(json["Pr"]) if "Pr" in json else int(json["PrNm"]),
temp=int(json["Temp"]),
spin_speed=int(json["SpinSp"]) * 100,
remaining_minutes=round(int(json["RemTime"]) / 60),
Expand Down
40 changes: 40 additions & 0 deletions tests/fixtures/washing_machine/no_pr.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"statusLavatrice": {
"WiFiStatus": "1",
"Err": "0",
"MachMd": "2",
"PrNm": "6",
"PrCode": "3",
"PrPh": "2",
"SLevel": "1",
"Temp": "40",
"SpinSp": "10",
"Opt1": "0",
"Opt2": "0",
"Opt3": "0",
"Opt4": "0",
"Opt5": "0",
"Opt6": "0",
"Opt7": "0",
"Opt8": "0",
"Opt9": "0",
"DelVal": "25",
"Steam": "0",
"DryT": "0",
"RemTime": "2760",
"RecipeId": "D_21",
"CheckUpState": "0",
"Lang": "1",
"FillR": "53",
"Det": "0",
"Soft": "0",
"DetWarn": "0",
"SoftWarn": "0",
"DetPreW": "0",
"SoftPreW": "0",
"DPrgCnt": "0",
"SPrgCnt": "0",
"WaterHard": "0",
"rED": "0"
}
}
19 changes: 19 additions & 0 deletions tests/test_sensor_washing_machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,25 @@ async def test_main_sensor_no_fillr(hass: HomeAssistant, aioclient_mock: Aiohttp
}


async def test_main_sensor_no_pr(hass: HomeAssistant, aioclient_mock: AiohttpClientMocker):
await init_integration(hass, aioclient_mock, load_fixture("washing_machine/no_pr.json"))

state = hass.states.get("sensor.washing_machine")

assert state
assert state.state == "Running"
assert state.attributes == {
'program': 6,
'temperature': 40,
'spin_speed': 1000,
'remaining_minutes': 46,
'remote_control': True,
'fill_percent': 53,
'friendly_name': 'Washing machine',
'icon': 'mdi:washing-machine'
}


async def test_main_sensor_device_info(hass: HomeAssistant, aioclient_mock: AiohttpClientMocker):
await init_integration(hass, aioclient_mock, load_fixture("washing_machine/idle.json"))

Expand Down

0 comments on commit 1e00c57

Please sign in to comment.