Skip to content

Commit

Permalink
Match all 11.x or newer firmware #975
Browse files Browse the repository at this point in the history
  • Loading branch information
mrlt8 committed Sep 12, 2023
1 parent bf1d3e3 commit 761cc0e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
10 changes: 9 additions & 1 deletion app/wyzebridge/bridge_utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import contextlib
import os
from typing import Any
from typing import Any, Optional

from wyzecam.api_models import WyzeCamera

Expand Down Expand Up @@ -64,3 +65,10 @@ def is_livestream(uri: str) -> bool:
services = {"youtube", "facebook", "livestream"}

return any(env_bool(f"{service}_{uri}") for service in services)


def is_fw11(fw_ver: Optional[str]) -> bool:
with contextlib.suppress(IndexError, ValueError):
if fw_ver and int(fw_ver.split(".")[2]) > 10:
return True
return False
10 changes: 5 additions & 5 deletions app/wyzebridge/wyze_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from typing import Any, Optional

import requests
from wyzebridge.bridge_utils import env_bool
from wyzebridge.bridge_utils import env_bool, is_fw11
from wyzebridge.config import BOA_COOLDOWN, BOA_INTERVAL, IMG_PATH, MQTT_TOPIC
from wyzebridge.logging import logger
from wyzebridge.mqtt import MQTT_ENABLED, publish_messages
Expand Down Expand Up @@ -138,15 +138,14 @@ def camera_control(
:param uri: URI-safe name of the camera.
"""
boa = check_boa_enabled(sess, uri)
fw_11 = sess.camera.firmware_ver and sess.camera.firmware_ver.startswith("4.36.11")

while sess.state == WyzeIOTCSessionState.AUTHENTICATION_SUCCEEDED:
boa_control(sess, boa)
try:
cmd = camera_cmd.get(timeout=BOA_INTERVAL)
topic, payload = cmd if isinstance(cmd, tuple) else (cmd, None)
except Empty:
update_params(sess, bool(fw_11))
update_params(sess)
continue

if topic == "caminfo":
Expand All @@ -162,7 +161,7 @@ def camera_control(
resp = update_bit_fps(sess, topic, payload)
else:
# Use K10050GetVideoParam if newer firmware
if topic == "bitrate" and fw_11:
if topic == "bitrate" and is_fw11(sess.camera.firmware_ver):
cmd = "_bitrate"
resp = send_tutk_msg(sess, cmd)
if boa and cmd == "take_photo":
Expand All @@ -171,12 +170,13 @@ def camera_control(
camera_info.put({topic: resp})


def update_params(sess: WyzeIOTCSession, fw_11: bool = False):
def update_params(sess: WyzeIOTCSession):
"""
Update camera parameters.
"""
if sess.state != WyzeIOTCSessionState.AUTHENTICATION_SUCCEEDED:
return
fw_11 = is_fw11(sess.camera.firmware_ver)

if MQTT_ENABLED or not fw_11:
remove = {"bitrate", "res"} if fw_11 else set()
Expand Down

0 comments on commit 761cc0e

Please sign in to comment.