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

[python] Move string encoding to ChipDeviceCtrl.py #20306

Merged
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
8 changes: 3 additions & 5 deletions src/controller/python/chip-device-ctrl.py
Original file line number Diff line number Diff line change
Expand Up @@ -552,8 +552,7 @@ def do_paseonly(self, line):
print("Device is assigned with nodeid = {}".format(nodeid))

if args[0] == "-ip" and len(args) >= 3:
self.devCtrl.EstablishPASESessionIP(args[1].encode(
"utf-8"), int(args[2]), nodeid)
self.devCtrl.EstablishPASESessionIP(args[1], int(args[2]), nodeid)
else:
print("Usage:")
self.do_help("paseonly")
Expand Down Expand Up @@ -614,8 +613,7 @@ def do_connect(self, line):
print("Device is assigned with nodeid = {}".format(nodeid))

if args[0] == "-ip" and len(args) >= 3:
self.devCtrl.CommissionIP(args[1].encode(
"utf-8"), int(args[2]), nodeid)
self.devCtrl.CommissionIP(args[1], int(args[2]), nodeid)
elif args[0] == "-ble" and len(args) >= 3:
self.devCtrl.ConnectBLE(int(args[1]), int(args[2]), nodeid)
elif args[0] in ['-qr', '-code'] and len(args) >= 2:
Expand Down Expand Up @@ -948,7 +946,7 @@ def do_setpairingwificredential(self, line):
self.do_help("set-pairing-wifi-credential")
return
self.devCtrl.SetWiFiCredentials(
args[0].encode("utf-8"), args[1].encode("utf-8"))
args[0], args[1])
except Exception as ex:
print(str(ex))
return
Expand Down
14 changes: 7 additions & 7 deletions src/controller/python/chip/ChipDeviceCtrl.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,13 +278,13 @@ def CloseSession(self, nodeid):
self.devCtrl, nodeid)
)

def EstablishPASESessionIP(self, ipaddr, setupPinCode, nodeid):
def EstablishPASESessionIP(self, ipaddr: str, setupPinCode: int, nodeid: int):
self.CheckIsActive()

self.state = DCState.RENDEZVOUS_ONGOING
return self._ChipStack.CallAsync(
lambda: self._dmLib.pychip_DeviceController_EstablishPASESessionIP(
self.devCtrl, ipaddr, setupPinCode, nodeid)
self.devCtrl, ipaddr.encode("utf-8"), setupPinCode, nodeid)
)

def Commission(self, nodeid):
Expand Down Expand Up @@ -345,7 +345,7 @@ def CommissionWithCode(self, setupPayload: str, nodeid: int):
return False
return self._ChipStack.commissioningEventRes == 0

def CommissionIP(self, ipaddr, setupPinCode, nodeid):
def CommissionIP(self, ipaddr: str, setupPinCode: int, nodeid: int):
self.CheckIsActive()

# IP connection will run through full commissioning, so we need to wait
Expand All @@ -356,7 +356,7 @@ def CommissionIP(self, ipaddr, setupPinCode, nodeid):

self._ChipStack.CallAsync(
lambda: self._dmLib.pychip_DeviceController_ConnectIP(
self.devCtrl, ipaddr, setupPinCode, nodeid)
self.devCtrl, ipaddr.encode("utf-8"), setupPinCode, nodeid)
)
if not self._ChipStack.commissioningCompleteEvent.isSet():
# Error 50 is a timeout
Expand All @@ -374,18 +374,18 @@ def CommissionThread(self, discriminator, setupPinCode, nodeId, threadOperationa
self.SetThreadOperationalDataset(threadOperationalDataset)
return self.ConnectBLE(discriminator, setupPinCode, nodeId)

def CommissionWiFi(self, discriminator, setupPinCode, nodeId, ssid, credentials):
def CommissionWiFi(self, discriminator, setupPinCode, nodeId, ssid: str, credentials: str):
''' Commissions a WiFi device over BLE
'''
self.SetWiFiCredentials(ssid, credentials)
return self.ConnectBLE(discriminator, setupPinCode, nodeId)

def SetWiFiCredentials(self, ssid, credentials):
def SetWiFiCredentials(self, ssid: str, credentials: str):
self.CheckIsActive()

return self._ChipStack.Call(
lambda: self._dmLib.pychip_DeviceController_SetWiFiCredentials(
ssid, credentials)
ssid.encode("utf-8"), credentials.encode("utf-8"))
)

def SetThreadOperationalDataset(self, threadOperationalDataset):
Expand Down
8 changes: 4 additions & 4 deletions src/controller/python/test/test_scripts/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def _WaitForOneDiscoveredDevice(self, timeoutSeconds: int = 2):
time.sleep(0.2)
if time.time() > timeout:
return None
return ctypes.string_at(addrStrStorage)
return ctypes.string_at(addrStrStorage).decode("utf-8")

def TestDiscovery(self, discriminator: int):
self.logger.info(
Expand All @@ -207,7 +207,7 @@ def TestPaseOnly(self, ip: str, setuppin: int, nodeid: int):
self.logger.info(
"Attempting to establish PASE session with device id: {} addr: {}".format(str(nodeid), ip))
if self.devCtrl.EstablishPASESessionIP(
ip.encode("utf-8"), setuppin, nodeid) is not None:
ip, setuppin, nodeid) is not None:
self.logger.info(
"Failed to establish PASE session with device id: {} addr: {}".format(str(nodeid), ip))
return False
Expand Down Expand Up @@ -261,7 +261,7 @@ def TestCommissionFailureOnReport(self, nodeid: int, failAfter: int):

def TestCommissioning(self, ip: str, setuppin: int, nodeid: int):
self.logger.info("Commissioning device {}".format(ip))
if not self.devCtrl.CommissionIP(ip.encode("utf-8"), setuppin, nodeid):
if not self.devCtrl.CommissionIP(ip, setuppin, nodeid):
self.logger.info(
"Failed to finish commissioning device {}".format(ip))
return False
Expand Down Expand Up @@ -483,7 +483,7 @@ async def TestMultiFabric(self, ip: str, setuppin: int, nodeid: int):
self.devCtrl2 = self.fabricAdmin2.NewController(
self.controllerNodeId, self.paaTrustStorePath)

if not self.devCtrl2.CommissionIP(ip.encode("utf-8"), setuppin, nodeid):
if not self.devCtrl2.CommissionIP(ip, setuppin, nodeid):
self.logger.info(
"Failed to finish key exchange with device {}".format(ip))
return False
Expand Down
2 changes: 0 additions & 2 deletions src/controller/python/test/test_scripts/mobile-device-test.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ def ethernet_commissioning(test: BaseTestHelper, discriminator: int, setup_pin:

if address_override:
address = address_override
else:
address = address.decode("utf-8")

logger.info("Testing commissioning")
FailIfNot(test.TestCommissioning(ip=address,
Expand Down