Skip to content

Commit

Permalink
Add more dishwasher attributes (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
ofalvai authored Oct 23, 2021
1 parent e799fc6 commit 715cc38
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 4 deletions.
10 changes: 9 additions & 1 deletion custom_components/candy/client/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,19 +178,27 @@ class DishwasherStatus:
machine_state: DishwasherState
program: str
remaining_minutes: int
delayed_start_hours: Optional[int]
door_open: bool
door_open_allowed: Optional[bool]
eco_mode: bool
remote_control: bool
salt_empty: bool
rinse_aid_empty: bool

@classmethod
def from_json(cls, json):
return cls(
machine_state=DishwasherState(int(json["StatoDWash"])),
program=DishwasherStatus.parse_program(json),
remaining_minutes=int(json["RemTime"]),
delayed_start_hours=int(json["DelayStart"]) if json["DelayStart"] != "0" else None,
door_open=json["OpenDoor"] != "0",
door_open_allowed=json["OpenDoorOpt"] == "1" if "OpenDoorOpt" in json else None,
eco_mode=json["Eco"] != "0",
remote_control=json["StatoWiFi"] == "1"
remote_control=json["StatoWiFi"] == "1",
salt_empty=json["MissSalt"] == "1",
rinse_aid_empty=json["MissRinse"] == "1"
)

@staticmethod
Expand Down
8 changes: 8 additions & 0 deletions custom_components/candy/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,8 +381,16 @@ def extra_state_attributes(self) -> Mapping[str, Any]:
"remote_control": status.remote_control,
"door_open": status.door_open,
"eco_mode": status.eco_mode,
"salt_empty": status.salt_empty,
"rinse_aid_empty": status.rinse_aid_empty
}

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

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

return attributes


Expand Down
21 changes: 21 additions & 0 deletions tests/fixtures/dishwasher/drying_optional_params.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"statusDWash": {
"StatoWiFi": "1",
"StatoDWash": "4",
"CodiceErrore": "E0",
"StartStop": "1",
"Program": "P2",
"OpzProg": "0",
"DelayStart": "4",
"RemTime": "58",
"TreinUno": "0",
"Eco": "1",
"MetaCarico": "0",
"ExtraDry": "0",
"OpenDoorOpt": "1",
"MissSalt": "0",
"MissRinse": "1",
"OpenDoor": "0",
"Reset": "0"
}
}
4 changes: 2 additions & 2 deletions tests/fixtures/dishwasher/wash.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
"Eco": "1",
"MetaCarico": "0",
"ExtraDry": "0",
"MissSalt": "0",
"MissRinse": "0",
"MissSalt": "1",
"MissRinse": "1",
"OpenDoor": "0",
"Reset": "0",
"FWver": "L1.12"
Expand Down
32 changes: 31 additions & 1 deletion tests/test_sensor_dishwasher.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ async def test_main_sensor_idle(hass: HomeAssistant, aioclient_mock: AiohttpClie
"eco_mode": False,
"door_open": False,
"remote_control": True,
"salt_empty": False,
"rinse_aid_empty": False,
"friendly_name": "Dishwasher",
"icon": "mdi:glass-wine"
}
Expand All @@ -38,12 +40,15 @@ async def test_main_sensor_wash(hass: HomeAssistant, aioclient_mock: AiohttpClie
"eco_mode": True,
"door_open": False,
"remote_control": False,
"salt_empty": True,
"rinse_aid_empty": True,
"friendly_name": "Dishwasher",
"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"))
await init_integration(hass, aioclient_mock, load_fixture("dishwasher/wash_no_opzprog.json"))

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

Expand All @@ -55,10 +60,35 @@ async def test_main_sensor_wash_no_opzprog(hass: HomeAssistant, aioclient_mock:
"eco_mode": True,
"door_open": False,
"remote_control": False,
"salt_empty": False,
"rinse_aid_empty": False,
"friendly_name": "Dishwasher",
"icon": "mdi:glass-wine"
}


async def test_main_sensor_drying_optional_params(hass: HomeAssistant, aioclient_mock: AiohttpClientMocker):
await init_integration(hass, aioclient_mock, load_fixture("dishwasher/drying_optional_params.json"))

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

assert state
assert state.state == "Drying"
assert state.attributes == {
"program": "P2",
"remaining_minutes": 58,
"delayed_start_hours": 4,
"eco_mode": True,
"door_open": False,
"door_open_allowed": True,
"remote_control": True,
"salt_empty": False,
"rinse_aid_empty": True,
"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 715cc38

Please sign in to comment.