diff --git a/app/wyzebridge/bridge_utils.py b/app/wyzebridge/bridge_utils.py index 60705b54..862b264a 100644 --- a/app/wyzebridge/bridge_utils.py +++ b/app/wyzebridge/bridge_utils.py @@ -1,5 +1,6 @@ +import contextlib import os -from typing import Any +from typing import Any, Optional from wyzecam.api_models import WyzeCamera @@ -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 diff --git a/app/wyzebridge/wyze_control.py b/app/wyzebridge/wyze_control.py index 8db08aaf..e2db8099 100644 --- a/app/wyzebridge/wyze_control.py +++ b/app/wyzebridge/wyze_control.py @@ -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 @@ -138,7 +138,6 @@ 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) @@ -146,7 +145,7 @@ def camera_control( 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": @@ -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": @@ -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()