diff --git a/custom_components/candy/client/model.py b/custom_components/candy/client/model.py index 2e56e37..81b542e 100644 --- a/custom_components/candy/client/model.py +++ b/custom_components/candy/client/model.py @@ -178,9 +178,13 @@ 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): @@ -188,9 +192,13 @@ def from_json(cls, json): 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 diff --git a/custom_components/candy/sensor.py b/custom_components/candy/sensor.py index b9155a3..be468fa 100644 --- a/custom_components/candy/sensor.py +++ b/custom_components/candy/sensor.py @@ -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 diff --git a/tests/fixtures/dishwasher/drying_optional_params.json b/tests/fixtures/dishwasher/drying_optional_params.json new file mode 100644 index 0000000..018d2ec --- /dev/null +++ b/tests/fixtures/dishwasher/drying_optional_params.json @@ -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" + } +} \ No newline at end of file diff --git a/tests/fixtures/dishwasher/wash.json b/tests/fixtures/dishwasher/wash.json index 19b658a..6b1ab91 100644 --- a/tests/fixtures/dishwasher/wash.json +++ b/tests/fixtures/dishwasher/wash.json @@ -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" diff --git a/tests/fixtures/dishwasher/wash-no-opzprog.json b/tests/fixtures/dishwasher/wash_no_opzprog.json similarity index 100% rename from tests/fixtures/dishwasher/wash-no-opzprog.json rename to tests/fixtures/dishwasher/wash_no_opzprog.json diff --git a/tests/test_sensor_dishwasher.py b/tests/test_sensor_dishwasher.py index a7b7b4a..2c9cbda 100644 --- a/tests/test_sensor_dishwasher.py +++ b/tests/test_sensor_dishwasher.py @@ -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" } @@ -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") @@ -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"))