From 84eacf432ef809d36e6184cbc292697daa89f193 Mon Sep 17 00:00:00 2001 From: Anubhav Lal <67056859+anubhavlal07@users.noreply.github.com> Date: Sat, 28 Nov 2026 20:49:35 +0530 Subject: [PATCH] Fix swapped pan directions for smartcam pantilt module (#1858) --- kasa/smartcam/modules/pantilt.py | 4 ++-- tests/smartcam/modules/test_pantilt.py | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/kasa/smartcam/modules/pantilt.py b/kasa/smartcam/modules/pantilt.py index 52b2db0d..d6268e25 100644 --- a/kasa/smartcam/modules/pantilt.py +++ b/kasa/smartcam/modules/pantilt.py @@ -35,7 +35,7 @@ class PanTilt(SmartCamModule): "pan_right", "Pan right", container=self, - attribute_setter=lambda: self.pan(self._pan_step * -1), + attribute_setter=lambda: self.pan(self._pan_step), type=Feature.Type.Action, ) ) @@ -45,7 +45,7 @@ class PanTilt(SmartCamModule): "pan_left", "Pan left", container=self, - attribute_setter=lambda: self.pan(self._pan_step), + attribute_setter=lambda: self.pan(self._pan_step * -1), type=Feature.Type.Action, ) ) diff --git a/tests/smartcam/modules/test_pantilt.py b/tests/smartcam/modules/test_pantilt.py index 626ac333..8c88df5a 100644 --- a/tests/smartcam/modules/test_pantilt.py +++ b/tests/smartcam/modules/test_pantilt.py @@ -210,3 +210,25 @@ async def test_pantilt_no_presets_in_data(dev: Device, mocker: MockerFixture) -> assert pantilt_mod._presets == {} assert pantilt_mod.presets == {} + + +@pantilt +@pytest.mark.parametrize( + ("feature_id", "x_coord", "y_coord"), + [ + ("pan_right", "30", "0"), + ("pan_left", "-30", "0"), + ("tilt_up", "0", "10"), + ("tilt_down", "0", "-10"), + ], +) +async def test_pantilt_direction_features( + dev: Device, mocker: MockerFixture, feature_id: str, x_coord: str, y_coord: str +) -> None: + mock_protocol_query = mocker.patch.object(dev.protocol, "query", return_value={}) + + await dev.features[feature_id].set_value(None) + + mock_protocol_query.assert_called_with( + request={"do": {"motor": {"move": {"x_coord": x_coord, "y_coord": y_coord}}}} + )