Skip to content

Commit

Permalink
workaround for proxy cameras with repeated serial no (#270)
Browse files Browse the repository at this point in the history
  • Loading branch information
maciej-or authored Dec 4, 2024
1 parent 287fca0 commit c5f6cb8
Show file tree
Hide file tree
Showing 4 changed files with 1,639 additions and 33 deletions.
15 changes: 10 additions & 5 deletions custom_components/hikvision_next/isapi/isapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,10 @@ async def get_cameras(self):
if not source:
continue

# Generate serial number if not provided by camera
# As combination of protocol and IP
serial_no = source.get("serialNumber")

if not serial_no:
serial_no = str(source.get("proxyProtocol")) + str(source.get("ipAddress", "")).replace(".", "")
if not serial_no or self.get_camera_by_serial_no(serial_no):
# serial no is not always recognized correcly by NVR
serial_no = f"{self.device_info.serial_no}_{source.get("proxyProtocol")}_{camera_id}"

self.cameras.append(
IPCamera(
Expand Down Expand Up @@ -367,6 +365,13 @@ def get_camera_by_id(self, camera_id: int) -> IPCamera | AnalogCamera | None:
# Camera id does not exist
return None

def get_camera_by_serial_no(self, serial_no: str) -> IPCamera | AnalogCamera | None:
"""Get camera object by serial number."""
for c in self.cameras:
if c.serial_no == serial_no:
return c
return None

async def get_storage_devices(self):
"""Get HDD and NAS storage devices."""
storage_list = []
Expand Down
4 changes: 2 additions & 2 deletions tests/fixtures/devices/DS-7608NXI-I2.json
Original file line number Diff line number Diff line change
Expand Up @@ -1198,7 +1198,7 @@
"connMode": "plugplay",
"streamType": "auto",
"model": "DS-2CD2386G2-IU",
"serialNumber": "DS-2CD2386G2-IU00000000AAWRK00000000",
"serialNumber": "DS-2CD2386G2-IU00000000AAWRK00000001",
"firmwareVersion": "V5.7.15 build 240201",
"deviceID": null
},
Expand All @@ -1221,7 +1221,7 @@
"connMode": "plugplay",
"streamType": "auto",
"model": "DS-2CD2386G2-IU",
"serialNumber": "DS-2CD2386G2-IU00000000AAWRK00000000",
"serialNumber": "DS-2CD2386G2-IU00000000AAWRK00000002",
"firmwareVersion": "V5.7.15 build 240201",
"deviceID": null
},
Expand Down
Loading

0 comments on commit c5f6cb8

Please sign in to comment.