Skip to content

Commit

Permalink
Remove WaitTime enum and use int/hex conversion instead
Browse files Browse the repository at this point in the history
  • Loading branch information
natekspencer committed Dec 16, 2020
1 parent a338131 commit 5f6d3e9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 16 deletions.
23 changes: 8 additions & 15 deletions pylitterbot/robot.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
from enum import Enum
from typing import Iterable, Optional

import requests

from .const import CYCLE_CAPACITY, CYCLE_COUNT, DRAWER_FULL_CYCLES, NAME
from .exceptions import InvalidCommandException, LitterRobotException
from .session import Session
Expand All @@ -18,6 +16,8 @@
class Robot:
"""Data and methods for interacting with a Litter-Robot Connect self-cleaning litter box"""

VALID_WAIT_TIMES = [3, 7, 15]

class UnitStatus(Enum):
BR = "Bonnet Removed"
CCC = "Clean Cycle Complete"
Expand All @@ -42,11 +42,6 @@ class UnitStatus(Enum):
SDF = "Drawer Full (0 cycles left)"
SPF = "Pinch Detect Startup"

class WaitTime(Enum):
THREE_MINUTES = "3"
SEVEN_MINUTES = "7"
FIFTEEN_MINUTES = "F"

class Commands:
"""Known commands that can be sent to trigger an action or setting for a Litter-Robot Connect self-cleaning litter box"""

Expand Down Expand Up @@ -122,9 +117,7 @@ def refresh_robot_info(self, data: dict = None):
self.auto_offline_disabled = data["autoOfflineDisabled"]
self.setup_date = self.from_litter_robot_timestamp(data["setupDate"])
self.dfi_cycle_count = int(data["DFICycleCount"])
self.clean_cycle_wait_time_minutes = self.WaitTime(
data["cleanCycleWaitTimeMinutes"]
)
self.clean_cycle_wait_time_minutes = int(data["cleanCycleWaitTimeMinutes"], 16)
self.unit_status = self.UnitStatus[data["unitStatus"]]
self.is_onboarded = data["isOnboarded"]
self.device_type = data["deviceType"]
Expand Down Expand Up @@ -192,17 +185,17 @@ def set_sleep_mode(self, value: bool, sleep_time: time = None):
f"An attempt to turn on sleep mode was received with an invalid time. Check the time and try again."
)
return self._dispatch_command(
f"{self.Commands.SLEEP_MODE_ON}{(datetime(2, 1, 1) - (datetime.combine(datetime.now(timezone.utc),sleep_time,sleep_time.tzinfo if sleep_time.tzinfo else timezone.utc,)- datetime.now(timezone.utc))).strftime('%H:%M:%S')}"
f"{self.Commands.SLEEP_MODE_ON}{(datetime(2, 1, 1) - (datetime.combine(datetime.now(timezone.utc),sleep_time,sleep_time.tzinfo if sleep_time.tzinfo else timezone.utc)- datetime.now(timezone.utc))).strftime('%H:%M:%S')}"
if value
else self.Commands.SLEEP_MODE_OFF
)

def set_wait_time(self, wait_time: WaitTime):
if not isinstance(wait_time, Robot.WaitTime):
def set_wait_time(self, wait_time: int):
if wait_time not in self.VALID_WAIT_TIMES:
raise InvalidCommandException(
f"Attempt to send an invalid wait time to Litter-Robot. Wait time must be one of: [3, 7, F], but received {wait_time}"
f"Attempt to send an invalid wait time to Litter-Robot. Wait time must be one of: {self.VALID_WAIT_TIMES}, but received {wait_time}"
)
return self._dispatch_command(f"{self.Commands.WAIT_TIME}{wait_time.value}")
return self._dispatch_command(f"{self.Commands.WAIT_TIME}{f'{wait_time:X}'}")

def set_robot_name(self, name: str):
data = self._patch({NAME: name})
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setup(
name="pylitterbot",
version="0.1.0",
version="0.1.1",
description="Python package for controlling a Litter-Robot Connect self-cleaning litter box",
long_description=long_description,
long_description_content_type="text/markdown",
Expand Down

0 comments on commit 5f6d3e9

Please sign in to comment.