Skip to content

Commit 08f6220

Browse files
committed
Add aliases for changed fields
1 parent ddab707 commit 08f6220

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

music_assistant_models/player.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,8 @@ def current_item_id(self) -> str | None:
179179
return self.current_media.queue_item_id or self.current_media.uri
180180
return None
181181

182-
def __post_serialize__(self, d: dict[str, Any]) -> dict[str, Any]:
182+
@classmethod
183+
def __post_serialize__(cls, d: dict[str, Any]) -> dict[str, Any]:
183184
"""Adjust dict object after it has been serialized."""
184185
# TEMP 2025-03-15: convert power to boolean for backwards compatibility
185186
# Remove this once the HA integration is updated to handle this
@@ -194,3 +195,20 @@ def __post_serialize__(self, d: dict[str, Any]) -> dict[str, Any]:
194195
# add alias for extra_data for backwards compatibility
195196
d["extra_data"] = d["extra_attributes"]
196197
return d
198+
199+
@classmethod
200+
def __pre_deserialize__(cls, d: dict[Any, Any]) -> dict[Any, Any]:
201+
"""Adjust object before it will be deserialized."""
202+
# add alias for playback_state for backwards compatibility
203+
if "playback_state" not in d and "state" in d:
204+
d["playback_state"] = d["state"]
205+
# add alias for name for backwards compatibility
206+
if "name" not in d and "display_name" in d:
207+
d["name"] = d["display_name"]
208+
# add alias for group_members for backwards compatibility
209+
if "group_members" not in d and "group_childs" in d:
210+
d["group_members"] = d["group_childs"]
211+
# add alias for extra_attributes for backwards compatibility
212+
if "extra_attributes" not in d and "extra_data" in d:
213+
d["extra_attributes"] = d["extra_data"]
214+
return d

0 commit comments

Comments
 (0)