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

Cache supported commands for each WyzeCamera #922

Closed
wants to merge 1 commit into from
Closed
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
10 changes: 9 additions & 1 deletion app/wyzecam/api_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ class WyzeCamera(BaseModel):
mac: str
product_model: str
camera_info: Optional[dict[str, Any]] = None
supported_commands: Optional[list[str]] = None
nickname: Optional[str]
timezone_name: Optional[str]
firmware_ver: Optional[str]
Expand All @@ -126,9 +127,16 @@ class WyzeCamera(BaseModel):
parent_mac: Optional[str]
thumbnail: Optional[str]

def set_camera_info(self, info: dict[str, Any]) -> None:
def set_camera_info(self, info: dict[str, Any], commands: list[str] = None) -> None:
# Called internally as part of WyzeIOTC.connect_and_auth()
self.camera_info = info
self.supported_commands = commands

def supports_command(self, command: int) -> bool:
"""Return whether the command is supported by this camera."""
if self.supported_commands:
return str(command) in self.supported_commands
return False

@property
def name_uri(self) -> str:
Expand Down
6 changes: 5 additions & 1 deletion app/wyzecam/iotc.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
K10020CheckCameraParams,
K10052DBSetResolvingBit,
K10056SetResolvingBit,
get_supported_commands,
respond_to_ioctrl_10001,
)

Expand Down Expand Up @@ -1000,7 +1001,10 @@ def _auth(self):
if auth_response["connectionRes"] != "1":
warnings.warn(f"AUTH FAILED: {auth_response}")
raise ValueError("AUTH_FAILED")
self.camera.set_camera_info(auth_response["cameraInfo"])
self.camera.set_camera_info(
auth_response["cameraInfo"],
get_supported_commands(self.camera.product_model, challenge.resp_protocol),
)
frame_bit = self.preferred_frame_size, self.preferred_bitrate
if self.camera.product_model in (
"WYZEDB3",
Expand Down
6 changes: 5 additions & 1 deletion app/wyzecam/tutk/tutk_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -1073,7 +1073,7 @@ def respond_to_ioctrl_10001(
return response


def supports(product_model, protocol, command):
def get_supported_commands(product_model, protocol):
with open(project_root / "device_config.json") as f:
device_config = json.load(f)
commands_db = device_config["supportedCommands"]
Expand All @@ -1090,5 +1090,9 @@ def supports(product_model, protocol, command):
for k in commands_db[product_model]:
if int(k) <= int(protocol):
supported_commands.extend(commands_db[product_model][k])
return supported_commands


def supports(product_model, protocol, command):
supported_commands = get_supported_commands(product_model, protocol)
return str(command) in supported_commands