Skip to content

Commit

Permalink
Guard against null messages
Browse files Browse the repository at this point in the history
  • Loading branch information
rroller committed Jun 9, 2024
1 parent b90aa2c commit 07deed0
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions custom_components/dahua/vto.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ def data_received(self, data):
try:
messages = self.parse_response(packet)
for message in messages:
if message is None:
continue

message_id = message.get("id")

handler: Callable = self.data_handlers.get(message_id, self.handle_default)
Expand All @@ -115,6 +118,8 @@ def data_received(self, data):

def handle_notify_event_stream(self, params):
try:
if params is None:
return
event_list = params.get("eventList")

for message in event_list:
Expand Down Expand Up @@ -183,6 +188,8 @@ def pre_login(self):
_LOGGER.debug("Prepare pre-login message")

def handle_pre_login(message):
if message is None:
return
error = message.get("error")
params = message.get("params")

Expand Down Expand Up @@ -210,6 +217,8 @@ def login(self):
_LOGGER.debug("Prepare login message")

def handle_login(message):
if message is None:
return
params = message.get("params")
keep_alive_interval = params.get("keepAliveInterval")

Expand Down Expand Up @@ -241,6 +250,8 @@ def attach_event_manager(self):
_LOGGER.info("Attach event manager")

def handle_attach_event_manager(message):
if message is None:
return
method = message.get("method")
params = message.get("params")

Expand All @@ -257,6 +268,9 @@ def load_access_control(self):
_LOGGER.info("Get access control configuration")

def handle_access_control(message):
if message is None:
return

params = message.get("params")
table = params.get("table")

Expand Down Expand Up @@ -288,6 +302,9 @@ def load_version(self):
_LOGGER.info("Get version")

def handle_version(message):
if message is None:
return

params = message.get("params")
version_details = params.get("version", {})
build_date = version_details.get("BuildDate")
Expand All @@ -304,6 +321,9 @@ def load_device_type(self):
_LOGGER.info("Get device type")

def handle_device_type(message):
if message is None:
return

params = message.get("params")
device_type = params.get("type")

Expand All @@ -317,6 +337,9 @@ def load_serial_number(self):
_LOGGER.info("Get serial number")

def handle_serial_number(message):
if message is None:
return

params = message.get("params")
table = params.get("table", {})
serial_number = table.get("UUID")
Expand All @@ -336,6 +359,8 @@ def keep_alive(self):

def handle_keep_alive(message):
Timer(self.keep_alive_interval, self.keep_alive).start()
if message is None:
return

message_id = message.get('id')
if message_id is not None and message_id in self.data_handlers:
Expand Down

0 comments on commit 07deed0

Please sign in to comment.