diff --git a/app/wyzebridge/wyze_commands.py b/app/wyzebridge/wyze_commands.py index 2a0c9867..b7956090 100644 --- a/app/wyzebridge/wyze_commands.py +++ b/app/wyzebridge/wyze_commands.py @@ -28,6 +28,8 @@ SET_CMDS = { "state": None, "power": None, + "time_zone": None, + "cruise_point": None, "irled": "K10046SetIRLEDStatus", "night_vision": "K10042SetNightVisionStatus", "status_light": "K10032SetNetworkLightStatus", @@ -44,8 +46,6 @@ "ptz_position": "K11018SetPTZPosition", "motion_tracking": "K11022SetMotionTracking", "motion_tagging": "K10292SetMotionTagging", - # "time_zone": "K10302SetTimeZone", - "time_zone": None, "fps": "K10052SetFPS", "bitrate": "K10052SetBitrate", "rtsp": "K10600SetRtspSwitch", diff --git a/app/wyzebridge/wyze_control.py b/app/wyzebridge/wyze_control.py index b8e12208..7efe0def 100644 --- a/app/wyzebridge/wyze_control.py +++ b/app/wyzebridge/wyze_control.py @@ -163,6 +163,8 @@ def camera_control( "last_photo": boa["last_photo"], } resp = {topic: cam_info} + if topic == "cruise_point": + resp = {topic: pan_to_cruise_point(sess, cmd)} else: resp = send_tutk_msg(sess, cmd) if boa and cmd == "take_photo": @@ -177,6 +179,37 @@ def camera_control( camera_info.put(resp, block=False) +def pan_to_cruise_point(sess: WyzeIOTCSession, cmd): + """ + Pan to cruise point/waypoint. + """ + resp = {"command": "cruise_point", "status": "error", "value": None} + if not isinstance(cmd, tuple) or not str(cmd[1]).isdigit(): + return resp | {"response": f"Invalid cruise point: {cmd=}"} + + i = int(cmd[1]) + with sess.iotctrl_mux() as mux: + points = mux.send_ioctl(tutk_protocol.K11010GetCruisePoints()).result(timeout=5) + if not points or not isinstance(points, list): + return resp | {"response": f"Invalid cruise points: {points=}"} + + try: + waypoints = (points[i]["vertical"], points[i]["horizontal"]) + except IndexError: + return resp | {"response": f"Cruise point NOT found. {points=}"} + + logger.info(f"Pan to cruise_point={i} ({waypoints})") + res = mux.send_ioctl(tutk_protocol.K11018SetPTZPosition(*waypoints)).result( + timeout=5 + ) + + return resp | { + "status": "success", + "response": ",".join(map(str, res)) if isinstance(res, bytes) else res, + "value": i, + } + + def update_mqtt_values(topic: str, cam_name: str, resp: dict): base = f"{MQTT_TOPIC}/{cam_name}" if msgs := [(f"{base}/{k}", resp[v]) for k, v in PARAMS.items() if v in resp]: