From 35dde0d9bcdb4e1ec8a62980aa967700b0ac92a3 Mon Sep 17 00:00:00 2001 From: Marijn Doeve Date: Sun, 5 Jun 2022 16:00:19 +0200 Subject: [PATCH] Prefix on prints --- extron.py | 2 ++ projector.py | 2 ++ serialdevice.py | 7 ++++--- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/extron.py b/extron.py index 3d649ef..d929167 100644 --- a/extron.py +++ b/extron.py @@ -36,6 +36,8 @@ class ExtronSerial(SerialDevice): baudrate = 9600 super().__init__(serial_port, baudrate, verbose) + self.prefix = "Extron " + def send_command(self, command: str) -> str: response = super().send_command(command) diff --git a/projector.py b/projector.py index b799f43..79a9c9e 100644 --- a/projector.py +++ b/projector.py @@ -11,6 +11,8 @@ class ProjectorSerial(SerialDevice): super().__init__(serial_port, baudrate, verbose) + self.prefix = "Projector" + def send_command(self, command: str, device_id: str = "ZZ") -> str: assert device_id in ["01", "02", "03", "04", "05", "06", "ZZ"] diff --git a/serialdevice.py b/serialdevice.py index a48d9f7..46fe2a6 100644 --- a/serialdevice.py +++ b/serialdevice.py @@ -9,12 +9,13 @@ class SerialDevice: self.serial_port: str = serial_port self.baudrate = baudrate self.verbose = verbose + self.prefix = "" def send_command(self, command: str) -> str: with Serial(self.serial_port, self.baudrate, timeout=1) as s: if self.verbose: - print("Send:", command) + print(self.prefix, "send:", command) s.write(command.encode()) @@ -30,8 +31,8 @@ class SerialDevice: response = "" if self.verbose: - print("Resp:", response) + print(self.prefix, "resp:", response) if not response: - print("No response") + print(self.prefix, "No response") return response