From f6e23572631718f266f6c6234aa270c5bd7af985 Mon Sep 17 00:00:00 2001 From: Nick Mowen Date: Wed, 14 Dec 2022 12:08:11 -0700 Subject: [PATCH] Fix bugs --- frigate/comms/dispatcher.py | 11 +++++++---- frigate/comms/mqtt.py | 2 +- frigate/ptz.py | 9 ++++++--- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/frigate/comms/dispatcher.py b/frigate/comms/dispatcher.py index a555a98ab..4ae11ae7c 100644 --- a/frigate/comms/dispatcher.py +++ b/frigate/comms/dispatcher.py @@ -70,7 +70,7 @@ class Dispatcher: camera_name = topic.split("/")[-3] command = topic.split("/")[-2] self._camera_settings_handlers[command](camera_name, payload) - except Exception as e: + except IndexError as e: logger.error(f"Received invalid set command: {topic}") return elif topic.endswith("ptz"): @@ -78,7 +78,7 @@ class Dispatcher: # example /cam_name/ptz payload=MOVE_UP|MOVE_DOWN|STOP... camera_name = topic.split("/")[-2] self._on_ptz_command(camera_name, payload) - except Exception as e: + except IndexError as e: logger.error(f"Received invalid ptz command: {topic}") return elif topic == "restart": @@ -222,5 +222,8 @@ class Dispatcher: try: command = OnvifCommandEnum[payload.lower()] self.onvif.handle_command(camera_name, command) - except Exception as e: - return + logger.info(f"Setting ptz command to {command} for {camera_name}") + except KeyError as k: + logger.error(f"Invalid PTZ command {payload}: {k.with_traceback()}") + #except Exception as e: + # logger.error(f"Error sending {payload} to {camera_name}: {e}") diff --git a/frigate/comms/mqtt.py b/frigate/comms/mqtt.py index 7db2cafb5..37fdd44ae 100644 --- a/frigate/comms/mqtt.py +++ b/frigate/comms/mqtt.py @@ -169,7 +169,7 @@ class MqttClient(Communicator): # type: ignore[misc] if self.config.cameras[name].onvif.host: self.client.message_callback_add( - f"{self.mqtt_config.topic_prefix}/{name}/ptz/#", + f"{self.mqtt_config.topic_prefix}/{name}/ptz", self.on_mqtt_command, ) diff --git a/frigate/ptz.py b/frigate/ptz.py index 29b11b647..abacba40f 100644 --- a/frigate/ptz.py +++ b/frigate/ptz.py @@ -38,6 +38,7 @@ class OnvifController: } def _init_onvif(self, camera_name: str) -> None: + logger.error(f"Init onvif...") onvif: ONVIFCamera = self.cams[camera_name]["onvif"] media = onvif.create_media_service() profile = media.GetProfiles()[0] @@ -56,6 +57,7 @@ class OnvifController: self.cams[camera_name]["move_request"] = move_request def _stop(self, camera_name: str) -> None: + logger.error(f"Stop onvif") onvif: ONVIFCamera = self.cams[camera_name]["onvif"] move_request = self.cams[camera_name]["move_request"] onvif.get_service("ptz").Stop( @@ -68,6 +70,7 @@ class OnvifController: self.cams[camera_name]["active"] = False def _move(self, camera_name: str, command: OnvifCommandEnum) -> None: + logger.error(f"Move onvif {command}") if self.cams[camera_name]["active"]: logger.warning( f"{camera_name} is already performing an action, stopping..." @@ -78,13 +81,13 @@ class OnvifController: onvif: ONVIFCamera = self.cams[camera_name]["onvif"] move_request = self.cams[camera_name]["move_request"] - if command == OnvifCommandEnum.left: + if command == OnvifCommandEnum.move_left: move_request.Velocity.PanTilt.x = -0.5 move_request.Velocity.PanTilt.y = 0 - elif command == OnvifCommandEnum.right: + elif command == OnvifCommandEnum.move_right: move_request.Velocity.PanTilt.x = 0.5 move_request.Velocity.PanTilt.y = 0 - elif command == OnvifCommandEnum.up: + elif command == OnvifCommandEnum.move_up: move_request.Velocity.PanTilt.x = 0 move_request.Velocity.PanTilt.y = 1 else: