Skip to content

Commit

Permalink
Expose washing machine program code if available (#215)
Browse files Browse the repository at this point in the history
  • Loading branch information
ofalvai authored Nov 14, 2022
1 parent 7a79280 commit ef5b1b1
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 1 deletion.
2 changes: 2 additions & 0 deletions custom_components/candy/client/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class WashingMachineStatus:
machine_state: MachineState
program_state: WashProgramState
program: int
program_code: Optional[int]
temp: int
spin_speed: int
remaining_minutes: int
Expand All @@ -61,6 +62,7 @@ def from_json(cls, json):
machine_state=MachineState.from_code(int(json["MachMd"])),
program_state=WashProgramState.from_code(int(json["PrPh"])),
program=int(json["Pr"]) if "Pr" in json else int(json["PrNm"]),
program_code=int(json["PrCode"]) if "PrCode" in json else None,
temp=int(json["Temp"]),
spin_speed=int(json["SpinSp"]) * 100,
remaining_minutes=round(int(json["RemTime"]) / 60),
Expand Down
3 changes: 3 additions & 0 deletions custom_components/candy/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ def extra_state_attributes(self) -> Mapping[str, Any]:
if status.fill_percent is not None:
attributes["fill_percent"] = status.fill_percent

if status.program_code is not None:
attributes["program_code"] = status.program_code

return attributes


Expand Down
1 change: 0 additions & 1 deletion tests/fixtures/__init__.py

This file was deleted.

2 changes: 2 additions & 0 deletions tests/test_sensor_washing_machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ async def test_main_sensor_idle(hass: HomeAssistant, aioclient_mock: AiohttpClie
assert state.state == "Idle"
assert state.attributes == {
'program': 1,
'program_code': 136,
'temperature': 40,
'spin_speed': 800,
'remaining_minutes': 0,
Expand Down Expand Up @@ -94,6 +95,7 @@ async def test_main_sensor_no_pr(hass: HomeAssistant, aioclient_mock: AiohttpCli
assert state.state == "Running"
assert state.attributes == {
'program': 6,
'program_code': 3,
'temperature': 40,
'spin_speed': 1000,
'remaining_minutes': 46,
Expand Down

0 comments on commit ef5b1b1

Please sign in to comment.