pyimouapi 1.4.0__tar.gz → 1.4.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pyimouapi-1.4.0 → pyimouapi-1.4.1}/PKG-INFO +1 -1
- {pyimouapi-1.4.0 → pyimouapi-1.4.1}/pyimouapi/__init__.py +1 -1
- {pyimouapi-1.4.0 → pyimouapi-1.4.1}/pyimouapi/const.py +1 -0
- {pyimouapi-1.4.0 → pyimouapi-1.4.1}/pyimouapi/device.py +29 -0
- {pyimouapi-1.4.0 → pyimouapi-1.4.1}/pyimouapi/ha_device.py +33 -64
- {pyimouapi-1.4.0 → pyimouapi-1.4.1}/pyimouapi.egg-info/PKG-INFO +1 -1
- {pyimouapi-1.4.0 → pyimouapi-1.4.1}/pyimouapi.egg-info/SOURCES.txt +1 -0
- {pyimouapi-1.4.0 → pyimouapi-1.4.1}/pyproject.toml +1 -1
- {pyimouapi-1.4.0 → pyimouapi-1.4.1}/setup.py +1 -1
- pyimouapi-1.4.1/tests/test_device_stream.py +123 -0
- {pyimouapi-1.4.0 → pyimouapi-1.4.1}/tests/test_event_identifier_map.py +9 -0
- {pyimouapi-1.4.0 → pyimouapi-1.4.1}/tests/test_pic_decode.py +27 -1
- {pyimouapi-1.4.0 → pyimouapi-1.4.1}/LICENSE +0 -0
- {pyimouapi-1.4.0 → pyimouapi-1.4.1}/README.md +0 -0
- {pyimouapi-1.4.0 → pyimouapi-1.4.1}/pyimouapi/alarm_mode.py +0 -0
- {pyimouapi-1.4.0 → pyimouapi-1.4.1}/pyimouapi/collection_point.py +0 -0
- {pyimouapi-1.4.0 → pyimouapi-1.4.1}/pyimouapi/exceptions.py +0 -0
- {pyimouapi-1.4.0 → pyimouapi-1.4.1}/pyimouapi/openapi.py +0 -0
- {pyimouapi-1.4.0 → pyimouapi-1.4.1}/pyimouapi/pic_decode.py +0 -0
- {pyimouapi-1.4.0 → pyimouapi-1.4.1}/pyimouapi/push.py +0 -0
- {pyimouapi-1.4.0 → pyimouapi-1.4.1}/pyimouapi/py.typed +0 -0
- {pyimouapi-1.4.0 → pyimouapi-1.4.1}/pyimouapi/select_option.py +0 -0
- {pyimouapi-1.4.0 → pyimouapi-1.4.1}/pyimouapi/sensor.py +0 -0
- {pyimouapi-1.4.0 → pyimouapi-1.4.1}/pyimouapi/siren.py +0 -0
- {pyimouapi-1.4.0 → pyimouapi-1.4.1}/pyimouapi.egg-info/dependency_links.txt +0 -0
- {pyimouapi-1.4.0 → pyimouapi-1.4.1}/pyimouapi.egg-info/not-zip-safe +0 -0
- {pyimouapi-1.4.0 → pyimouapi-1.4.1}/pyimouapi.egg-info/requires.txt +0 -0
- {pyimouapi-1.4.0 → pyimouapi-1.4.1}/pyimouapi.egg-info/top_level.txt +0 -0
- {pyimouapi-1.4.0 → pyimouapi-1.4.1}/setup.cfg +0 -0
- {pyimouapi-1.4.0 → pyimouapi-1.4.1}/tests/test_accessory_device_id.py +0 -0
- {pyimouapi-1.4.0 → pyimouapi-1.4.1}/tests/test_alarm_control_panel.py +0 -0
- {pyimouapi-1.4.0 → pyimouapi-1.4.1}/tests/test_alarm_mode.py +0 -0
- {pyimouapi-1.4.0 → pyimouapi-1.4.1}/tests/test_auth_failure_propagates.py +0 -0
- {pyimouapi-1.4.0 → pyimouapi-1.4.1}/tests/test_bind_device.py +0 -0
- {pyimouapi-1.4.0 → pyimouapi-1.4.1}/tests/test_channel_id_and_api_guards.py +0 -0
- {pyimouapi-1.4.0 → pyimouapi-1.4.1}/tests/test_collect_property_entities.py +0 -0
- {pyimouapi-1.4.0 → pyimouapi-1.4.1}/tests/test_collection_point.py +0 -0
- {pyimouapi-1.4.0 → pyimouapi-1.4.1}/tests/test_connection_pool.py +0 -0
- {pyimouapi-1.4.0 → pyimouapi-1.4.1}/tests/test_device_image.py +0 -0
- {pyimouapi-1.4.0 → pyimouapi-1.4.1}/tests/test_device_summaries.py +0 -0
- {pyimouapi-1.4.0 → pyimouapi-1.4.1}/tests/test_entity_tables_golden.py +0 -0
- {pyimouapi-1.4.0 → pyimouapi-1.4.1}/tests/test_feature_switches.py +0 -0
- {pyimouapi-1.4.0 → pyimouapi-1.4.1}/tests/test_get_devices.py +0 -0
- {pyimouapi-1.4.0 → pyimouapi-1.4.1}/tests/test_lookup_property.py +0 -0
- {pyimouapi-1.4.0 → pyimouapi-1.4.1}/tests/test_message_callback.py +0 -0
- {pyimouapi-1.4.0 → pyimouapi-1.4.1}/tests/test_motion_detect_excepts.py +0 -0
- {pyimouapi-1.4.0 → pyimouapi-1.4.1}/tests/test_openapi_http.py +0 -0
- {pyimouapi-1.4.0 → pyimouapi-1.4.1}/tests/test_packaging.py +0 -0
- {pyimouapi-1.4.0 → pyimouapi-1.4.1}/tests/test_product_id_guard.py +0 -0
- {pyimouapi-1.4.0 → pyimouapi-1.4.1}/tests/test_push.py +0 -0
- {pyimouapi-1.4.0 → pyimouapi-1.4.1}/tests/test_select_option.py +0 -0
- {pyimouapi-1.4.0 → pyimouapi-1.4.1}/tests/test_sensor_normalize.py +0 -0
- {pyimouapi-1.4.0 → pyimouapi-1.4.1}/tests/test_services_entities_concurrency.py +0 -0
- {pyimouapi-1.4.0 → pyimouapi-1.4.1}/tests/test_set_text_value.py +0 -0
- {pyimouapi-1.4.0 → pyimouapi-1.4.1}/tests/test_shared_status_reads.py +0 -0
- {pyimouapi-1.4.0 → pyimouapi-1.4.1}/tests/test_siren.py +0 -0
- {pyimouapi-1.4.0 → pyimouapi-1.4.1}/tests/test_status_read_concurrency.py +0 -0
- {pyimouapi-1.4.0 → pyimouapi-1.4.1}/tests/test_switch_status_aggregation.py +0 -0
- {pyimouapi-1.4.0 → pyimouapi-1.4.1}/tests/test_update_from_detail.py +0 -0
- {pyimouapi-1.4.0 → pyimouapi-1.4.1}/tests/test_write_optimistic_state.py +0 -0
|
@@ -16,6 +16,7 @@ API_ENDPOINT_BIND_DEVICE = "/openapi/bindDevice"
|
|
|
16
16
|
API_ENDPOINT_BIND_DEVICE_LIVE = "/openapi/bindDeviceLive"
|
|
17
17
|
API_ENDPOINT_GET_DEVICE_ONLINE = "/openapi/deviceOnline"
|
|
18
18
|
API_ENDPOINT_GET_DEVICE_LIVE_INFO = "/openapi/getLiveStreamInfo"
|
|
19
|
+
API_ENDPOINT_GET_STREAM_URL = "/openapi/getStreamUrl"
|
|
19
20
|
API_ENDPOINT_SET_DEVICE_SNAP = "/openapi/setDeviceSnapEnhanced"
|
|
20
21
|
API_ENDPOINT_GET_IOT_DEVICE_PROPERTIES = "/openapi/getIotDeviceProperties"
|
|
21
22
|
API_ENDPOINT_SET_IOT_DEVICE_PROPERTIES = "/openapi/setIotDeviceProperties"
|
|
@@ -21,6 +21,7 @@ from .const import (
|
|
|
21
21
|
API_ENDPOINT_GET_IOT_DEVICE_DETAIL_INFO,
|
|
22
22
|
API_ENDPOINT_GET_IOT_DEVICE_PROPERTIES,
|
|
23
23
|
API_ENDPOINT_GET_PRODUCT_MODEL,
|
|
24
|
+
API_ENDPOINT_GET_STREAM_URL,
|
|
24
25
|
API_ENDPOINT_IOT_DEVICE_CONTROL,
|
|
25
26
|
API_ENDPOINT_LIST_DEVICE_DETAILS,
|
|
26
27
|
API_ENDPOINT_MODIFY_DEVICE_ALARM_STATUS,
|
|
@@ -321,6 +322,12 @@ class ImouDeviceManager:
|
|
|
321
322
|
return
|
|
322
323
|
self._event_maps[product_id] = _parse_event_ref_map(data)
|
|
323
324
|
|
|
325
|
+
def cached_event_map(self, product_id: str) -> dict[str, str]:
|
|
326
|
+
"""Return the cached events ref→identifier map, or {} if not loaded."""
|
|
327
|
+
if not product_id:
|
|
328
|
+
return {}
|
|
329
|
+
return dict(self._event_maps.get(product_id) or {})
|
|
330
|
+
|
|
324
331
|
async def async_resolve_event_identifier(
|
|
325
332
|
self, product_id: str, ref: str
|
|
326
333
|
) -> str | None:
|
|
@@ -603,6 +610,28 @@ class ImouDeviceManager:
|
|
|
603
610
|
API_ENDPOINT_GET_DEVICE_LIVE_INFO, params
|
|
604
611
|
)
|
|
605
612
|
|
|
613
|
+
async def async_get_rtsp_stream_url(
|
|
614
|
+
self,
|
|
615
|
+
device_id: str,
|
|
616
|
+
channel_id: str | None,
|
|
617
|
+
stream_id: int = 0,
|
|
618
|
+
product_id: str | None = None,
|
|
619
|
+
) -> dict[str, Any]:
|
|
620
|
+
"""Obtain a short-lived cloud RTSP URL (getStreamUrl).
|
|
621
|
+
|
|
622
|
+
``productId`` is only sent for IoT devices that have one.
|
|
623
|
+
"""
|
|
624
|
+
params: dict[str, Any] = {
|
|
625
|
+
PARAM_DEVICE_ID: device_id,
|
|
626
|
+
PARAM_CHANNEL_ID: channel_id,
|
|
627
|
+
PARAM_STREAM_ID: stream_id,
|
|
628
|
+
}
|
|
629
|
+
if product_id:
|
|
630
|
+
params[PARAM_PRODUCT_ID] = product_id
|
|
631
|
+
return await self._imou_api_client.async_request_api(
|
|
632
|
+
API_ENDPOINT_GET_STREAM_URL, params
|
|
633
|
+
)
|
|
634
|
+
|
|
606
635
|
async def async_get_device_snap(
|
|
607
636
|
self, device_id: str, channel_id: str | None
|
|
608
637
|
) -> dict[str, Any]:
|
|
@@ -22,9 +22,6 @@ from .const import (
|
|
|
22
22
|
BUTTON_TYPE_ABILITY,
|
|
23
23
|
BUTTON_TYPE_PARAM_VALUE,
|
|
24
24
|
BUTTON_TYPE_REF,
|
|
25
|
-
ERROR_CODE_DEVICE_SLEEPING,
|
|
26
|
-
ERROR_CODE_LIVE_ALREADY_EXIST,
|
|
27
|
-
ERROR_CODE_LIVE_NOT_EXIST,
|
|
28
25
|
ERROR_CODE_NO_STORAGE_MEDIUM,
|
|
29
26
|
PARAM_ABILITY,
|
|
30
27
|
PARAM_ALKELEC,
|
|
@@ -42,7 +39,6 @@ from .const import (
|
|
|
42
39
|
PARAM_EXPRESSION,
|
|
43
40
|
PARAM_FUNCTION_TYPE,
|
|
44
41
|
PARAM_HD,
|
|
45
|
-
PARAM_HLS,
|
|
46
42
|
PARAM_HUMIDITY_CURRENT,
|
|
47
43
|
PARAM_INPUT_REF,
|
|
48
44
|
PARAM_LITELEC,
|
|
@@ -65,8 +61,6 @@ from .const import (
|
|
|
65
61
|
PARAM_STATE,
|
|
66
62
|
PARAM_STATUS,
|
|
67
63
|
PARAM_STORAGE_USED,
|
|
68
|
-
PARAM_STREAM_ID,
|
|
69
|
-
PARAM_STREAMS,
|
|
70
64
|
PARAM_SUPPORTED,
|
|
71
65
|
PARAM_TEMPERATURE_CURRENT,
|
|
72
66
|
PARAM_TOTAL_BYTES,
|
|
@@ -305,6 +299,7 @@ class ImouHaDevice:
|
|
|
305
299
|
self._parent_product_id: str | None = None
|
|
306
300
|
self._parent_device_id: str | None = None
|
|
307
301
|
self._device_ability = "unknown"
|
|
302
|
+
self._channel_ability = "unknown"
|
|
308
303
|
|
|
309
304
|
@property
|
|
310
305
|
def device_id(self) -> str:
|
|
@@ -382,6 +377,10 @@ class ImouHaDevice:
|
|
|
382
377
|
def device_ability(self) -> str:
|
|
383
378
|
return self._device_ability
|
|
384
379
|
|
|
380
|
+
@property
|
|
381
|
+
def channel_ability(self) -> str:
|
|
382
|
+
return self._channel_ability
|
|
383
|
+
|
|
385
384
|
@property
|
|
386
385
|
def device_name(self) -> str:
|
|
387
386
|
return self._device_name
|
|
@@ -398,6 +397,9 @@ class ImouHaDevice:
|
|
|
398
397
|
def set_device_ability(self, device_ability: str) -> None:
|
|
399
398
|
self._device_ability = device_ability
|
|
400
399
|
|
|
400
|
+
def set_channel_ability(self, channel_ability: str) -> None:
|
|
401
|
+
self._channel_ability = channel_ability
|
|
402
|
+
|
|
401
403
|
def __str__(self) -> str:
|
|
402
404
|
return (
|
|
403
405
|
f"device_id: {self._device_id}, product_id:{self._product_id},parent_device_id:{self._parent_product_id},device_name: {self._device_name}, manufacturer: {self._manufacturer}, "
|
|
@@ -955,41 +957,29 @@ class ImouHaDeviceManager:
|
|
|
955
957
|
apply_sensor_state(device.sensors, PARAM_STORAGE_USED, "e2")
|
|
956
958
|
|
|
957
959
|
async def async_get_device_stream(
|
|
958
|
-
self, device: ImouHaDevice, live_resolution: str, live_protocol: str
|
|
959
|
-
):
|
|
960
|
-
|
|
961
|
-
return await self._async_get_device_exist_stream(
|
|
962
|
-
device, live_resolution, live_protocol
|
|
963
|
-
)
|
|
964
|
-
except RequestFailedException as exception:
|
|
965
|
-
if ERROR_CODE_LIVE_NOT_EXIST in exception.message:
|
|
966
|
-
try:
|
|
967
|
-
return await self._async_create_device_stream(
|
|
968
|
-
device, live_resolution, live_protocol
|
|
969
|
-
)
|
|
970
|
-
except RequestFailedException as ex:
|
|
971
|
-
if ERROR_CODE_LIVE_ALREADY_EXIST in ex.message:
|
|
972
|
-
return await self._async_get_device_exist_stream(
|
|
973
|
-
device, live_resolution, live_protocol
|
|
974
|
-
)
|
|
975
|
-
raise ex
|
|
976
|
-
raise exception
|
|
977
|
-
|
|
978
|
-
async def _async_get_device_exist_stream(
|
|
979
|
-
self, device: ImouHaDevice, resolution: str, protocol: str
|
|
980
|
-
):
|
|
981
|
-
data = await self.delegate.async_get_stream_url(
|
|
982
|
-
device.device_id, device.channel_id
|
|
983
|
-
)
|
|
984
|
-
return await self.async_get_stream_url(data, resolution, protocol)
|
|
960
|
+
self, device: ImouHaDevice, live_resolution: str, live_protocol: str = ""
|
|
961
|
+
) -> str:
|
|
962
|
+
"""Return a fresh cloud RTSP URL from getStreamUrl.
|
|
985
963
|
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
964
|
+
``live_protocol`` is unused (kept so Home Assistant callers that
|
|
965
|
+
still pass https keep working). Shared-account viewers cannot use
|
|
966
|
+
HLS live addresses; getStreamUrl works for the owner and sharers.
|
|
967
|
+
"""
|
|
968
|
+
del live_protocol
|
|
969
|
+
stream_id = 0 if live_resolution == PARAM_HD else 1
|
|
970
|
+
data = await self.delegate.async_get_rtsp_stream_url(
|
|
971
|
+
device.device_id,
|
|
972
|
+
device.channel_id,
|
|
973
|
+
stream_id,
|
|
974
|
+
device.product_id,
|
|
991
975
|
)
|
|
992
|
-
|
|
976
|
+
url = data.get(PARAM_URL) if data else None
|
|
977
|
+
if not url:
|
|
978
|
+
raise RequestFailedException(
|
|
979
|
+
f"device {device.device_id} answered getStreamUrl without a url"
|
|
980
|
+
)
|
|
981
|
+
_LOGGER.debug("get_device_stream %s", url)
|
|
982
|
+
return url
|
|
993
983
|
|
|
994
984
|
async def async_get_device_image(
|
|
995
985
|
self, device: ImouHaDevice, wait_seconds: int
|
|
@@ -1028,6 +1018,7 @@ class ImouHaDeviceManager:
|
|
|
1028
1018
|
imou_ha_device = self.build_device(device)
|
|
1029
1019
|
imou_ha_device.set_channel_id(channel.channel_id)
|
|
1030
1020
|
imou_ha_device.set_channel_name(channel.channel_name)
|
|
1021
|
+
imou_ha_device.set_channel_ability(channel.channel_ability)
|
|
1031
1022
|
if device.product_id is not None:
|
|
1032
1023
|
_LOGGER.debug(
|
|
1033
1024
|
"channels and product_id is not none, device_id:%s,product_id:%s",
|
|
@@ -1437,19 +1428,6 @@ class ImouHaDeviceManager:
|
|
|
1437
1428
|
PARAM_FUNCTION_TYPE: ability.get(PARAM_FUNCTION_TYPE),
|
|
1438
1429
|
}
|
|
1439
1430
|
|
|
1440
|
-
@staticmethod
|
|
1441
|
-
async def async_get_stream_url(data: dict, resolution: str, protocol: str) -> str:
|
|
1442
|
-
if data.get(PARAM_STREAMS):
|
|
1443
|
-
for stream in data[PARAM_STREAMS]:
|
|
1444
|
-
if (
|
|
1445
|
-
stream[PARAM_HLS].startswith(protocol + ":")
|
|
1446
|
-
and (0 if resolution == PARAM_HD else 1) == stream[PARAM_STREAM_ID]
|
|
1447
|
-
):
|
|
1448
|
-
_LOGGER.debug("get_device_stream %s", stream[PARAM_HLS])
|
|
1449
|
-
return stream[PARAM_HLS]
|
|
1450
|
-
return data[PARAM_STREAMS][0][PARAM_HLS]
|
|
1451
|
-
return ""
|
|
1452
|
-
|
|
1453
1431
|
async def _async_configure_device_by_ref(
|
|
1454
1432
|
self,
|
|
1455
1433
|
channel_ability_refs: list[str],
|
|
@@ -1832,7 +1810,7 @@ class ImouHaDeviceManager:
|
|
|
1832
1810
|
"_async_update_device_binary_sensor_status_by_ref fail:%s", e
|
|
1833
1811
|
)
|
|
1834
1812
|
|
|
1835
|
-
async def _async_update_device_battery(self, device
|
|
1813
|
+
async def _async_update_device_battery(self, device):
|
|
1836
1814
|
try:
|
|
1837
1815
|
data = await self.delegate.async_get_device_power_info(device.device_id)
|
|
1838
1816
|
battery_level = "0"
|
|
@@ -1846,17 +1824,8 @@ class ImouHaDeviceManager:
|
|
|
1846
1824
|
battery_level = electricity[PARAM_ELECTRIC]
|
|
1847
1825
|
apply_sensor_state(device.sensors, PARAM_BATTERY, battery_level)
|
|
1848
1826
|
except RequestFailedException as exception:
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
try:
|
|
1852
|
-
await self.delegate.async_wake_up_device(device.device_id)
|
|
1853
|
-
await self._async_update_device_battery(device, True)
|
|
1854
|
-
except RequestFailedException as e:
|
|
1855
|
-
_LOGGER.error("_async_update_device_battery error: %s", e)
|
|
1856
|
-
apply_sensor_state(device.sensors, PARAM_BATTERY, "0")
|
|
1857
|
-
else:
|
|
1858
|
-
_LOGGER.error("_async_update_device_battery error: %s", exception)
|
|
1859
|
-
apply_sensor_state(device.sensors, PARAM_BATTERY, "0")
|
|
1827
|
+
_LOGGER.error("_async_update_device_battery error: %s", exception)
|
|
1828
|
+
apply_sensor_state(device.sensors, PARAM_BATTERY, "0")
|
|
1860
1829
|
|
|
1861
1830
|
@staticmethod
|
|
1862
1831
|
def configure_text_by_ref(
|
|
@@ -32,6 +32,7 @@ tests/test_collect_property_entities.py
|
|
|
32
32
|
tests/test_collection_point.py
|
|
33
33
|
tests/test_connection_pool.py
|
|
34
34
|
tests/test_device_image.py
|
|
35
|
+
tests/test_device_stream.py
|
|
35
36
|
tests/test_device_summaries.py
|
|
36
37
|
tests/test_entity_tables_golden.py
|
|
37
38
|
tests/test_event_identifier_map.py
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
"""Tests for getStreamUrl live addresses."""
|
|
2
|
+
|
|
3
|
+
from unittest.mock import AsyncMock, MagicMock
|
|
4
|
+
|
|
5
|
+
import pytest
|
|
6
|
+
from pyimouapi.const import (
|
|
7
|
+
PARAM_CHANNEL_ID,
|
|
8
|
+
PARAM_DEVICE_ID,
|
|
9
|
+
PARAM_HD,
|
|
10
|
+
PARAM_PRODUCT_ID,
|
|
11
|
+
PARAM_STREAM_ID,
|
|
12
|
+
PARAM_URL,
|
|
13
|
+
)
|
|
14
|
+
from pyimouapi.device import ImouDeviceManager
|
|
15
|
+
from pyimouapi.exceptions import RequestFailedException
|
|
16
|
+
from pyimouapi.ha_device import ImouHaDevice, ImouHaDeviceManager
|
|
17
|
+
|
|
18
|
+
RTSP_URL = "rtsp://rtspproxy.example.com:8554/clip"
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def camera(*, product_id: str | None = None) -> ImouHaDevice:
|
|
22
|
+
"""Return a camera channel, optionally as an IoT device."""
|
|
23
|
+
ha_device = ImouHaDevice("dev1", "Cam", "Imou", "IPC", "1.0")
|
|
24
|
+
ha_device.set_channel_id("0")
|
|
25
|
+
if product_id is not None:
|
|
26
|
+
ha_device.set_product_id(product_id)
|
|
27
|
+
return ha_device
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
@pytest.mark.asyncio
|
|
31
|
+
async def test_rtsp_request_omits_product_id_for_paas_devices() -> None:
|
|
32
|
+
"""productId is only for IoT; a PaaS camera must not send it."""
|
|
33
|
+
client = MagicMock()
|
|
34
|
+
client.async_request_api = AsyncMock(return_value={PARAM_URL: RTSP_URL})
|
|
35
|
+
manager = ImouDeviceManager(client)
|
|
36
|
+
|
|
37
|
+
await manager.async_get_rtsp_stream_url("dev1", "0", 0)
|
|
38
|
+
|
|
39
|
+
client.async_request_api.assert_awaited_once_with(
|
|
40
|
+
"/openapi/getStreamUrl",
|
|
41
|
+
{
|
|
42
|
+
PARAM_DEVICE_ID: "dev1",
|
|
43
|
+
PARAM_CHANNEL_ID: "0",
|
|
44
|
+
PARAM_STREAM_ID: 0,
|
|
45
|
+
},
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
@pytest.mark.asyncio
|
|
50
|
+
async def test_rtsp_request_sends_product_id_for_iot_devices() -> None:
|
|
51
|
+
"""IoT cameras pass the product they were listed with."""
|
|
52
|
+
client = MagicMock()
|
|
53
|
+
client.async_request_api = AsyncMock(return_value={PARAM_URL: RTSP_URL})
|
|
54
|
+
manager = ImouDeviceManager(client)
|
|
55
|
+
|
|
56
|
+
await manager.async_get_rtsp_stream_url("dev1", "0", 1, "BF5W2WL4")
|
|
57
|
+
|
|
58
|
+
client.async_request_api.assert_awaited_once_with(
|
|
59
|
+
"/openapi/getStreamUrl",
|
|
60
|
+
{
|
|
61
|
+
PARAM_DEVICE_ID: "dev1",
|
|
62
|
+
PARAM_CHANNEL_ID: "0",
|
|
63
|
+
PARAM_STREAM_ID: 1,
|
|
64
|
+
PARAM_PRODUCT_ID: "BF5W2WL4",
|
|
65
|
+
},
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
@pytest.mark.asyncio
|
|
70
|
+
async def test_live_stream_uses_get_stream_url_only() -> None:
|
|
71
|
+
"""Live view fetches getStreamUrl; it does not look up or create HLS."""
|
|
72
|
+
delegate = MagicMock()
|
|
73
|
+
delegate.async_get_stream_url = AsyncMock()
|
|
74
|
+
delegate.async_create_stream_url = AsyncMock()
|
|
75
|
+
delegate.async_get_rtsp_stream_url = AsyncMock(return_value={PARAM_URL: RTSP_URL})
|
|
76
|
+
manager = ImouHaDeviceManager(delegate)
|
|
77
|
+
|
|
78
|
+
assert (
|
|
79
|
+
await manager.async_get_device_stream(camera(), PARAM_HD, "https") == RTSP_URL
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
delegate.async_get_stream_url.assert_not_awaited()
|
|
83
|
+
delegate.async_create_stream_url.assert_not_awaited()
|
|
84
|
+
delegate.async_get_rtsp_stream_url.assert_awaited_once_with("dev1", "0", 0, None)
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
@pytest.mark.asyncio
|
|
88
|
+
async def test_live_stream_passes_product_id_for_iot() -> None:
|
|
89
|
+
"""The request must include productId when the device has one."""
|
|
90
|
+
delegate = MagicMock()
|
|
91
|
+
delegate.async_get_rtsp_stream_url = AsyncMock(return_value={PARAM_URL: RTSP_URL})
|
|
92
|
+
manager = ImouHaDeviceManager(delegate)
|
|
93
|
+
|
|
94
|
+
await manager.async_get_device_stream(
|
|
95
|
+
camera(product_id="BF5W2WL4"), PARAM_HD, "https"
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
delegate.async_get_rtsp_stream_url.assert_awaited_once_with(
|
|
99
|
+
"dev1", "0", 0, "BF5W2WL4"
|
|
100
|
+
)
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
@pytest.mark.asyncio
|
|
104
|
+
async def test_live_stream_uses_substream_for_sd() -> None:
|
|
105
|
+
"""SD live resolution maps to streamId 1."""
|
|
106
|
+
delegate = MagicMock()
|
|
107
|
+
delegate.async_get_rtsp_stream_url = AsyncMock(return_value={PARAM_URL: RTSP_URL})
|
|
108
|
+
manager = ImouHaDeviceManager(delegate)
|
|
109
|
+
|
|
110
|
+
await manager.async_get_device_stream(camera(), "SD", "https")
|
|
111
|
+
|
|
112
|
+
delegate.async_get_rtsp_stream_url.assert_awaited_once_with("dev1", "0", 1, None)
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
@pytest.mark.asyncio
|
|
116
|
+
async def test_live_stream_without_url_reaches_the_caller() -> None:
|
|
117
|
+
"""An answer with no url must not look like a working stream."""
|
|
118
|
+
delegate = MagicMock()
|
|
119
|
+
delegate.async_get_rtsp_stream_url = AsyncMock(return_value={})
|
|
120
|
+
manager = ImouHaDeviceManager(delegate)
|
|
121
|
+
|
|
122
|
+
with pytest.raises(RequestFailedException, match="without a url"):
|
|
123
|
+
await manager.async_get_device_stream(camera(), PARAM_HD, "https")
|
|
@@ -48,10 +48,18 @@ async def test_ensure_event_map_fetches_once_and_caches():
|
|
|
48
48
|
API_ENDPOINT_GET_PRODUCT_MODEL,
|
|
49
49
|
{PARAM_PRODUCT_ID: "pidA"},
|
|
50
50
|
)
|
|
51
|
+
assert manager.cached_event_map("pidA") == {"33000": "doorOpen"}
|
|
51
52
|
assert await manager.async_resolve_event_identifier("pidA", "33000") == "doorOpen"
|
|
52
53
|
assert await manager.async_resolve_event_identifier("pidA", "missing") is None
|
|
53
54
|
|
|
54
55
|
|
|
56
|
+
def test_cached_event_map_empty_until_fetched() -> None:
|
|
57
|
+
"""Setup-time entity gating must not invent events that were never loaded."""
|
|
58
|
+
manager = ImouDeviceManager(MagicMock())
|
|
59
|
+
assert manager.cached_event_map("pidA") == {}
|
|
60
|
+
assert manager.cached_event_map("") == {}
|
|
61
|
+
|
|
62
|
+
|
|
55
63
|
@pytest.mark.asyncio
|
|
56
64
|
async def test_ensure_event_map_failure_does_not_poison_cache():
|
|
57
65
|
client = MagicMock()
|
|
@@ -64,6 +72,7 @@ async def test_ensure_event_map_failure_does_not_poison_cache():
|
|
|
64
72
|
manager = ImouDeviceManager(client)
|
|
65
73
|
|
|
66
74
|
await manager.async_ensure_event_map("pidB")
|
|
75
|
+
assert manager.cached_event_map("pidB") == {}
|
|
67
76
|
assert await manager.async_resolve_event_identifier("pidB", "1") == "ok"
|
|
68
77
|
assert client.async_request_api.await_count == 2
|
|
69
78
|
|
|
@@ -3,8 +3,9 @@
|
|
|
3
3
|
import ctypes
|
|
4
4
|
import hashlib
|
|
5
5
|
from pathlib import Path
|
|
6
|
-
from unittest.mock import MagicMock
|
|
6
|
+
from unittest.mock import AsyncMock, MagicMock
|
|
7
7
|
|
|
8
|
+
import pytest
|
|
8
9
|
from pyimouapi.ha_device import ImouHaDeviceManager
|
|
9
10
|
from pyimouapi.pic_decode import (
|
|
10
11
|
LCOpenPicDecoder,
|
|
@@ -29,6 +30,31 @@ def test_build_device_copies_device_ability() -> None:
|
|
|
29
30
|
src.device_ability = "WLAN,TCM"
|
|
30
31
|
ha = ImouHaDeviceManager.build_device(src)
|
|
31
32
|
assert ha.device_ability == "WLAN,TCM"
|
|
33
|
+
assert ha.channel_ability == "unknown"
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
@pytest.mark.asyncio
|
|
37
|
+
async def test_ha_get_devices_copies_channel_ability() -> None:
|
|
38
|
+
"""PaaS channel abilities (CallAbility, MobileDetect, …) must reach HA devices."""
|
|
39
|
+
from pyimouapi.device import ImouChannel
|
|
40
|
+
|
|
41
|
+
src = MagicMock()
|
|
42
|
+
src.device_id = "SN1"
|
|
43
|
+
src.device_name = "Cam"
|
|
44
|
+
src.brand = "Imou"
|
|
45
|
+
src.device_model = "IPC"
|
|
46
|
+
src.device_version = "1"
|
|
47
|
+
src.product_id = None
|
|
48
|
+
src.parent_product_id = None
|
|
49
|
+
src.parent_device_id = None
|
|
50
|
+
src.is_ipc = True
|
|
51
|
+
src.device_ability = "WLAN"
|
|
52
|
+
src.channels = [ImouChannel("0", "Front", "1", "WLAN,CallAbility,MobileDetect")]
|
|
53
|
+
delegate = MagicMock()
|
|
54
|
+
delegate.async_get_devices = AsyncMock(return_value=[src])
|
|
55
|
+
devices = await ImouHaDeviceManager(delegate).async_get_devices()
|
|
56
|
+
assert devices[0].channel_ability == "WLAN,CallAbility,MobileDetect"
|
|
57
|
+
assert devices[0].channel_id == "0"
|
|
32
58
|
|
|
33
59
|
|
|
34
60
|
def test_is_tcm_ability_token() -> None:
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|