Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use pythonic way in Chip Bluez Manager and Utility #9613

Merged
merged 1 commit into from
Sep 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/controller/python/chip/ChipBluezMgr.py
Original file line number Diff line number Diff line change
Expand Up @@ -844,9 +844,9 @@ def ble_adapter_print(self):
self.bluez, self.bus, ADAPTER_INTERFACE, "/org/bluez"
)
]
for i in range(len(adapters)):
for adapter in adapters:
self.logger.info("AdapterName: %s AdapterAddress: %s" % (
adapters[i].path.replace("/org/bluez/", ""), adapters[i].Address))
adapter.path.replace("/org/bluez/", ""), adapter.Address))
except dbus.exceptions.DBusException as ex:
self.logger.debug(str(ex))

Expand Down
10 changes: 4 additions & 6 deletions src/controller/python/chip/ChipUtility.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,20 @@ def VoidPtrToByteArray(ptr, len):
v = bytearray(len)
memmove((c_byte * len).from_buffer(v), ptr, len)
return v
else:
return None
return None

@staticmethod
def ByteArrayToVoidPtr(array):
if array != None:
if not (isinstance(array, bytes) or isinstance(array, bytearray)):
raise TypeError("Array must be an str or a bytearray")
return cast((c_byte * len(array)).from_buffer_copy(array), c_void_p)
else:
return c_void_p(0)
return c_void_p(0)

@staticmethod
def IsByteArrayAllZeros(array):
for i in range(len(array)):
if array[i] != 0:
for i in array:
andy31415 marked this conversation as resolved.
Show resolved Hide resolved
if i != 0:
return False
return True

Expand Down