55from asyncio import Queue , Task , get_running_loop , sleep
66from collections .abc import Callable
77from dataclasses import dataclass
8- from sortedcontainers import SortedList
98import logging
109
10+ from sortedcontainers import SortedList
11+
1112from ..api import StickEvent
1213from ..exceptions import MessageError , NodeTimeout , StickError , StickTimeout
1314from ..messages import Priority
@@ -31,6 +32,7 @@ class DroppingPriorityQueue(Queue):
3132
3233 Older entries are dropped when the queue reaches its maximum size.
3334 """
35+
3436 def _init (self , maxsize ):
3537 # called by asyncio.Queue.__init__
3638 self ._queue = SortedList ()
@@ -52,7 +54,7 @@ def __drop(self):
5254 self .task_done ()
5355
5456 def put_nowait (self , item ):
55- """ Override method for queue.put."""
57+ """Override method for queue.put."""
5658 if self .full ():
5759 self .__drop ()
5860 super ().put_nowait (item )
@@ -72,7 +74,9 @@ def __init__(self) -> None:
7274 """Initialize the message session controller."""
7375 self ._stick : StickConnectionManager | None = None
7476 self ._loop = get_running_loop ()
75- self ._submit_queue : DroppingPriorityQueue [PlugwiseRequest ] = DroppingPriorityQueue (maxsize = 56 )
77+ self ._submit_queue : DroppingPriorityQueue [PlugwiseRequest ] = (
78+ DroppingPriorityQueue (maxsize = 56 )
79+ )
7680 self ._submit_worker_task : Task [None ] | None = None
7781 self ._unsubscribe_connection_events : Callable [[], None ] | None = None
7882 self ._running = False
@@ -187,7 +191,9 @@ async def _send_queue_worker(self) -> None:
187191 return
188192
189193 if self ._stick .queue_depth > 3 :
190- _LOGGER .warning ("Awaiting plugwise responses %d" , self ._stick .queue_depth )
194+ _LOGGER .warning (
195+ "Awaiting plugwise responses %d" , self ._stick .queue_depth
196+ )
191197 await sleep (0.125 )
192198
193199 await self ._stick .write_to_stick (request )
0 commit comments