From 6be57614dd0504fd1f685cd717de4bc2241eed0d Mon Sep 17 00:00:00 2001 From: Ryan Gregg Date: Wed, 18 Mar 2026 02:21:31 +0000 Subject: [PATCH] Apply Ruff formatting to Python files Co-Authored-By: Claude Opus 4.6 (1M context) --- frigate/ptz/onvif.py | 15 +++++----- frigate/test/test_ptz_commands.py | 49 +++++++++++++++++++------------ 2 files changed, 38 insertions(+), 26 deletions(-) diff --git a/frigate/ptz/onvif.py b/frigate/ptz/onvif.py index b8107af8d..2ab9fe05a 100644 --- a/frigate/ptz/onvif.py +++ b/frigate/ptz/onvif.py @@ -319,7 +319,9 @@ class OnvifController: self.cams[camera_name]["absolute_move_request"] = move_request except (Fault, ONVIFError, TransportError, Exception) as e: - logger.debug(f"PTZ configuration options not available for {camera_name}: {e}") + logger.debug( + f"PTZ configuration options not available for {camera_name}: {e}" + ) # setup existing presets try: @@ -541,13 +543,10 @@ class OnvifController: move_request.Translation.PanTilt.x = pan move_request.Translation.PanTilt.y = tilt - if ( - "zoom-r" in self.cams[camera_name]["features"] - and ( - zoom != 0 - or self.config.cameras[camera_name].onvif.autotracking.zooming - == ZoomingModeEnum.relative - ) + if "zoom-r" in self.cams[camera_name]["features"] and ( + zoom != 0 + or self.config.cameras[camera_name].onvif.autotracking.zooming + == ZoomingModeEnum.relative ): try: move_request.Speed = { diff --git a/frigate/test/test_ptz_commands.py b/frigate/test/test_ptz_commands.py index 2828d254c..4f0460612 100644 --- a/frigate/test/test_ptz_commands.py +++ b/frigate/test/test_ptz_commands.py @@ -95,8 +95,15 @@ class TestDispatcherPtzParsing(TestCase): self.assertEqual(param, "relative_0.5_-0.3_0.8") def test_simple_commands(self): - for cmd_name in ["move_up", "move_down", "move_left", "move_right", - "stop", "zoom_in", "zoom_out"]: + for cmd_name in [ + "move_up", + "move_down", + "move_left", + "move_right", + "stop", + "zoom_in", + "zoom_out", + ]: command, param = self._parse_ptz_payload(cmd_name) self.assertEqual(command, OnvifCommandEnum[cmd_name]) self.assertEqual(param, "") @@ -136,8 +143,9 @@ class TestDragToZoomCalculation(TestCase): and zoom values sent to the backend. """ - def _calculate_drag_zoom(self, drag_start, drag_end, rect_left, rect_top, - rect_width, rect_height): + def _calculate_drag_zoom( + self, drag_start, drag_end, rect_left, rect_top, rect_width, rect_height + ): """Replicate the drag-to-zoom calculation from LiveCameraView.""" x1 = min(drag_start[0], drag_end[0]) y1 = min(drag_start[1], drag_end[1]) @@ -177,7 +185,8 @@ class TestDragToZoomCalculation(TestCase): zoom = 1 - max(1.0, 0.5) = 0.0. """ pan, tilt, zoom = self._calculate_drag_zoom( - (250, 125), (750, 375), 0, 0, 1000, 500) + (250, 125), (750, 375), 0, 0, 1000, 500 + ) self.assertAlmostEqual(pan, 0.0) self.assertAlmostEqual(tilt, 0.0) self.assertAlmostEqual(zoom, 0.0) @@ -188,7 +197,8 @@ class TestDragToZoomCalculation(TestCase): # box_aspect = 0.5/0.25 = 2.0 = frame_aspect, no expansion # zoom = 1 - max(0.5, 0.25) = 0.5 pan, tilt, zoom = self._calculate_drag_zoom( - (250, 187), (750, 312), 0, 0, 1000, 500) + (250, 187), (750, 312), 0, 0, 1000, 500 + ) self.assertAlmostEqual(pan, 0.0) self.assertAlmostEqual(tilt, 0.002) # slight offset due to rounding self.assertAlmostEqual(zoom, 0.5) @@ -198,8 +208,7 @@ class TestDragToZoomCalculation(TestCase): Box is 0.5x0.5 normalized, aspect correction expands to 1.0 wide. """ - pan, tilt, zoom = self._calculate_drag_zoom( - (0, 0), (500, 250), 0, 0, 1000, 500) + pan, tilt, zoom = self._calculate_drag_zoom((0, 0), (500, 250), 0, 0, 1000, 500) self.assertAlmostEqual(pan, -0.5) self.assertAlmostEqual(tilt, 0.5) self.assertAlmostEqual(zoom, 0.0) @@ -207,7 +216,8 @@ class TestDragToZoomCalculation(TestCase): def test_bottom_right_drag(self): """Drag a box in the bottom-right quadrant of a 2:1 frame.""" pan, tilt, zoom = self._calculate_drag_zoom( - (500, 250), (1000, 500), 0, 0, 1000, 500) + (500, 250), (1000, 500), 0, 0, 1000, 500 + ) self.assertAlmostEqual(pan, 0.5) self.assertAlmostEqual(tilt, -0.5) self.assertAlmostEqual(zoom, 0.0) @@ -215,7 +225,8 @@ class TestDragToZoomCalculation(TestCase): def test_full_frame_drag_no_zoom(self): """Dragging the entire frame should produce zero zoom.""" pan, tilt, zoom = self._calculate_drag_zoom( - (0, 0), (1000, 500), 0, 0, 1000, 500) + (0, 0), (1000, 500), 0, 0, 1000, 500 + ) self.assertAlmostEqual(pan, 0.0) self.assertAlmostEqual(tilt, 0.0) self.assertAlmostEqual(zoom, 0.0) @@ -227,7 +238,8 @@ class TestDragToZoomCalculation(TestCase): # box_aspect = 1.0 < frame_aspect 2.0, expand width: 0.1 * 2.0 = 0.2 # zoom = 1 - max(0.2, 0.1) = 0.8 pan, tilt, zoom = self._calculate_drag_zoom( - (450, 225), (550, 275), 0, 0, 1000, 500) + (450, 225), (550, 275), 0, 0, 1000, 500 + ) self.assertAlmostEqual(pan, 0.0) self.assertAlmostEqual(tilt, 0.0) self.assertAlmostEqual(zoom, 0.8) @@ -237,7 +249,8 @@ class TestDragToZoomCalculation(TestCase): # Frame is 1000x500 (2:1 aspect) # Drag a tall box: 100px wide x 250px tall at center pan, tilt, zoom = self._calculate_drag_zoom( - (450, 125), (550, 375), 0, 0, 1000, 500) + (450, 125), (550, 375), 0, 0, 1000, 500 + ) # Raw box: 0.1 wide x 0.5 tall # box_aspect = 0.1/0.5 = 0.2, frame_aspect = 2.0 # box is taller -> expand width: box_w = 0.5 * 2.0 = 1.0 @@ -251,7 +264,8 @@ class TestDragToZoomCalculation(TestCase): # Frame is 1000x500 (2:1 aspect) # Drag a wide box: 800px wide x 100px tall at center pan, tilt, zoom = self._calculate_drag_zoom( - (100, 200), (900, 300), 0, 0, 1000, 500) + (100, 200), (900, 300), 0, 0, 1000, 500 + ) # Raw box: 0.8 wide x 0.2 tall # box_aspect = 0.8/0.2 = 4.0 > frame_aspect 2.0 # box is wider -> expand height: box_h = 0.8/2.0 = 0.4 @@ -267,17 +281,16 @@ class TestDragToZoomCalculation(TestCase): # Normalized: 0.5x0.5, aspect correction expands width to 1.0 # zoom = 1 - 1.0 = 0.0 pan, tilt, zoom = self._calculate_drag_zoom( - (300, 150), (700, 350), 100, 50, 800, 400) + (300, 150), (700, 350), 100, 50, 800, 400 + ) self.assertAlmostEqual(pan, 0.0) self.assertAlmostEqual(tilt, 0.0) self.assertAlmostEqual(zoom, 0.0) def test_reversed_drag_direction(self): """Dragging bottom-right to top-left should give same result as top-left to bottom-right.""" - result1 = self._calculate_drag_zoom( - (250, 125), (750, 375), 0, 0, 1000, 500) - result2 = self._calculate_drag_zoom( - (750, 375), (250, 125), 0, 0, 1000, 500) + result1 = self._calculate_drag_zoom((250, 125), (750, 375), 0, 0, 1000, 500) + result2 = self._calculate_drag_zoom((750, 375), (250, 125), 0, 0, 1000, 500) for a, b in zip(result1, result2): self.assertAlmostEqual(a, b)