From 77b80dd9b3500539b24b7dc6258c02c23fd4d015 Mon Sep 17 00:00:00 2001 From: Evgeny Zinoviev Date: Sat, 17 Feb 2024 13:39:01 +0300 Subject: fix ipcam_ntp_util --- bin/ipcam_ntp_util.py | 18 ++++++++++++++++++ include/py/homekit/camera/types.py | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/bin/ipcam_ntp_util.py b/bin/ipcam_ntp_util.py index 0268a06..b27995c 100755 --- a/bin/ipcam_ntp_util.py +++ b/bin/ipcam_ntp_util.py @@ -151,6 +151,23 @@ class HikvisionISAPIClient: ntp_port: int = 123): format = 'ipaddress' if validate_ipv4(ntp_host) else 'hostname' + # test ntp server first + data = f'{format}{ntp_host}{ntp_port}' + r = requests.post(self.isapi_uri('System/time/ntpServers/test'), data=data, headers={ + 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8', + 'X-Requested-With': 'XMLHttpRequest', + }, cookies=self.cookies) + r.raise_for_status() + + resp = xml_to_dict(r.text)['NTPTestResult'] + + error_code = int(resp['errorCode'][0]) + error_description = resp['errorDescription'][0] + + if error_code != 0 or error_description.lower() != 'ok': + raise ResponseError('response status looks bad') + + # then set it data = '' data += f'1{format}{ntp_host}{ntp_port}1440' @@ -194,6 +211,7 @@ def process_hikvision_camera(host: str, print(f'[{host}] {client.get_ntp_server()}') return client.set_ntp_server(ntp_server) + print(f'[{host}] done') except AuthError as e: print(f'[{host}] ({str(e)})') except ResponseError as e: diff --git a/include/py/homekit/camera/types.py b/include/py/homekit/camera/types.py index 1a97e63..ec4663b 100644 --- a/include/py/homekit/camera/types.py +++ b/include/py/homekit/camera/types.py @@ -42,7 +42,7 @@ class CameraType(Enum): return VideoContainerType.MP4 if self.get_codec(1) == VideoCodecType.H264 else VideoContainerType.MOV def is_hikvision(self) -> bool: - return self in (CameraType.HIKVISION_264.value, CameraType.HIKVISION_265) + return self in (CameraType.HIKVISION_264, CameraType.HIKVISION_265) class TimeFilterType(Enum): -- cgit v1.2.3