-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added support for new ISAPI urls #49
base: master
Are you sure you want to change the base?
Conversation
get_device_status get_device_time get_get_upnp_ports_status
I have tested these changes with two Hikvision DVRs I have with, cameras of Hikvision, CP Plus, Dahua., |
I'm on board with the new endpoints, but things need streamlined a bit. The current intent of the library is that initialize is always called first which should define some of the items you are repeating in each function (digest check in particular). I also don't see the need to add the beautiful soup dependency when everything can be done with the existing XML tree functions. |
@mezz64 Okay we can streamline the library. I used beautiful soup because of its flexibility and ease of use. |
I have removed the BeautifulSoup dependency from the new added URLs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did a more thorough review to help let you know what changes need made to bring these additions in-line with the rest of the code base.
pyhik/hikvision.py
Outdated
@@ -242,6 +242,7 @@ def initialize(self): | |||
device_info = self.get_device_info() | |||
|
|||
if device_info is None: | |||
print('Hello this is it') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed this unwanted print statement.
pyhik/hikvision.py
Outdated
@@ -401,6 +402,7 @@ def get_device_info(self): | |||
except (requests.exceptions.RequestException, | |||
requests.exceptions.ConnectionError) as err: | |||
_LOGGING.error('Unable to fetch deviceInfo, error: %s', err) | |||
print('This is test') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed this unwanted print statement
pyhik/hikvision.py
Outdated
@@ -430,6 +432,182 @@ def get_device_info(self): | |||
_LOGGING.error('There was a problem: %s', err) | |||
return None | |||
|
|||
""" | |||
This function is added by Ayush Pratap Singh (ayushs56@gmail.com) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Attribution comments aren't needed. You'll be the owner on the merged PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed attribution comment
"""Parse deviceInfo into dictionary.""" | ||
device_status = {} | ||
url = '%s/ISAPI/System/status' % self.root_url | ||
using_digest = False |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resetting the digest flag isn't needed. It will be set once the initialize function is called.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed resetting of digest flag
|
||
try: | ||
response = self.hik_request.get(url, timeout=CONNECT_TIMEOUT) | ||
if response.status_code == requests.codes.unauthorized: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use the using_digest
variable to determine what auth type to use.
# Seems to be difference between camera and nvr, they can't seem to | ||
# agree if they should 404 or 401 first | ||
if not using_digest and response.status_code == requests.codes.unauthorized: | ||
_LOGGING.debug('Basic authentication failed. Using digest.') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, use the variable to decide.
try: | ||
tree = ET.fromstring(response.text) | ||
|
||
device_status['currentdevicetime'] = tree[0].text.strip() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use the element_query
function to find the fields you want. This allows the XML ordering to change and you can still return the correct result.
_LOGGING.error('There was a problem: %s', err) | ||
return None | ||
|
||
def get_device_time(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implement same changes on this function as the previous one.
Get the Ports using the endpoint : /ISAPI/System/Network/UPnP/ports/status | ||
""" | ||
#TODO : This needs to be implemented | ||
def get_upnp_ports_status(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implement same changes on this function as the previous one.
get_device_status
get_device_time
get_get_upnp_ports_status