diff options
author | Evgeny Zinoviev <me@ch1p.io> | 2024-02-17 13:39:01 +0300 |
---|---|---|
committer | Evgeny Zinoviev <me@ch1p.io> | 2024-02-17 13:39:01 +0300 |
commit | 77b80dd9b3500539b24b7dc6258c02c23fd4d015 (patch) | |
tree | cb9382f937feffc3f18aec894bde2aa3b27a8bc6 | |
parent | c5e69cf2c9b89d546ad7a4f6bb26aef47021dd50 (diff) |
fix ipcam_ntp_util
-rwxr-xr-x | bin/ipcam_ntp_util.py | 18 | ||||
-rw-r--r-- | include/py/homekit/camera/types.py | 2 |
2 files changed, 19 insertions, 1 deletions
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'<?xml version="1.0" encoding="UTF-8"?><NTPTestDescription><addressingFormatType>{format}</addressingFormatType><ipAddress>{ntp_host}</ipAddress><portNo>{ntp_port}</portNo></NTPTestDescription>' + 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 = '<?xml version="1.0" encoding="UTF-8"?>' data += f'<NTPServer><id>1</id><addressingFormatType>{format}</addressingFormatType><ipAddress>{ntp_host}</ipAddress><portNo>{ntp_port}</portNo><synchronizeInterval>1440</synchronizeInterval></NTPServer>' @@ -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): |