diff --git a/simplipy/device/__init__.py b/simplipy/device/__init__.py index f1bd551b..2900e880 100644 --- a/simplipy/device/__init__.py +++ b/simplipy/device/__init__.py @@ -32,6 +32,7 @@ class DeviceTypes(Enum): LOCK = 16 OUTDOOR_CAMERA = 17 MOTION_V2 = 20 + SCOUT_CAMERA = 21 OUTDOOR_ALARM_SECURITY_BELL_BOX = 22 LOCK_KEYPAD = 253 UNKNOWN = 99 diff --git a/simplipy/device/camera.py b/simplipy/device/camera.py index 56b790d1..e2bca444 100644 --- a/simplipy/device/camera.py +++ b/simplipy/device/camera.py @@ -23,6 +23,7 @@ class CameraTypes(Enum): CAMERA = 0 DOORBELL = 1 OUTDOOR_CAMERA = 2 + SCOUT_CAMERA = 3 UNKNOWN = 99 @@ -31,6 +32,7 @@ class CameraTypes(Enum): "SS002": CameraTypes.DOORBELL, "SS003": CameraTypes.CAMERA, "SSOBCM4": CameraTypes.OUTDOOR_CAMERA, + "scout": CameraTypes.SCOUT_CAMERA, } diff --git a/tests/common.py b/tests/common.py index 8f75f113..01dadcdb 100644 --- a/tests/common.py +++ b/tests/common.py @@ -18,6 +18,8 @@ TEST_LOCK_ID = "987" TEST_LOCK_ID_2 = "654" TEST_LOCK_ID_3 = "321" +TEST_SCOUT_CAMERA_ID = "0000000000000000000000000000abcd" +TEST_SCOUT_SERIAL = "0000abcd" TEST_REFRESH_TOKEN = "qrstu98765" # noqa: S105 TEST_SUBSCRIPTION_ID = 12345 TEST_SYSTEM_ID = 12345 diff --git a/tests/fixtures/scout_camera.json b/tests/fixtures/scout_camera.json new file mode 100644 index 00000000..adddaa07 --- /dev/null +++ b/tests/fixtures/scout_camera.json @@ -0,0 +1,327 @@ +{ + "uuid": "0000000000000000000000000000abcd", + "uid": 12345, + "sid": 12345, + "cameraSettings": { + "activityZones": { + "zones": [] + }, + "spotlight": { + "enableColorNightMode": false + }, + "videoFlip": { + "enable": false, + "verticalFlip": false, + "horizontalFlip": false + }, + "alarmState": { + "recordOnAlarm": false, + "recordOnCount": false, + "spotlightFlashOnAlarm": false, + "sirenOnAlarm": false + }, + "motion": { + "enable": { + "off": false, + "home": false, + "away": true + }, + "granularObjectDetectionTypes": [] + }, + "notifications": { + "motion": { + "off": false, + "home": false, + "away": true + } + }, + "videoTimestamp": { + "enabled": false + }, + "cameraName": "Scout", + "pictureQuality": "1536p", + "nightVision": "auto", + "statusLight": "on", + "micSensitivity": 55, + "micEnable": true, + "speakerVolume": 50, + "motionSensitivity": 50, + "shutterHome": "closedAlarmOnly", + "shutterAway": "open", + "shutterOff": "closedAlarmOnly", + "wifiSsid": "REDACTED", + "canStream": false, + "canRecord": false, + "pirEnable": true, + "vaEnable": false, + "notificationsEnable": true, + "enableDoorbellNotification": true, + "doorbellChimeVolume": "off", + "doorbellChimeType": "Mechanical", + "privacyEnable": false, + "hdr": false, + "vaZoningEnable": false, + "vaZoningRows": 0, + "vaZoningCols": 0, + "vaZoningMask": [], + "maxDigitalZoom": 10, + "supportedResolutions": ["640p", "960p", "1536p"], + "admin": { + "tinyYolo": { + "numFramesToAnalyze": 5, + "confidenceThreshold": 0.9, + "positiveFramesThreshold": 0.5 + }, + "powerControl": { + "disabled": false + }, + "wakeModeOperation": { + "custom": { + "upperRFThresholdRX": 0, + "lowerRFThresholdRX": 0, + "upperRFThresholdTX": 0, + "lowerRFThresholdTX": 0 + }, + "mode": "AUTO" + }, + "messageDispatch": { + "motionEvent": "APERTURE" + }, + "IRLED": 0, + "pirSens": 0, + "statusLEDState": 1, + "lux": "lowLux", + "motionDetectionEnabled": false, + "motionThresholdZero": 0, + "motionThresholdOne": 10000, + "levelChangeDelayZero": 30, + "levelChangeDelayOne": 10, + "audioDetectionEnabled": false, + "audioChannelNum": 2, + "audioSampleRate": 16000, + "audioChunkBytes": 2048, + "audioSampleFormat": 3, + "audioSensitivity": 50, + "audioThreshold": 50, + "audioDirection": 0, + "bitRate": 2000000, + "longPress": "REDACTED", + "kframe": 1, + "gopLength": 40, + "idr": 1, + "fps": 20, + "firmwareVersion": "1.53.3.44371", + "netConfigVersion": "", + "camAgentVersion": "", + "lastLogin": 1794329461, + "lastLogout": 1794329467, + "pirSampleRateMs": 800, + "pirHysteresisHigh": 2, + "pirHysteresisLow": 10, + "pirFilterCoefficient": 1, + "pirSensitivityThreshold": 40, + "pirBlindTime": 2, + "pirPulseCount": 1, + "pirWindowTime": 2, + "pirSignalSource": 0, + "pirHpfCutoff": 0, + "pirPulseDetectionMode": 0, + "pirOperationMode": 2, + "pirLevel": "medium", + "logEnabled": true, + "logLevel": 3, + "logQDepth": 20, + "firmwareGroup": "public", + "otaProvider": "malbec", + "irOpenThreshold": 750, + "irCloseThreshold": 1000, + "irOpenDelay": 3, + "irCloseDelay": 3, + "irThreshold1x": 600, + "irThreshold2x": 450, + "irThreshold3x": 300, + "statsPeriod": 3600000, + "sarlaccDebugLogTypes": 0, + "odProcessingFps": 8, + "odObjectMinWidthPercent": 6, + "odObjectMinHeightPercent": 24, + "odEnableObjectDetection": true, + "odClassificationMask": 2, + "odClassificationConfidenceThreshold": 0.95, + "odEnableOverlay": false, + "odAnalyticsLib": 2, + "odSensitivity": 85, + "odEventObjectMask": 15, + "odLuxThreshold": 445, + "odLuxHysteresisHigh": 4, + "odLuxHysteresisLow": 4, + "odLuxSamplingFrequency": 30, + "odFGExtractorMode": 2, + "odVideoScaleFactor": 1, + "odSceneType": 1, + "odCameraView": 3, + "odCameraFOV": 2, + "odBackgroundLearnStationary": true, + "odBackgroundLearnStationarySpeed": 15, + "odClassifierQualityProfile": 1, + "odEnableVideoAnalyticsWhileStreaming": false, + "wlanMac": "00:00:00:00:00:00", + "region": "us-west-2", + "webRTCProvider": "kvs", + "recordingProvider": "kvs", + "enableWifiAnalyticsLib": false, + "alwaysUploadBitmap": 0, + "outdoorMonitoringEnabled": false, + "account": "000000000000", + "ivLicense": "", + "battery": [ + [1794080675, 92], + [1794080841, 99], + [1794080866, 92], + [1794080960, 100], + [1794081153, 100], + [1794081441, 100], + [1794081868, 100], + [1794329327, 100] + ], + "rssi": [ + [1794080675, -57], + [1794080841, -49], + [1794080866, -52], + [1794080960, -53], + [1794081017, -51], + [1794081101, -45], + [1794081153, -46], + [1794081441, -41], + [1794081868, -55], + [1794329327, -53] + ], + "vmUse": 0, + "resSet": 0, + "uptime": 0, + "wifiDisconnects": 0, + "wifiDriverReloads": 0 + }, + "motionNotificationsOnlyWhileUnmonitored": false, + "aiEventSummaryEnabled": false, + "pirLevel": "medium", + "odLevel": "medium" + }, + "cameraStatus": { + "firmwareVersion": "1.53.3.44371", + "netConfigVersion": "", + "camAgentVersion": "", + "otaUpgradeStatus": "", + "lastConnected": 1794329460, + "lastLogin": 1794329461, + "lastLogout": 1794329467, + "wlanMac": "00:00:00:00:00:00", + "fwDownloadVersion": "", + "fwDownloadPercentage": 0, + "recovered": false, + "recoveredFromVersion": "", + "setupTimestamp": 1794080647, + "monitoredPerformanceModeActive": false, + "unmetPerformanceModeCriteria": ["POWER"], + "_id": "000000000000000000000000", + "initErrors": [], + "monitoredPerformanceModeLastChanged": 1794080647973, + "speedTestTokenCreated": 1794080648, + "batteryPercentage": 100 + }, + "staleSettingsTypes": [], + "upgradeWhitelisted": false, + "model": "scout", + "__v": 0, + "supportedFeatures": { + "providers": { + "allSupportedProviders": { + "webrtc": ["kvs", "mist"], + "recording": ["kvs", "mist"], + "live": [] + }, + "webrtc": "kvs", + "recording": "kvs", + "live": "none" + }, + "receiptCapabilities": { + "wake": [], + "record": [] + }, + "activityZones": { + "maxVertices": 0, + "maxZones": 0, + "zoneTypes": [] + }, + "pir": true, + "videoAnalytics": true, + "privacyShutter": true, + "microphone": "REDACTED", + "fullDuplexAudio": true, + "wired": false, + "battery": true, + "aspectRatio": "1:1", + "networkSpeedTest": true, + "speaker": true, + "spotlight": false, + "spotlightManualControl": false, + "colorNightMode": false, + "videoFlip": false, + "doorbell": false, + "videoAnalyticsZones": true, + "pairedToBasestation": true, + "modeChangeEventsOverWifi": true, + "siren": true, + "sirenManualControl": false, + "sirenManualControlV2": false, + "forceStatusLightsOn": false, + "supportsEventUuid": true, + "deviceManagedRecordings": true, + "doorbellChimeSupported": false, + "supportedChimeTypes": [], + "digitalChimeDuration": false, + "doorbellButtonSound": false, + "canTriggerBSAlarm": true, + "cameraEventsWithSystemState": true, + "granularObjectDetectionTypes": [], + "videoEncoding": "h264", + "audioEncodings": ["aac"], + "resolutions": ["640p", "960p", "1536p"], + "monitoredLiveStream": true, + "outdoorMonitoring": false, + "videoTimestamp": true, + "_id": "000000000000000000000000", + "aiEventSummary": false + }, + "hubId": "00000000", + "serial": "0000abcd", + "subscription": { + "enabled": false, + "freeTrialActive": false, + "freeTrialUsed": false, + "freeTrialEnds": 0, + "freeTrialExpires": 0, + "planSku": "", + "price": 0, + "expires": 0, + "storageDays": 0, + "trialUsed": false, + "trialActive": false, + "trialExpires": 0 + }, + "currentState": { + "idle": false, + "liveStreaming": false, + "recording": false, + "otaDownloading": false, + "otaFlashing": false, + "batteryCharging": false, + "ts": 1794329467, + "online": false, + "connected": false, + "wifiAwakeEnabled": false, + "webrtcProvider": "KVS", + "recordingProvider": "KVS" + }, + "status": "offline" +} diff --git a/tests/fixtures/scout_sensor.json b/tests/fixtures/scout_sensor.json new file mode 100644 index 00000000..e4ed5464 --- /dev/null +++ b/tests/fixtures/scout_sensor.json @@ -0,0 +1,22 @@ +{ + "flags": { + "offline": false, + "lowBattery": false, + "swingerShutdown": false + }, + "serial": "0000abcd", + "type": 21, + "name": "REDACTED", + "setting": { + "off": 0, + "home": 0, + "home2": 0, + "away": 1, + "away2": 0, + "instantTrigger": false + }, + "status": {}, + "timestamp": 1794080623, + "deviceGroupID": 0, + "firmwareVersion": "0.0.0" +} diff --git a/tests/test_camera.py b/tests/test_camera.py index c1fdaae9..39588676 100644 --- a/tests/test_camera.py +++ b/tests/test_camera.py @@ -2,13 +2,17 @@ from __future__ import annotations -from typing import cast +import copy +import json +import logging +from typing import Any, cast import aiohttp import pytest from aresponses import ResponsesMockServer from simplipy import API +from simplipy.device import DeviceTypes, get_device_type_from_data from simplipy.device.camera import CameraTypes from simplipy.system.v3 import SystemV3 @@ -17,7 +21,12 @@ TEST_CAMERA_ID, TEST_CAMERA_ID_2, TEST_CODE_VERIFIER, + TEST_SCOUT_CAMERA_ID, + TEST_SCOUT_SERIAL, + TEST_SUBSCRIPTION_ID, TEST_SYSTEM_ID, + TEST_USER_ID, + load_fixture, ) @@ -97,3 +106,86 @@ async def test_video_urls( ) aresponses.assert_plan_strictly_followed() + + +@pytest.fixture(name="scout_server") +def scout_server_fixture( + authenticated_simplisafe_server: ResponsesMockServer, + subscriptions_response: dict[str, Any], + v3_sensors_response: dict[str, Any], + v3_settings_response: dict[str, Any], +) -> ResponsesMockServer: + """Define a V3 server whose system also includes a Scout indoor camera. + + The camera shows up twice in the real API: once in the subscription's camera list + (model "scout") and once in the sensors list (device type 21). + + Args: + authenticated_simplisafe_server: A mock SimpliSafe cloud API connection. + subscriptions_response: An API response payload. + v3_sensors_response: An API response payload. + v3_settings_response: An API response payload. + + Returns: + A mock server. + """ + subscriptions = copy.deepcopy(subscriptions_response) + sensors = copy.deepcopy(v3_sensors_response) + subscriptions["subscriptions"][0]["location"]["system"]["cameras"].append( + json.loads(load_fixture("scout_camera.json")) + ) + sensors["sensors"].append(json.loads(load_fixture("scout_sensor.json"))) + + for path, payload in ( + (f"/v1/users/{TEST_USER_ID}/subscriptions", subscriptions), + ( + f"/v1/ss3/subscriptions/{TEST_SUBSCRIPTION_ID}/settings/normal", + v3_settings_response, + ), + (f"/v1/ss3/subscriptions/{TEST_SUBSCRIPTION_ID}/sensors", sensors), + ): + authenticated_simplisafe_server.add( + "api.simplisafe.com", + path, + "get", + response=aiohttp.web_response.json_response(payload, status=200), + ) + return authenticated_simplisafe_server + + +@pytest.mark.asyncio +async def test_scout_camera( + caplog: pytest.LogCaptureFixture, scout_server: ResponsesMockServer +) -> None: + """Test that a Scout indoor camera is recognized without logging errors. + + Args: + caplog: A log capture fixture. + scout_server: A mock server whose system includes a Scout camera. + """ + caplog.set_level(logging.ERROR) + async with scout_server, aiohttp.ClientSession() as session: + simplisafe = await API.async_from_auth( + TEST_AUTHORIZATION_CODE, TEST_CODE_VERIFIER, session=session + ) + systems = await simplisafe.async_get_systems() + system: SystemV3 = cast(SystemV3, systems[TEST_SYSTEM_ID]) + + camera = system.cameras[TEST_SCOUT_CAMERA_ID] + assert camera.camera_type == CameraTypes.SCOUT_CAMERA + assert camera.name == "Scout" + assert camera.serial == TEST_SCOUT_CAMERA_ID + assert system.camera_data[TEST_SCOUT_CAMERA_ID]["serial"] == TEST_SCOUT_SERIAL + + sensor = system.sensors[TEST_SCOUT_SERIAL] + assert sensor.type == DeviceTypes.SCOUT_CAMERA + + assert not [r for r in caplog.records if "Unknown" in r.message] + + +def test_device_type_21() -> None: + """Test that raw device type 21 maps to the Scout camera device type.""" + assert ( + get_device_type_from_data({"type": 21, "serial": TEST_SCOUT_SERIAL}) + == DeviceTypes.SCOUT_CAMERA + )