Skip to content

Commit 333e19d

Browse files
committed
test fixes
1 parent 0b6e17b commit 333e19d

File tree

2 files changed

+112
-141
lines changed

2 files changed

+112
-141
lines changed

nowplaying/inputs/stagelinq.py

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,23 @@
33

44
import asyncio
55
import contextlib
6-
from curses import meta
76
import dataclasses
87
import datetime
98
import logging
109

1110
from typing import TYPE_CHECKING
1211

13-
from nowplaying.exceptions import PluginVerifyError
1412
from nowplaying.inputs import InputPlugin
1513
from nowplaying.types import TrackMetadata
1614

1715
from nowplaying.vendor.stagelinq.discovery import DiscoveryConfig, discover_stagelinq_devices
16+
from nowplaying.vendor.stagelinq.device import AsyncDevice
1817
from nowplaying.vendor.stagelinq.messages import Token
1918
from nowplaying.vendor.stagelinq.value_names import DeckValueNames
2019

2120
if TYPE_CHECKING:
2221
import nowplaying.config
23-
from nowplaying.vendor.stagelinq.device import AsyncDevice, State
22+
from nowplaying.vendor.stagelinq.device import State
2423
from PySide6.QtWidgets import QWidget
2524

2625

@@ -30,7 +29,7 @@ class DeckInfo():
3029
updated: datetime.datetime
3130
track: str | None = None
3231
artist: str | None = None
33-
bpm: int | None = None
32+
bpm: float | None = None
3433
playing: bool = False
3534

3635
def __post_init__(self):
@@ -58,7 +57,7 @@ class StagelinqHandler():
5857

5958
def __init__(self, event: asyncio.Event):
6059
"""Initialize the StagelinQ handler.
61-
60+
6261
Args:
6362
event: Asyncio event used to signal shutdown
6463
"""
@@ -69,7 +68,7 @@ def __init__(self, event: asyncio.Event):
6968

7069
async def get_device(self):
7170
"""Discover and connect to a StagelinQ device.
72-
71+
7372
Continuously searches for StagelinQ devices until one is found
7473
or the event is set to stop searching.
7574
"""
@@ -89,12 +88,12 @@ async def get_device(self):
8988
logging.info("Waiting for devices... (searching)")
9089
await asyncio.sleep(2)
9190

92-
except Exception as e:
93-
logging.exception("Discovery error: %s", e)
91+
except Exception as err: # pylint: disable=broad-exception-caught
92+
logging.exception("Discovery error: %s", err)
9493

9594
async def loop(self):
9695
"""Main loop that maintains connection to StagelinQ device and processes updates.
97-
96+
9897
This method handles device discovery, connection management, and subscribes
9998
to track state updates from all decks. It automatically reconnects if
10099
the connection is lost.
@@ -152,14 +151,15 @@ async def loop(self):
152151
if self.event.is_set():
153152
return
154153

155-
except Exception as e:
156-
logging.error(f"Connection error: {e}")
154+
except Exception as err: # pylint: disable=broad-exception-caught
155+
logging.exception("Connection error: %s", err)
157156
logging.error("Retrying connection in 5 seconds...")
158157
await asyncio.sleep(5)
159158

160-
def process_state_update(self, temp_decks: dict[int, DeckInfo], state: "State"):
159+
@staticmethod
160+
def process_state_update(temp_decks: dict[int, DeckInfo], state: "State"):
161161
"""Process a state update and update deck information.
162-
162+
163163
Args:
164164
temp_decks: Dictionary of deck information being built during this update cycle
165165
state: StagelinQ state object containing updated deck information
@@ -186,7 +186,7 @@ def process_state_update(self, temp_decks: dict[int, DeckInfo], state: "State"):
186186

187187
def update_current_tracks(self, temp_decks: dict[int, DeckInfo]):
188188
"""Update the current deck states with new information.
189-
189+
190190
Args:
191191
temp_decks: Dictionary of updated deck information from the latest state updates
192192
"""
@@ -196,7 +196,7 @@ def update_current_tracks(self, temp_decks: dict[int, DeckInfo]):
196196
if deck_num not in temp_decks:
197197
self.decks.pop(deck_num, None)
198198
continue
199-
199+
200200
if not temp_decks[deck_num].playing and deck_num in self.decks:
201201
del self.decks[deck_num]
202202
elif self.decks.get(deck_num) is None:
@@ -219,10 +219,10 @@ async def stop(self):
219219

220220
async def get_track(self, mixmode: str) -> DeckInfo | None:
221221
"""Get the currently playing track based on the specified mix mode.
222-
222+
223223
Args:
224224
mixmode: Either "newest" or "oldest" to determine which deck to return
225-
225+
226226
Returns:
227227
DeckInfo for the selected deck, or None if no decks are playing
228228
"""
@@ -269,10 +269,10 @@ def validmixmodes(self) -> list[str]: # pylint: disable=no-self-use
269269

270270
def setmixmode(self, mixmode: str) -> str: # pylint: disable=no-self-use, unused-argument
271271
"""Set the mix mode for determining which deck to use.
272-
272+
273273
Args:
274274
mixmode: Either "newest" or "oldest"
275-
275+
276276
Returns:
277277
The validated mix mode that was set
278278
"""
@@ -290,7 +290,7 @@ def getmixmode(self) -> str: # pylint: disable=no-self-use
290290

291291
async def getplayingtrack(self) -> TrackMetadata | None:
292292
"""Get the currently playing track metadata.
293-
293+
294294
Returns:
295295
Dictionary containing track metadata (artist, track, bpm) or None if no handler
296296
"""
@@ -311,10 +311,10 @@ async def getplayingtrack(self) -> TrackMetadata | None:
311311

312312
async def getrandomtrack(self, playlist: str) -> str | None:
313313
"""Get a random track from a playlist.
314-
314+
315315
Args:
316316
playlist: Name of the playlist (not implemented for StagelinQ)
317-
317+
318318
Raises:
319319
NotImplementedError: This method is not supported for StagelinQ
320320
"""

0 commit comments

Comments
 (0)