Skip to content

Commit 9189b79

Browse files
authored
[Python] Use Python logging everywhere (project-chip#32383)
Do not print to the console but use the Python logging module explicitly.
1 parent ac1ebc5 commit 9189b79

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

src/controller/python/chip/ChipDeviceCtrl.py

+12-11
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import ctypes
3535
import enum
3636
import json
37+
import logging
3738
import threading
3839
import time
3940
import typing
@@ -265,9 +266,9 @@ def __init__(self, name: str = ''):
265266
def _set_dev_ctrl(self, devCtrl):
266267
def HandleCommissioningComplete(nodeid, err):
267268
if err.is_success:
268-
print("Commissioning complete")
269+
logging.info("Commissioning complete")
269270
else:
270-
print("Failed to commission: {}".format(err))
271+
logging.warning("Failed to commission: {}".format(err))
271272

272273
self.state = DCState.IDLE
273274
self._ChipStack.callbackRes = err
@@ -283,30 +284,30 @@ def HandleFabricCheck(nodeId):
283284
def HandleOpenWindowComplete(nodeid: int, setupPinCode: int, setupManualCode: str,
284285
setupQRCode: str, err: PyChipError) -> None:
285286
if err.is_success:
286-
print("Open Commissioning Window complete setting nodeid {} pincode to {}".format(nodeid, setupPinCode))
287+
logging.info("Open Commissioning Window complete setting nodeid {} pincode to {}".format(nodeid, setupPinCode))
287288
self._ChipStack.openCommissioningWindowPincode[nodeid] = CommissioningParameters(
288289
setupPinCode=setupPinCode, setupManualCode=setupManualCode.decode(), setupQRCode=setupQRCode.decode())
289290
else:
290-
print("Failed to open commissioning window: {}".format(err))
291+
logging.warning("Failed to open commissioning window: {}".format(err))
291292

292293
self._ChipStack.callbackRes = err
293294
self._ChipStack.completeEvent.set()
294295

295296
def HandleUnpairDeviceComplete(nodeid: int, err: PyChipError):
296297
if err.is_success:
297-
print("Succesfully unpaired device with nodeid {}".format(nodeid))
298+
logging.info("Succesfully unpaired device with nodeid {}".format(nodeid))
298299
else:
299-
print("Failed to unpair device: {}".format(err))
300+
logging.warning("Failed to unpair device: {}".format(err))
300301

301302
self._ChipStack.callbackRes = err
302303
self._ChipStack.completeEvent.set()
303304

304305
def HandlePASEEstablishmentComplete(err: PyChipError):
305306
if not err.is_success:
306-
print("Failed to establish secure session to device: {}".format(err))
307+
logging.warning("Failed to establish secure session to device: {}".format(err))
307308
self._ChipStack.callbackRes = err.to_exception()
308309
else:
309-
print("Established secure session with Device")
310+
logging.info("Established secure session with Device")
310311

311312
if self.state != DCState.COMMISSIONING:
312313
# During Commissioning, HandlePASEEstablishmentComplete will also be called,
@@ -785,7 +786,7 @@ def GetConnectedDeviceSync(self, nodeid, allowPASE=True, timeoutMs: int = None):
785786
res = self._ChipStack.Call(lambda: self._dmLib.pychip_GetDeviceBeingCommissioned(
786787
self.devCtrl, nodeid, byref(returnDevice)), timeoutMs)
787788
if res.is_success:
788-
print('Using PASE connection')
789+
logging.info('Using PASE connection')
789790
return DeviceProxyWrapper(returnDevice)
790791

791792
class DeviceAvailableClosure():
@@ -1151,7 +1152,7 @@ def _parseEventPathTuple(self, pathTuple: typing.Union[
11511152
# Wildcard
11521153
pass
11531154
elif not isinstance(pathTuple, tuple):
1154-
print(type(pathTuple))
1155+
logging.debug(type(pathTuple))
11551156
if isinstance(pathTuple, int):
11561157
endpoint = pathTuple
11571158
elif issubclass(pathTuple, ClusterObjects.Cluster):
@@ -1426,7 +1427,7 @@ def ZCLSend(self, cluster, command, nodeid, endpoint, groupid, args, blocking=Fa
14261427
raise UnknownCommand(cluster, command)
14271428
try:
14281429
res = asyncio.run(self.SendCommand(nodeid, endpoint, req))
1429-
print(f"CommandResponse {res}")
1430+
logging.debug(f"CommandResponse {res}")
14301431
return (0, res)
14311432
except InteractionModelError as ex:
14321433
return (int(ex.status), None)

0 commit comments

Comments
 (0)