Skip to content

Commit

Permalink
Handle stop on HA media players
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelveldt committed Oct 25, 2024
1 parent d9ae94e commit 3e652b1
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions music_assistant/server/providers/hass_players/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 3e652b1

Please sign in to comment.