From 3e652b1b88b0898eaa2d3988faa6592737bc63a3 Mon Sep 17 00:00:00 2001 From: Marcel van der Veldt Date: Fri, 25 Oct 2024 02:06:49 +0200 Subject: [PATCH] Handle stop on HA media players --- .../server/providers/hass_players/__init__.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/music_assistant/server/providers/hass_players/__init__.py b/music_assistant/server/providers/hass_players/__init__.py index 4bbe66203..2ed93adf1 100644 --- a/music_assistant/server/providers/hass_players/__init__.py +++ b/music_assistant/server/providers/hass_players/__init__.py @@ -11,6 +11,8 @@ from enum import IntFlag from typing import TYPE_CHECKING, Any +from hass_client.exceptions import FailedCommand + from music_assistant.common.helpers.datetime import from_iso_string from music_assistant.common.models.config_entries import ( CONF_ENTRY_CROSSFADE_DURATION, @@ -223,9 +225,17 @@ async def cmd_stop(self, player_id: str) -> None: - player_id: player_id of the player to handle the command. """ - await self.hass_prov.hass.call_service( - domain="media_player", service="media_stop", target={"entity_id": player_id} - ) + try: + await self.hass_prov.hass.call_service( + domain="media_player", service="media_stop", target={"entity_id": player_id} + ) + except FailedCommand as exc: + # some HA players do not support STOP + if "does not support this service" not in str(exc): + raise + if player := self.mass.players.get(player_id): + if PlayerFeature.PAUSE in player.supported_features: + await self.cmd_pause(player_id) async def cmd_play(self, player_id: str) -> None: """Send PLAY (unpause) command to given player.