Skip to content

Commit

Permalink
SET cruise_point #835
Browse files Browse the repository at this point in the history
  • Loading branch information
mrlt8 committed Jul 19, 2023
1 parent 2b18354 commit 9dd5707
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app/wyzebridge/wyze_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
SET_CMDS = {
"state": None,
"power": None,
"time_zone": None,
"cruise_point": None,
"irled": "K10046SetIRLEDStatus",
"night_vision": "K10042SetNightVisionStatus",
"status_light": "K10032SetNetworkLightStatus",
Expand All @@ -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",
Expand Down
33 changes: 33 additions & 0 deletions app/wyzebridge/wyze_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand All @@ -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]:
Expand Down

0 comments on commit 9dd5707

Please sign in to comment.