fix ipcam_ntp_util
This commit is contained in:
parent
c5e69cf2c9
commit
77b80dd9b3
@ -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:
|
||||
|
@ -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):
|
||||
|
Loading…
x
Reference in New Issue
Block a user