|
| 1 | +From 9189b790c7b6f713a40222ddec9ffb99742a05e7 Mon Sep 17 00:00:00 2001 |
| 2 | +Message-ID: <9189b790c7b6f713a40222ddec9ffb99742a05e7.1711548827.git.stefan@agner.ch> |
| 3 | +From: Stefan Agner <stefan@agner.ch> |
| 4 | +Date: Fri, 1 Mar 2024 09:43:47 +0100 |
| 5 | +Subject: [PATCH] [Python] Use Python logging everywhere (#32383) |
| 6 | + |
| 7 | +Do not print to the console but use the Python logging module |
| 8 | +explicitly. |
| 9 | +--- |
| 10 | + src/controller/python/chip/ChipDeviceCtrl.py | 23 ++++++++++---------- |
| 11 | + 1 file changed, 12 insertions(+), 11 deletions(-) |
| 12 | + |
| 13 | +diff --git a/src/controller/python/chip/ChipDeviceCtrl.py b/src/controller/python/chip/ChipDeviceCtrl.py |
| 14 | +index 318c2b56ef..bf9bb245ec 100644 |
| 15 | +--- a/src/controller/python/chip/ChipDeviceCtrl.py |
| 16 | ++++ b/src/controller/python/chip/ChipDeviceCtrl.py |
| 17 | +@@ -34,6 +34,7 @@ import copy |
| 18 | + import ctypes |
| 19 | + import enum |
| 20 | + import json |
| 21 | ++import logging |
| 22 | + import threading |
| 23 | + import time |
| 24 | + import typing |
| 25 | +@@ -265,9 +266,9 @@ class ChipDeviceControllerBase(): |
| 26 | + def _set_dev_ctrl(self, devCtrl): |
| 27 | + def HandleCommissioningComplete(nodeid, err): |
| 28 | + if err.is_success: |
| 29 | +- print("Commissioning complete") |
| 30 | ++ logging.info("Commissioning complete") |
| 31 | + else: |
| 32 | +- print("Failed to commission: {}".format(err)) |
| 33 | ++ logging.warning("Failed to commission: {}".format(err)) |
| 34 | + |
| 35 | + self.state = DCState.IDLE |
| 36 | + self._ChipStack.callbackRes = err |
| 37 | +@@ -283,30 +284,30 @@ class ChipDeviceControllerBase(): |
| 38 | + def HandleOpenWindowComplete(nodeid: int, setupPinCode: int, setupManualCode: str, |
| 39 | + setupQRCode: str, err: PyChipError) -> None: |
| 40 | + if err.is_success: |
| 41 | +- print("Open Commissioning Window complete setting nodeid {} pincode to {}".format(nodeid, setupPinCode)) |
| 42 | ++ logging.info("Open Commissioning Window complete setting nodeid {} pincode to {}".format(nodeid, setupPinCode)) |
| 43 | + self._ChipStack.openCommissioningWindowPincode[nodeid] = CommissioningParameters( |
| 44 | + setupPinCode=setupPinCode, setupManualCode=setupManualCode.decode(), setupQRCode=setupQRCode.decode()) |
| 45 | + else: |
| 46 | +- print("Failed to open commissioning window: {}".format(err)) |
| 47 | ++ logging.warning("Failed to open commissioning window: {}".format(err)) |
| 48 | + |
| 49 | + self._ChipStack.callbackRes = err |
| 50 | + self._ChipStack.completeEvent.set() |
| 51 | + |
| 52 | + def HandleUnpairDeviceComplete(nodeid: int, err: PyChipError): |
| 53 | + if err.is_success: |
| 54 | +- print("Succesfully unpaired device with nodeid {}".format(nodeid)) |
| 55 | ++ logging.info("Succesfully unpaired device with nodeid {}".format(nodeid)) |
| 56 | + else: |
| 57 | +- print("Failed to unpair device: {}".format(err)) |
| 58 | ++ logging.warning("Failed to unpair device: {}".format(err)) |
| 59 | + |
| 60 | + self._ChipStack.callbackRes = err |
| 61 | + self._ChipStack.completeEvent.set() |
| 62 | + |
| 63 | + def HandlePASEEstablishmentComplete(err: PyChipError): |
| 64 | + if not err.is_success: |
| 65 | +- print("Failed to establish secure session to device: {}".format(err)) |
| 66 | ++ logging.warning("Failed to establish secure session to device: {}".format(err)) |
| 67 | + self._ChipStack.callbackRes = err.to_exception() |
| 68 | + else: |
| 69 | +- print("Established secure session with Device") |
| 70 | ++ logging.info("Established secure session with Device") |
| 71 | + |
| 72 | + if self.state != DCState.COMMISSIONING: |
| 73 | + # During Commissioning, HandlePASEEstablishmentComplete will also be called, |
| 74 | +@@ -785,7 +786,7 @@ class ChipDeviceControllerBase(): |
| 75 | + res = self._ChipStack.Call(lambda: self._dmLib.pychip_GetDeviceBeingCommissioned( |
| 76 | + self.devCtrl, nodeid, byref(returnDevice)), timeoutMs) |
| 77 | + if res.is_success: |
| 78 | +- print('Using PASE connection') |
| 79 | ++ logging.info('Using PASE connection') |
| 80 | + return DeviceProxyWrapper(returnDevice) |
| 81 | + |
| 82 | + class DeviceAvailableClosure(): |
| 83 | +@@ -1151,7 +1152,7 @@ class ChipDeviceControllerBase(): |
| 84 | + # Wildcard |
| 85 | + pass |
| 86 | + elif not isinstance(pathTuple, tuple): |
| 87 | +- print(type(pathTuple)) |
| 88 | ++ logging.debug(type(pathTuple)) |
| 89 | + if isinstance(pathTuple, int): |
| 90 | + endpoint = pathTuple |
| 91 | + elif issubclass(pathTuple, ClusterObjects.Cluster): |
| 92 | +@@ -1426,7 +1427,7 @@ class ChipDeviceControllerBase(): |
| 93 | + raise UnknownCommand(cluster, command) |
| 94 | + try: |
| 95 | + res = asyncio.run(self.SendCommand(nodeid, endpoint, req)) |
| 96 | +- print(f"CommandResponse {res}") |
| 97 | ++ logging.debug(f"CommandResponse {res}") |
| 98 | + return (0, res) |
| 99 | + except InteractionModelError as ex: |
| 100 | + return (int(ex.status), None) |
| 101 | +-- |
| 102 | +2.44.0 |
| 103 | + |
0 commit comments