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

Add patch to use Python logging everywhere #46

Merged
merged 1 commit into from
Mar 27, 2024
Merged
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
103 changes: 103 additions & 0 deletions 0010-Python-Use-Python-logging-everywhere-32383.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
From 9189b790c7b6f713a40222ddec9ffb99742a05e7 Mon Sep 17 00:00:00 2001
Message-ID: <9189b790c7b6f713a40222ddec9ffb99742a05e7.1711548827.git.stefan@agner.ch>
From: Stefan Agner <stefan@agner.ch>
Date: Fri, 1 Mar 2024 09:43:47 +0100
Subject: [PATCH] [Python] Use Python logging everywhere (#32383)

Do not print to the console but use the Python logging module
explicitly.
---
src/controller/python/chip/ChipDeviceCtrl.py | 23 ++++++++++----------
1 file changed, 12 insertions(+), 11 deletions(-)

diff --git a/src/controller/python/chip/ChipDeviceCtrl.py b/src/controller/python/chip/ChipDeviceCtrl.py
index 318c2b56ef..bf9bb245ec 100644
--- a/src/controller/python/chip/ChipDeviceCtrl.py
+++ b/src/controller/python/chip/ChipDeviceCtrl.py
@@ -34,6 +34,7 @@ import copy
import ctypes
import enum
import json
+import logging
import threading
import time
import typing
@@ -265,9 +266,9 @@ class ChipDeviceControllerBase():
def _set_dev_ctrl(self, devCtrl):
def HandleCommissioningComplete(nodeid, err):
if err.is_success:
- print("Commissioning complete")
+ logging.info("Commissioning complete")
else:
- print("Failed to commission: {}".format(err))
+ logging.warning("Failed to commission: {}".format(err))

self.state = DCState.IDLE
self._ChipStack.callbackRes = err
@@ -283,30 +284,30 @@ class ChipDeviceControllerBase():
def HandleOpenWindowComplete(nodeid: int, setupPinCode: int, setupManualCode: str,
setupQRCode: str, err: PyChipError) -> None:
if err.is_success:
- print("Open Commissioning Window complete setting nodeid {} pincode to {}".format(nodeid, setupPinCode))
+ logging.info("Open Commissioning Window complete setting nodeid {} pincode to {}".format(nodeid, setupPinCode))
self._ChipStack.openCommissioningWindowPincode[nodeid] = CommissioningParameters(
setupPinCode=setupPinCode, setupManualCode=setupManualCode.decode(), setupQRCode=setupQRCode.decode())
else:
- print("Failed to open commissioning window: {}".format(err))
+ logging.warning("Failed to open commissioning window: {}".format(err))

self._ChipStack.callbackRes = err
self._ChipStack.completeEvent.set()

def HandleUnpairDeviceComplete(nodeid: int, err: PyChipError):
if err.is_success:
- print("Succesfully unpaired device with nodeid {}".format(nodeid))
+ logging.info("Succesfully unpaired device with nodeid {}".format(nodeid))
else:
- print("Failed to unpair device: {}".format(err))
+ logging.warning("Failed to unpair device: {}".format(err))

self._ChipStack.callbackRes = err
self._ChipStack.completeEvent.set()

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

if self.state != DCState.COMMISSIONING:
# During Commissioning, HandlePASEEstablishmentComplete will also be called,
@@ -785,7 +786,7 @@ class ChipDeviceControllerBase():
res = self._ChipStack.Call(lambda: self._dmLib.pychip_GetDeviceBeingCommissioned(
self.devCtrl, nodeid, byref(returnDevice)), timeoutMs)
if res.is_success:
- print('Using PASE connection')
+ logging.info('Using PASE connection')
return DeviceProxyWrapper(returnDevice)

class DeviceAvailableClosure():
@@ -1151,7 +1152,7 @@ class ChipDeviceControllerBase():
# Wildcard
pass
elif not isinstance(pathTuple, tuple):
- print(type(pathTuple))
+ logging.debug(type(pathTuple))
if isinstance(pathTuple, int):
endpoint = pathTuple
elif issubclass(pathTuple, ClusterObjects.Cluster):
@@ -1426,7 +1427,7 @@ class ChipDeviceControllerBase():
raise UnknownCommand(cluster, command)
try:
res = asyncio.run(self.SendCommand(nodeid, endpoint, req))
- print(f"CommandResponse {res}")
+ logging.debug(f"CommandResponse {res}")
return (0, res)
except InteractionModelError as ex:
return (int(ex.status), None)
--
2.44.0

Loading