Skip to content

Commit

Permalink
improve handling message
Browse files Browse the repository at this point in the history
  • Loading branch information
hishizuka committed Nov 27, 2023
1 parent 249031d commit 7579af8
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions modules/helper/ble_gatt_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ def on_off_gadgetbridge_gps(self):
def decode_b64(match_object):
return f'"{base64.b64decode(match_object.group(1)).decode()}"'

def decode_message(self, message: str):
message = message.lstrip(chr(F_BYTE_MARKER)).rstrip(chr(L_BYTE_MARKER))
def decode_message(self, raw_message: str):
message = raw_message.lstrip(chr(F_BYTE_MARKER)).rstrip(chr(L_BYTE_MARKER))

if message.startswith("setTime"):
res = re.match(r"^setTime\((\d+)\);E.setTimeZone\((\S+)\);", message)
Expand Down Expand Up @@ -162,7 +162,6 @@ def decode_message(self, message: str):
self.gui.show_message(
message["title"], message["body"], limit_length=True
)
app_logger.info(message)
elif m_type.startswith("find") and message.get("n", False):
self.gui.show_dialog_ok_only(fn=None, title="Gadgetbridge")
elif m_type == "gps":
Expand Down Expand Up @@ -230,8 +229,8 @@ def decode_message(self, message: str):
# self.gui.show_forced_message(msg)

except json.JSONDecodeError:
app_logger.exception(f"Failed to load message as json {message}")
app_logger.exception(f"Failed to load message as json {raw_message}")
except Exception: # noqa
app_logger.exception(f"Failure during message {message} handling")
app_logger.exception(f"Failure during message {raw_message} handling")
else:
app_logger.warning(f"{message} unknown message received")
app_logger.warning(f"{raw_message} unknown message received")

0 comments on commit 7579af8

Please sign in to comment.