Skip to content

Commit 3a95940

Browse files
committed
refactor: address pylint warnings and improve code quality
- Remove unnecessary pass statements in exception classes and methods. - Replace f-strings with lazy % formatting in logging calls to improve performance. - Add missing class docstrings to enums and classes for better documentation.
1 parent c2098f3 commit 3a95940

3 files changed

Lines changed: 15 additions & 13 deletions

File tree

aiocomfoconnect/bridge.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@
5656
class SelfDeregistrationError(Exception):
5757
"""Exception raised when trying to deregister self."""
5858

59-
pass
60-
6159

6260
class EventBus:
6361
"""An event bus for async replies.
@@ -76,7 +74,7 @@ def add_listener(self, event_name: int, future: asyncio.Future) -> None:
7674
event_name (int): The event reference number.
7775
future (asyncio.Future): The future to be set when the event is emitted.
7876
"""
79-
_LOGGER.debug(f"Adding listener for event {event_name}")
77+
_LOGGER.debug("Adding listener for event %s", event_name)
8078
if not self.listeners.get(event_name, None):
8179
self.listeners[event_name] = {future}
8280
else:
@@ -89,7 +87,7 @@ def emit(self, event_name: int, event: Any) -> None:
8987
event_name (int): The event reference number.
9088
event (Any): The event object or exception to set on the futures.
9189
"""
92-
_LOGGER.debug(f"Emitting for event {event_name}")
90+
_LOGGER.debug("Emitting for event %s", event_name)
9391
futures = self.listeners.get(event_name, set())
9492
for future in futures:
9593
if isinstance(event, Exception):
@@ -165,11 +163,11 @@ async def _connect(self, uuid: str) -> asyncio.Task:
165163
Raises:
166164
AioComfoConnectTimeout: If connection times out.
167165
"""
168-
_LOGGER.debug(f"Connecting to bridge {self.host}")
166+
_LOGGER.debug("Connecting to bridge %s", self.host)
169167
try:
170168
self._reader, self._writer = await asyncio.wait_for(asyncio.open_connection(self.host, self.PORT), TIMEOUT)
171169
except asyncio.TimeoutError as exc:
172-
_LOGGER.warning(f"Timeout while connecting to bridge {self.host}")
170+
_LOGGER.warning("Timeout while connecting to bridge %s", self.host)
173171
raise AioComfoConnectTimeout("Timeout while connecting to bridge") from exc
174172

175173
self._reference = 1
@@ -186,7 +184,7 @@ async def _read_messages() -> None:
186184
raise AioComfoConnectNotConnected("We have been disconnected") from exc
187185

188186
self._read_task = self._loop.create_task(_read_messages())
189-
_LOGGER.debug(f"Connected to bridge {self.host}")
187+
_LOGGER.debug("Connected to bridge %s", self.host)
190188
return self._read_task
191189

192190
async def _disconnect(self) -> None:
@@ -314,7 +312,7 @@ async def _transmit_message(self, message: Message) -> None:
314312
Args:
315313
message (Message): The message to transmit.
316314
"""
317-
_LOGGER.debug(f"TX {message}")
315+
_LOGGER.debug("TX %s", message)
318316
self._writer.write(message.encode())
319317
await self._writer.drain()
320318
self._reference += 1
@@ -362,7 +360,7 @@ async def _read(self) -> Message:
362360
msg_len = int.from_bytes(msg_len_buf, byteorder="big")
363361
msg_buf = await self._reader.readexactly(msg_len)
364362
message = Message.decode(msg_buf)
365-
_LOGGER.debug(f"RX {message}")
363+
_LOGGER.debug("RX %s", message)
366364
match message.cmd.result:
367365
case zehnder_pb2.GatewayOperation.OK:
368366
pass
@@ -411,7 +409,7 @@ async def _process_message(self) -> None:
411409
case _ if message.cmd.reference:
412410
self._event_bus.emit(message.cmd.reference, message.msg)
413411
case _:
414-
_LOGGER.warning(f"Unhandled message type {message.cmd.type}: {message}")
412+
_LOGGER.warning("Unhandled message type %s: %s", message.cmd.type, message)
415413
except asyncio.IncompleteReadError as exc:
416414
_LOGGER.info("The connection was closed.")
417415
await self._disconnect()
@@ -420,7 +418,7 @@ async def _process_message(self) -> None:
420418
if exc.message.cmd.reference:
421419
self._event_bus.emit(exc.message.cmd.reference, exc)
422420
except DecodeError as exc:
423-
_LOGGER.error(f"Failed to decode message: {exc}")
421+
_LOGGER.error("Failed to decode message: %s", exc)
424422

425423
@log_call
426424
def cmd_start_session(self, take_over: bool = False) -> Awaitable[Message]:
@@ -579,7 +577,6 @@ def cmd_keepalive(self) -> Awaitable[Message]:
579577
reply=False,
580578
)
581579

582-
583580
class Message:
584581
"""A message that is sent to the bridge.
585582

aiocomfoconnect/const.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ def __str__(self) -> str:
231231

232232

233233
class VentilationTemperatureProfile(IntEnum):
234+
"""Enum representing ventilation temperature profiles."""
234235
NORMAL = 0 # 0100000000ffffffffffffffff00 = normal
235236
COOL = 1 # 0100000000ffffffffffffffff01 = cool
236237
WARM = 2 # 0100000000ffffffffffffffff02 = warm
@@ -240,6 +241,7 @@ def __str__(self) -> str:
240241

241242

242243
class VentilationSpeed(IntEnum):
244+
"""Enum representing ventilation speed levels."""
243245
AWAY = 0 # 0100000000ffffffffffffffff00 = away
244246
LOW = 1 # 0100000000ffffffffffffffff01 = low
245247
MEDIUM = 2 # 0100000000ffffffffffffffff02 = medium
@@ -250,6 +252,7 @@ def __str__(self) -> str:
250252

251253

252254
class ComfoCoolMode(IntEnum):
255+
"""Enum representing ComfoCool operating modes."""
253256
AUTO = 0x00 # protocol value for 'auto'
254257
OFF = 0x01 # protocol value for 'off'
255258

@@ -258,6 +261,7 @@ def __str__(self) -> str:
258261

259262

260263
class BypassMode(IntEnum):
264+
"""Enum representing bypass operating modes."""
261265
AUTO = 0 # 0000000000080700000000000000 = auto
262266
OPEN = 1 # 0100000000100e00000b0e000001 = open
263267
CLOSED = 2 # 0100000000100e00000d0e000002 = closed
@@ -267,6 +271,7 @@ def __str__(self) -> str:
267271

268272

269273
class AirflowSpeed(IntEnum):
274+
"""Enum representing airflow speed levels."""
270275
AWAY = 3
271276
LOW = 4
272277
MEDIUM = 5

aiocomfoconnect/decorators.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@
1010
def log_call(func):
1111
"""Decorator to log method calls for command methods."""
1212
def wrapper(self, *args, **kwargs):
13-
_LOGGER.debug(f"{func.__name__} called")
13+
_LOGGER.debug("%s called", func.__name__)
1414
return func(self, *args, **kwargs)
1515
return wrapper

0 commit comments

Comments
 (0)