Skip to content

Commit

Permalink
Encode strings in ChipDeviceCtrl.py
Browse files Browse the repository at this point in the history
  • Loading branch information
agners committed Jul 5, 2022
1 parent 13ac032 commit d1edd0d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
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

0 comments on commit d1edd0d

Please sign in to comment.