Skip to content

Commit

Permalink
fix: avoid reflecting back SMOKE_CMONX when changing smart audio (#141)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco committed Jul 4, 2024
1 parent 1d7fb76 commit 7270a5c
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/uiprotect/data/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,20 @@ def unifi_dict_conversions(cls) -> dict[str, object | Callable[[Any], Any]]:
"autoTrackingObjectTypes": convert_smart_types,
} | super().unifi_dict_conversions()

def unifi_dict(
self,
data: dict[str, Any] | None = None,
exclude: set[str] | None = None,
) -> dict[str, Any]:
data = super().unifi_dict(data=data, exclude=exclude)
if audio_types := data.get("audioTypes"):
# SMOKE_CMONX is not supported for audio types
# and should not be sent to the camera
data["audioTypes"] = [
t for t in audio_types if t != SmartDetectAudioType.SMOKE_CMONX.value
]
return data


class LCDMessage(ProtectBaseObject):
type: DoorbellMessageType
Expand Down
38 changes: 38 additions & 0 deletions tests/data/test_camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
LCDMessage,
PTZPreset,
RecordingMode,
SmartDetectAudioType,
VideoMode,
)
from uiprotect.data.devices import CameraZone, Hotplug, HotplugExtender
Expand Down Expand Up @@ -1017,6 +1018,43 @@ async def test_camera_set_person_track(camera_obj: Camera | None, status: bool):
)


@pytest.mark.skipif(not TEST_CAMERA_EXISTS, reason="Missing testdata")
@pytest.mark.parametrize("status", [True, False])
@pytest.mark.asyncio()
async def test_camera_disable_co(camera_obj: Camera | None, status: bool):
if camera_obj is None:
pytest.skip("No camera_obj obj found")

camera_obj.feature_flags.is_ptz = True
camera_obj.recording_settings.mode = RecordingMode.ALWAYS

if status:
camera_obj.smart_detect_settings.audio_types = []
else:
camera_obj.smart_detect_settings.audio_types = [
SmartDetectAudioType.SMOKE,
SmartDetectAudioType.CMONX,
SmartDetectAudioType.SMOKE_CMONX,
]

camera_obj.api.api_request.reset_mock()

await camera_obj.set_smart_audio_detect_types(
[SmartDetectAudioType.SMOKE, SmartDetectAudioType.SMOKE_CMONX]
)

assert camera_obj.smart_detect_settings.audio_types == [
SmartDetectAudioType.SMOKE,
SmartDetectAudioType.SMOKE_CMONX,
]

camera_obj.api.api_request.assert_called_with(
f"cameras/{camera_obj.id}",
method="patch",
json={"smartDetectSettings": {"audioTypes": ["alrmSmoke"]}},
)


@pytest.mark.skipif(not TEST_CAMERA_EXISTS, reason="Missing testdata")
@pytest.mark.parametrize(
("value", "lux"),
Expand Down

0 comments on commit 7270a5c

Please sign in to comment.