Skip to content

Commit

Permalink
Configure 0 outputs if none found
Browse files Browse the repository at this point in the history
  • Loading branch information
pergolafabio committed Oct 1, 2023
1 parent 80de2d8 commit 1a62256
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
26 changes: 14 additions & 12 deletions hikvision-doorbell/src/doorbell.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,16 +205,14 @@ def isapi_door_capabilities() -> int:
try:
root = ET.fromstring(io_doors_xml)
door_number_element = root.find('{*}channelNo')
if door_number_element is None or door_number_element.text is None:
# Print a string representation of the response XML
logger.debug("No door relays found for the indoor device")
logger.debug("We have found {} door relays for the indoor device", door_number_element.text)
return int(door_number_element.text)
except ET.ParseError:
logger.debug("Error parsing: {}", io_doors_xml)
return 0
# Error out if we don't find attribute `max` inside the `doorNo` element
if door_number_element is None or door_number_element.text is None:
# Print a string representation of the response XML
logger.debug("No door relays found for the indoor device")
return 0
logger.debug("We have found {} door relays for the indoor device", door_number_element.text)
return int(door_number_element.text)
raise RuntimeError("Error parsing: {}", io_doors_xml)

# Define the list of available endpoints to try
available_endpoints: list[Callable] = [user_config, isapi_door_capabilities]
Expand All @@ -226,8 +224,10 @@ def isapi_door_capabilities() -> int:
# This endpoint failed, try the next one
pass

# We have run out of available endpoints to call
raise RuntimeError("Unable to get the number of doors, please configure the relays manually with this option in the config: output_relays")
# We have run out of available endpoints to call, dont ro a runtime error, just continue with 0 outputs
logger.info("Unable to get the number of doors, please configure the relays manually with this option in the config: output_relays")
return 0
#raise RuntimeError("Unable to get the number of doors, please configure the relays manually with this option in the config: output_relays")

def get_num_outputs(self) -> int:
"""
Expand Down Expand Up @@ -312,8 +312,10 @@ def isapi_device_info() -> int:
except RuntimeError:
# This endpoint failed, try the next one
pass
# We have run out of available endpoints to call
raise RuntimeError("Unable to get the number of doors, please configure the relays manually with this option in the config: output_relays")
# We have run out of available endpoints to call, dont ro a runtime error, just continue with 0 outputs
logger.info("Unable to get the number of doors, please configure the relays manually with this option in the config: output_relays")
return 0
#raise RuntimeError("Unable to get the number of doors, please configure the relays manually with this option in the config: output_relays")

def get_num_coms_indoor(self) -> int:
"""
Expand Down
2 changes: 1 addition & 1 deletion hikvision-doorbell/src/sdk/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def call_ISAPI(sdk: CDLL, user_id: int, http_method: str, url: str, requestBody:
# e.g.: `GET /ISAPI/System/IO/outputs`
inUrl = f"{http_method} {url}"

logger.debug("Request body: {}", requestBody)
logger.debug("Call ISAPI request method url body: {} {} {} ", http_method, url, requestBody)

# Input information
inputStruct = NET_DVR_XML_CONFIG_INPUT()
Expand Down

0 comments on commit 1a62256

Please sign in to comment.