Apply Ruff formatting to Python files

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Ryan Gregg 2026-03-18 02:21:31 +00:00
parent 4a00dbca9d
commit 6be57614dd
2 changed files with 38 additions and 26 deletions

View File

@ -319,7 +319,9 @@ class OnvifController:
self.cams[camera_name]["absolute_move_request"] = move_request self.cams[camera_name]["absolute_move_request"] = move_request
except (Fault, ONVIFError, TransportError, Exception) as e: 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 # setup existing presets
try: try:
@ -541,13 +543,10 @@ class OnvifController:
move_request.Translation.PanTilt.x = pan move_request.Translation.PanTilt.x = pan
move_request.Translation.PanTilt.y = tilt move_request.Translation.PanTilt.y = tilt
if ( if "zoom-r" in self.cams[camera_name]["features"] and (
"zoom-r" in self.cams[camera_name]["features"]
and (
zoom != 0 zoom != 0
or self.config.cameras[camera_name].onvif.autotracking.zooming or self.config.cameras[camera_name].onvif.autotracking.zooming
== ZoomingModeEnum.relative == ZoomingModeEnum.relative
)
): ):
try: try:
move_request.Speed = { move_request.Speed = {

View File

@ -95,8 +95,15 @@ class TestDispatcherPtzParsing(TestCase):
self.assertEqual(param, "relative_0.5_-0.3_0.8") self.assertEqual(param, "relative_0.5_-0.3_0.8")
def test_simple_commands(self): def test_simple_commands(self):
for cmd_name in ["move_up", "move_down", "move_left", "move_right", for cmd_name in [
"stop", "zoom_in", "zoom_out"]: "move_up",
"move_down",
"move_left",
"move_right",
"stop",
"zoom_in",
"zoom_out",
]:
command, param = self._parse_ptz_payload(cmd_name) command, param = self._parse_ptz_payload(cmd_name)
self.assertEqual(command, OnvifCommandEnum[cmd_name]) self.assertEqual(command, OnvifCommandEnum[cmd_name])
self.assertEqual(param, "") self.assertEqual(param, "")
@ -136,8 +143,9 @@ class TestDragToZoomCalculation(TestCase):
and zoom values sent to the backend. and zoom values sent to the backend.
""" """
def _calculate_drag_zoom(self, drag_start, drag_end, rect_left, rect_top, def _calculate_drag_zoom(
rect_width, rect_height): self, drag_start, drag_end, rect_left, rect_top, rect_width, rect_height
):
"""Replicate the drag-to-zoom calculation from LiveCameraView.""" """Replicate the drag-to-zoom calculation from LiveCameraView."""
x1 = min(drag_start[0], drag_end[0]) x1 = min(drag_start[0], drag_end[0])
y1 = min(drag_start[1], drag_end[1]) y1 = min(drag_start[1], drag_end[1])
@ -177,7 +185,8 @@ class TestDragToZoomCalculation(TestCase):
zoom = 1 - max(1.0, 0.5) = 0.0. zoom = 1 - max(1.0, 0.5) = 0.0.
""" """
pan, tilt, zoom = self._calculate_drag_zoom( 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(pan, 0.0)
self.assertAlmostEqual(tilt, 0.0) self.assertAlmostEqual(tilt, 0.0)
self.assertAlmostEqual(zoom, 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 # box_aspect = 0.5/0.25 = 2.0 = frame_aspect, no expansion
# zoom = 1 - max(0.5, 0.25) = 0.5 # zoom = 1 - max(0.5, 0.25) = 0.5
pan, tilt, zoom = self._calculate_drag_zoom( 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(pan, 0.0)
self.assertAlmostEqual(tilt, 0.002) # slight offset due to rounding self.assertAlmostEqual(tilt, 0.002) # slight offset due to rounding
self.assertAlmostEqual(zoom, 0.5) 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. Box is 0.5x0.5 normalized, aspect correction expands to 1.0 wide.
""" """
pan, tilt, zoom = self._calculate_drag_zoom( pan, tilt, zoom = self._calculate_drag_zoom((0, 0), (500, 250), 0, 0, 1000, 500)
(0, 0), (500, 250), 0, 0, 1000, 500)
self.assertAlmostEqual(pan, -0.5) self.assertAlmostEqual(pan, -0.5)
self.assertAlmostEqual(tilt, 0.5) self.assertAlmostEqual(tilt, 0.5)
self.assertAlmostEqual(zoom, 0.0) self.assertAlmostEqual(zoom, 0.0)
@ -207,7 +216,8 @@ class TestDragToZoomCalculation(TestCase):
def test_bottom_right_drag(self): def test_bottom_right_drag(self):
"""Drag a box in the bottom-right quadrant of a 2:1 frame.""" """Drag a box in the bottom-right quadrant of a 2:1 frame."""
pan, tilt, zoom = self._calculate_drag_zoom( 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(pan, 0.5)
self.assertAlmostEqual(tilt, -0.5) self.assertAlmostEqual(tilt, -0.5)
self.assertAlmostEqual(zoom, 0.0) self.assertAlmostEqual(zoom, 0.0)
@ -215,7 +225,8 @@ class TestDragToZoomCalculation(TestCase):
def test_full_frame_drag_no_zoom(self): def test_full_frame_drag_no_zoom(self):
"""Dragging the entire frame should produce zero zoom.""" """Dragging the entire frame should produce zero zoom."""
pan, tilt, zoom = self._calculate_drag_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(pan, 0.0)
self.assertAlmostEqual(tilt, 0.0) self.assertAlmostEqual(tilt, 0.0)
self.assertAlmostEqual(zoom, 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 # 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 # zoom = 1 - max(0.2, 0.1) = 0.8
pan, tilt, zoom = self._calculate_drag_zoom( 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(pan, 0.0)
self.assertAlmostEqual(tilt, 0.0) self.assertAlmostEqual(tilt, 0.0)
self.assertAlmostEqual(zoom, 0.8) self.assertAlmostEqual(zoom, 0.8)
@ -237,7 +249,8 @@ class TestDragToZoomCalculation(TestCase):
# Frame is 1000x500 (2:1 aspect) # Frame is 1000x500 (2:1 aspect)
# Drag a tall box: 100px wide x 250px tall at center # Drag a tall box: 100px wide x 250px tall at center
pan, tilt, zoom = self._calculate_drag_zoom( 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 # Raw box: 0.1 wide x 0.5 tall
# box_aspect = 0.1/0.5 = 0.2, frame_aspect = 2.0 # 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 # 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) # Frame is 1000x500 (2:1 aspect)
# Drag a wide box: 800px wide x 100px tall at center # Drag a wide box: 800px wide x 100px tall at center
pan, tilt, zoom = self._calculate_drag_zoom( 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 # Raw box: 0.8 wide x 0.2 tall
# box_aspect = 0.8/0.2 = 4.0 > frame_aspect 2.0 # 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 # 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 # Normalized: 0.5x0.5, aspect correction expands width to 1.0
# zoom = 1 - 1.0 = 0.0 # zoom = 1 - 1.0 = 0.0
pan, tilt, zoom = self._calculate_drag_zoom( 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(pan, 0.0)
self.assertAlmostEqual(tilt, 0.0) self.assertAlmostEqual(tilt, 0.0)
self.assertAlmostEqual(zoom, 0.0) self.assertAlmostEqual(zoom, 0.0)
def test_reversed_drag_direction(self): def test_reversed_drag_direction(self):
"""Dragging bottom-right to top-left should give same result as top-left to bottom-right.""" """Dragging bottom-right to top-left should give same result as top-left to bottom-right."""
result1 = self._calculate_drag_zoom( result1 = self._calculate_drag_zoom((250, 125), (750, 375), 0, 0, 1000, 500)
(250, 125), (750, 375), 0, 0, 1000, 500) result2 = self._calculate_drag_zoom((750, 375), (250, 125), 0, 0, 1000, 500)
result2 = self._calculate_drag_zoom(
(750, 375), (250, 125), 0, 0, 1000, 500)
for a, b in zip(result1, result2): for a, b in zip(result1, result2):
self.assertAlmostEqual(a, b) self.assertAlmostEqual(a, b)