From 04eed185cd9658b0f93e2eceaafe589fbb589ac2 Mon Sep 17 00:00:00 2001 From: Rogier van Staveren Date: Sun, 8 Dec 2024 15:26:46 +0100 Subject: [PATCH] Code and documentation tweaks --- benqprojector/benqprojector.py | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/benqprojector/benqprojector.py b/benqprojector/benqprojector.py index 781ab16..f523d05 100644 --- a/benqprojector/benqprojector.py +++ b/benqprojector/benqprojector.py @@ -192,10 +192,10 @@ def __str__(self): class BenQProjector(ABC): """ - BenQProjector class for controlling BenQ projectors. + BenQProjector base class for controlling BenQ projectors. """ - connection = None + connection: BenQConnection | None = None # Native networked projectors don't seem to have a command prompt, the code tries to detect if this is the case has_prompt = None _separator = b"\n" @@ -340,10 +340,7 @@ async def _connect(self) -> bool: await self.connection.open() logger.debug("Connected to %s", self.connection) - if self.connected(): - return True - - return False + return self.connected() async def connect(self, loop=None, interval: float = None) -> bool: """ @@ -462,10 +459,7 @@ async def connect(self, loop=None, interval: float = None) -> bool: return True def connected(self) -> bool: - if self.connection and self.connection.is_open(): - return True - - return False + return self.connection and self.connection.is_open() async def _disconnect(self): await self.connection.close() @@ -498,7 +492,7 @@ def _forward_to_listeners(self, command: str, data: Any | None): listener(command, data) # pylint: disable=broad-exception-caught except Exception: - logger.exception("Exception in Callback: %s", listener) + logger.exception("Exception in listener: %s", listener) async def _cancel_read(self) -> bool: if self._read_task is not None and not ( @@ -575,10 +569,6 @@ async def _read_coroutine(self): except (BrokenPipeError, ConnectionResetError, TimeoutError): logger.exception("Error communicating with BenQ projector") await self._disconnect() - # break - except Exception: - logger.exception("Unexpected error") - break self._read_task = None logger.debug("Read coroutine stopped") @@ -1486,8 +1476,7 @@ class BenQProjectorSerial(BenQProjector): def __init__( self, - serial_port: str, # The serial port where the RS-485 interface and - # screen is connected to. + serial_port: str, baud_rate: int, model_hint: str = None, strict_validation: bool = False,