Skip to content

Commit

Permalink
tweak
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelveldt committed Jan 31, 2025
1 parent d929249 commit 158354d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 11 deletions.
5 changes: 1 addition & 4 deletions music_assistant/providers/hass/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
from music_assistant.helpers.util import try_parse_int
from music_assistant.models.plugin import PluginProvider

from .constants import MediaPlayerEntityFeature
from .constants import OFF_STATES, MediaPlayerEntityFeature

if TYPE_CHECKING:
from hass_client.models import CompressedState, EntityStateEvent
Expand All @@ -53,9 +53,6 @@
CONF_MUTE_CONTROLS = "mute_controls"
CONF_VOLUME_CONTROLS = "volume_controls"

# HA states that we consider as "powered off"
OFF_STATES = ("unavailable", "unknown", "standby", "off")


async def setup(
mass: MusicAssistant, manifest: ProviderManifest, config: ProviderConfig
Expand Down
3 changes: 3 additions & 0 deletions music_assistant/providers/hass/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,6 @@ class MediaPlayerEntityFeature(IntFlag):
"unknown": PlayerState.IDLE,
"unavailable": PlayerState.IDLE,
}

# HA states that we consider as "powered off"
OFF_STATES = ("unavailable", "unknown", "standby", "off")
9 changes: 2 additions & 7 deletions music_assistant/providers/hass_players/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
from music_assistant.helpers.tags import async_parse_tags
from music_assistant.models.player_provider import PlayerProvider
from music_assistant.providers.hass import DOMAIN as HASS_DOMAIN
from music_assistant.providers.hass.constants import MediaPlayerEntityFeature, StateMap
from music_assistant.providers.hass.constants import OFF_STATES, MediaPlayerEntityFeature, StateMap

if TYPE_CHECKING:
from collections.abc import AsyncGenerator
Expand Down Expand Up @@ -457,12 +457,7 @@ def update_player_from_state_msg(entity_id: str, state: CompressedState) -> None
if "s" in state:
player.state = StateMap.get(state["s"], PlayerState.IDLE)
if PlayerFeature.POWER in player.supported_features:
player.powered = state["s"] not in (
"unavailable",
"unknown",
"standby",
"off",
)
player.powered = state["s"] not in OFF_STATES
if "a" in state:
self._update_player_attributes(player, state["a"])
self.mass.players.update(entity_id)
Expand Down

0 comments on commit 158354d

Please sign in to comment.