Failed to read data (AccessControl Event)
On some occasion the received response byte array contains errors:
response = b' \x00\x00\x00DHIP\xf4\xb1\xc9*\x08\x00\x00\x00{\x01\x00\x00\x00\x00\x00\x00{\x01\x00\x00\x00\x00\x00\x00{"id":8,"method":parse_response(response)"client.notifyEventStream","params":{"SID":513,"eventList":[{"Action":"Pulse","Code":"AccessControl"
parse_response(response)
can not handle this:
def parse_response(response):
result = None
try:
response_parts = str(response).split("\\x00")
for response_part in response_parts:
if response_part.startswith("{"):
end = response_part.rindex("}") + 1
message = response_part[0:end]
result = json.loads(message)
except Exception as e:
exc_type, exc_obj, exc_tb = sys.exc_info()
_LOGGER.error(f"Failed to read data: {response}, error: {e}, Line: {exc_tb.tb_lineno}")
return result
error 1: \x00{\ -> end = response_part.rindex("}") + 1 trows an exception -> I would replace it with rfind and only proceed if not 0. error 2: parse_response(response) -> somehow this gets in the answer string -> I added message = message.replace("parse_response(response)","") to quick fix this issue. Do you have any clue where this is coming from?
my parse_response function is now looking like this:
def parse_response(response):
result = None
try:
x=0
response_parts = str(response).split("\\x00")
for response_part in response_parts:
x=x+1
if response_part.startswith("{"):
end = response_part.rfind("}") + 1
if end!=0:
message = response_part[0:end]
message = message.replace("parse_response(response)","")
result = json.loads(message)
except Exception as e:
exc_type, exc_obj, exc_tb = sys.exc_info()
_LOGGER.error(f"Failed to read data: {response}, error: {e}, Line: {exc_tb.tb_lineno}")
return result