Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle cat detected status from displayCode field #215

Merged
merged 1 commit into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions pylitterbot/robot/litterrobot4.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"CYCLE_STATE_CAT_DETECT": LitterBoxStatus.CAT_SENSOR_INTERRUPTED,
"CYCLE_STATE_PAUSE": LitterBoxStatus.PAUSED,
}
DISPLAY_CODE_STATUS_MAP = {"DC_CAT_DETECT": LitterBoxStatus.CAT_DETECTED}

LITTER_LEVEL_EMPTY = 500

Expand Down Expand Up @@ -246,16 +247,25 @@ def sleep_mode_end_time(self) -> datetime | None:

@property
def status(self) -> LitterBoxStatus:
"""Return the status of the Litter-Robot."""
"""Return the status of the Litter-Robot.

The Litter-Robot 4's status is determined based on the values of:
- `displayCode`
- `robotCycleState`
- `robotStatus`
- `isDFIFull`
- `isOnline`
"""
if not self.is_online:
return LitterBoxStatus.OFFLINE
cycle_state = self._data["robotCycleState"]
status = self._data["robotStatus"]
if status == "ROBOT_IDLE" and self.is_waste_drawer_full:
if status := CYCLE_STATE_STATUS_MAP.get(self._data["robotCycleState"]):
return status
if status := DISPLAY_CODE_STATUS_MAP.get(self._data["displayCode"]):
return status
status = LR4_STATUS_MAP.get(self._data["robotStatus"], LitterBoxStatus.UNKNOWN)
if status == LitterBoxStatus.READY and self.is_waste_drawer_full:
return LitterBoxStatus.DRAWER_FULL
return CYCLE_STATE_STATUS_MAP.get(
cycle_state, LR4_STATUS_MAP.get(status, LitterBoxStatus.UNKNOWN)
)
return status

@property
def status_code(self) -> str | None:
Expand Down
1 change: 1 addition & 0 deletions tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@
"firmwareUpdateStatus": "SUCCEEDED",
"unitPowerType": "AC",
"catWeight": 7.93,
"displayCode": "DC_MODE_IDLE",
"unitTimezone": "America/Denver",
"cleanCycleWaitTime": 7,
"isKeypadLockout": False,
Expand Down
2 changes: 2 additions & 0 deletions tests/test_litterrobot4.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ async def test_litter_robot_4_cleaning(mock_account: Account) -> None:
@pytest.mark.parametrize(
"updated_data,status",
[
({"isDFIFull": True}, LitterBoxStatus.DRAWER_FULL),
({"isOnline": False}, LitterBoxStatus.OFFLINE),
(
{"isOnline": False, "robotCycleState": "CYCLE_STATE_PAUSE"},
Expand All @@ -403,6 +404,7 @@ async def test_litter_robot_4_cleaning(mock_account: Account) -> None:
({"robotStatus": "ROBOT_POWER_DOWN"}, LitterBoxStatus.POWER_DOWN),
({"robotStatus": "ROBOT_POWER_OFF"}, LitterBoxStatus.OFF),
({"robotStatus": "ROBOT_POWER_UP"}, LitterBoxStatus.POWER_UP),
({"displayCode": "DC_CAT_DETECT"}, LitterBoxStatus.CAT_DETECTED),
],
)
async def test_litter_robot_4_status(
Expand Down