Skip to content

Commit

Permalink
Merge pull request #215 from natekspencer/cat-detected
Browse files Browse the repository at this point in the history
Handle cat detected status from displayCode field
  • Loading branch information
natekspencer authored Apr 5, 2024
2 parents ec43e57 + cf736ba commit 9ba43df
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
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

0 comments on commit 9ba43df

Please sign in to comment.