Skip to content

Commit 8ea16da

Browse files
authored
Correctly map repeat mode in Music Assistant (#155777)
1 parent 5bd89ac commit 8ea16da

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

homeassistant/components/music_assistant/media_player.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,13 @@
115115
MediaPlayerEnqueue.REPLACE: QueueOption.REPLACE,
116116
}
117117

118+
REPEAT_MODE_MAPPING_TO_HA = {
119+
MassRepeatMode.OFF: RepeatMode.OFF,
120+
MassRepeatMode.ONE: RepeatMode.ONE,
121+
MassRepeatMode.ALL: RepeatMode.ALL,
122+
# UNKNOWN is intentionally not mapped - will return None
123+
}
124+
118125
SERVICE_PLAY_MEDIA_ADVANCED = "play_media"
119126
SERVICE_PLAY_ANNOUNCEMENT = "play_announcement"
120127
SERVICE_TRANSFER_QUEUE = "transfer_queue"
@@ -657,7 +664,7 @@ def _update_media_attributes(
657664
# player has an MA queue active (either its own queue or some group queue)
658665
self._attr_app_id = DOMAIN
659666
self._attr_shuffle = queue.shuffle_enabled
660-
self._attr_repeat = queue.repeat_mode.value
667+
self._attr_repeat = REPEAT_MODE_MAPPING_TO_HA.get(queue.repeat_mode)
661668
if not (cur_item := queue.current_item):
662669
# queue is empty
663670
return

tests/components/music_assistant/fixtures/player_queues.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@
134134
"links": null,
135135
"chapters": null,
136136
"performers": null,
137-
"preview": "https://p.scdn.co/mp3-preview/98deb9c370bbaa350be058b3470fbe3bc1e28d9d?cid=2eb96f9b37494be1824999d58028a305",
137+
"preview": "https://p.scdn.co/mp3-preview/98deb9c370bbaa350be058b3470fbe3bc1e28d9d",
138138
"popularity": 77,
139139
"last_refresh": null
140140
},

tests/components/music_assistant/snapshots/test_media_player.ambr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@
126126
'media_position': 232,
127127
'media_position_updated_at': datetime.datetime(2024, 10, 30, 18, 31, 49, 565951, tzinfo=datetime.timezone.utc),
128128
'media_title': 'November Rain',
129-
'repeat': 'all',
129+
'repeat': <RepeatMode.ALL: 'all'>,
130130
'shuffle': True,
131131
'supported_features': <MediaPlayerEntityFeature: 8320959>,
132132
'volume_level': 0.06,

0 commit comments

Comments
 (0)