Last pep8 errors.
This commit is contained in:
parent
023cafad90
commit
066a696b5c
4 changed files with 166 additions and 168 deletions
|
@ -192,7 +192,7 @@ class MyRadioAPI:
|
|||
def get_playlist_aux_items(self, library_id: str):
|
||||
# Sometimes they have "aux-<ID>", we only need the index.
|
||||
if library_id.index("-") > -1:
|
||||
library_id = library_id[library_id.index("-") + 1 :]
|
||||
library_id = library_id[library_id.index("-") + 1:]
|
||||
|
||||
url = "/nipswebPlaylist/{}/items".format(library_id)
|
||||
request = self.get_apiv2_call(url)
|
||||
|
|
|
@ -162,7 +162,7 @@ class StateManager:
|
|||
for callback in self.callbacks:
|
||||
try:
|
||||
callback()
|
||||
except Exception as e :
|
||||
except Exception as e:
|
||||
self.logger.log.critical(
|
||||
"Failed to execute status callback: {}".format(e)
|
||||
)
|
||||
|
|
|
@ -104,9 +104,9 @@ class TestPlayer(unittest.TestCase):
|
|||
source = response[: response.index(":")]
|
||||
if source in sources_filter:
|
||||
return response[
|
||||
len(source + ":" + msg) + 1 :
|
||||
len(source + ":" + msg) + 1:
|
||||
] # +1 to remove trailing : on source.
|
||||
except Empty :
|
||||
except Empty:
|
||||
pass
|
||||
finally:
|
||||
time.sleep(0.01)
|
||||
|
|
|
@ -62,23 +62,31 @@ class WebsocketServer:
|
|||
for channel in self.channel_to_q:
|
||||
channel.put("WEBSOCKET:STATUS")
|
||||
|
||||
async def handle_from_webstudio():
|
||||
self.from_webstudio = asyncio.create_task(self.handle_from_webstudio(websocket))
|
||||
self.to_webstudio = asyncio.create_task(self.handle_to_webstudio())
|
||||
|
||||
try:
|
||||
self.threads = await shield(
|
||||
asyncio.gather(self.from_webstudio, self.to_webstudio)
|
||||
)
|
||||
finally:
|
||||
self.from_webstudio.cancel()
|
||||
self.to_webstudio.cancel()
|
||||
|
||||
async def handle_from_webstudio(self, websocket):
|
||||
try:
|
||||
async for message in websocket:
|
||||
data = json.loads(message)
|
||||
if "channel" not in data:
|
||||
# Didn't specify a channel, send to all.
|
||||
for channel in range(len(self.channel_to_q)):
|
||||
sendCommand(channel, data)
|
||||
self.sendCommand(channel, data)
|
||||
else:
|
||||
channel = int(data["channel"])
|
||||
sendCommand(channel, data)
|
||||
|
||||
async def send(conn, message):
|
||||
conn.send(message)
|
||||
self.sendCommand(channel, data)
|
||||
|
||||
await asyncio.wait(
|
||||
[send(conn, message) for conn in self.baps_clients]
|
||||
[conn.send(message) for conn in self.baps_clients]
|
||||
)
|
||||
|
||||
except websockets.exceptions.ConnectionClosedError as e:
|
||||
|
@ -94,7 +102,7 @@ class WebsocketServer:
|
|||
self.logger.log.info("Removing client: {}".format(websocket))
|
||||
self.baps_clients.remove(websocket)
|
||||
|
||||
def sendCommand(channel, data):
|
||||
def sendCommand(self, channel, data):
|
||||
if channel not in range(len(self.channel_to_q)):
|
||||
self.logger.log.exception(
|
||||
"Received channel number larger than server supported channels."
|
||||
|
@ -173,7 +181,7 @@ class WebsocketServer:
|
|||
"Command missing from message. Data: {}".format(data)
|
||||
)
|
||||
|
||||
async def handle_to_webstudio():
|
||||
async def handle_to_webstudio(self):
|
||||
while True:
|
||||
for channel in range(len(self.webstudio_to_q)):
|
||||
try:
|
||||
|
@ -224,16 +232,6 @@ class WebsocketServer:
|
|||
)
|
||||
await asyncio.sleep(0.02)
|
||||
|
||||
self.from_webstudio = asyncio.create_task(handle_from_webstudio())
|
||||
self.to_webstudio = asyncio.create_task(handle_to_webstudio())
|
||||
|
||||
try:
|
||||
self.threads = await shield(
|
||||
asyncio.gather(self.from_webstudio, self.to_webstudio)
|
||||
)
|
||||
finally:
|
||||
self.from_webstudio.cancel()
|
||||
self.to_webstudio.cancel()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
Loading…
Reference in a new issue