From f1e44c213e7b718ae74260994259ed7b670495d3 Mon Sep 17 00:00:00 2001 From: Marcel van der Veldt Date: Sat, 19 Sep 2020 17:38:34 +0200 Subject: [PATCH] cool down errors in log, send stop command on power off --- music_assistant/constants.py | 2 +- music_assistant/player_manager.py | 3 +++ music_assistant/web.py | 15 ++++++++------- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/music_assistant/constants.py b/music_assistant/constants.py index df4939ba..941071d9 100755 --- a/music_assistant/constants.py +++ b/music_assistant/constants.py @@ -1,6 +1,6 @@ """All constants for Music Assistant.""" -__version__ = "0.0.37" +__version__ = "0.0.38" REQUIRED_PYTHON_VER = "3.7" CONF_USERNAME = "username" diff --git a/music_assistant/player_manager.py b/music_assistant/player_manager.py index 207b8f52..bee1022d 100755 --- a/music_assistant/player_manager.py +++ b/music_assistant/player_manager.py @@ -428,6 +428,9 @@ class PlayerManager: player = self.get_player(player_id) if not player: return + # send stop if player is playing + if player.active_queue == player_id: + await self.async_cmd_stop(player_id) player_config = self.mass.config.player_settings[player.player_id] # turn off player await self.get_player_provider(player_id).async_cmd_power_off(player_id) diff --git a/music_assistant/web.py b/music_assistant/web.py index 14e7becb..43ff0a74 100755 --- a/music_assistant/web.py +++ b/music_assistant/web.py @@ -690,7 +690,10 @@ class Web: # callback for internal events async def async_send_message(msg, msg_details=None): ws_msg = {"message": msg, "message_details": msg_details} - await ws_response.send_json(ws_msg, dumps=json_serializer) + try: + await ws_response.send_json(ws_msg, dumps=json_serializer) + except AssertionError: + LOGGER.debug("trying to send message to ws while disconnected") # process incoming messages async for msg in ws_response: @@ -744,13 +747,11 @@ class Web: else: # simply echo the message on the eventbus self.mass.signal_event(msg, msg_details) - - except (AssertionError, asyncio.CancelledError) as exc: - LOGGER.warning("Websocket disconnected - %s", str(exc)) + except (AssertionError, asyncio.CancelledError): + LOGGER.debug("Websocket disconnected") finally: - for callback in remove_callbacks: - callback() - LOGGER.debug("websocket connection closed") + for remove_callback in remove_callbacks: + remove_callback() return ws_response @require_local_subnet -- 2.34.1