Skip to content

Commit 2185178

Browse files
authored
Merge pull request #1265 from custom-components/unicode_decode_error_fix
fix for unicode decode errors
2 parents b3cc863 + c6c2490 commit 2185178

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

custom_components/ble_monitor/ble_parser/__init__.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,16 @@ def parse_raw_data(self, data):
136136
service_class_uuid128 = adstruct[2:]
137137
elif adstuct_type == 0x08:
138138
# AD type 'shortened local name'
139-
shortened_local_name = adstruct[2:].decode("utf-8")
139+
try:
140+
shortened_local_name = adstruct[2:].decode("utf-8")
141+
except UnicodeDecodeError:
142+
shortened_local_name = ""
140143
elif adstuct_type == 0x09:
141144
# AD type 'complete local name'
142-
complete_local_name = adstruct[2:].decode("utf-8")
145+
try:
146+
complete_local_name = adstruct[2:].decode("utf-8")
147+
except UnicodeDecodeError:
148+
complete_local_name = ""
143149
elif adstuct_type == 0x16 and adstuct_size > 4:
144150
# AD type 'Service Data - 16-bit UUID'
145151
service_data_list.append(adstruct)

0 commit comments

Comments
 (0)