Skip to content

Commit

Permalink
Cleanup add browse media forked daapd home-assistant#79009 (home-assi…
Browse files Browse the repository at this point in the history
  • Loading branch information
uvjustin authored Sep 27, 2022
1 parent 5eb50f6 commit b043a6b
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 19 deletions.
12 changes: 5 additions & 7 deletions homeassistant/components/forked_daapd/browse_media.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,11 @@
}
MEDIA_TYPE_TO_OWNTONE_TYPE = {v: k for k, v in OWNTONE_TYPE_TO_MEDIA_TYPE.items()}

"""
media_content_id is a uri in the form of SCHEMA:Title:OwnToneURI:Subtype (Subtype only used for Genre)
OwnToneURI is in format library:type:id (for directories, id is path)
media_content_type - type of item (mostly used to check if playable or can expand)
Owntone type may differ from media_content_type when media_content_type is a directory
Owntown type is used in our own branching, but media_content_type is used for determining playability
"""
# media_content_id is a uri in the form of SCHEMA:Title:OwnToneURI:Subtype (Subtype only used for Genre)
# OwnToneURI is in format library:type:id (for directories, id is path)
# media_content_type - type of item (mostly used to check if playable or can expand)
# Owntone type may differ from media_content_type when media_content_type is a directory
# Owntone type is used in our own branching, but media_content_type is used for determining playability


@dataclass
Expand Down
2 changes: 0 additions & 2 deletions homeassistant/components/forked_daapd/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -840,8 +840,6 @@ async def async_browse_media(
# This is the base level, so we combine our library with the media source
return library(ms_result.children)
return ms_result
# media_content_type should only be None if media_content_id is None
assert media_content_type
return await get_owntone_content(self, media_content_id)

async def async_get_browse_image(
Expand Down
13 changes: 6 additions & 7 deletions tests/components/forked_daapd/test_browse_media.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ async def test_async_browse_media(hass, hass_ws_client, config_entry):
autospec=True,
) as mock_api:
config_entry.add_to_hass(hass)
await config_entry.async_setup(hass)
await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done()

mock_api.return_value.full_url = lambda x: "http://owntone_instance/" + x
Expand Down Expand Up @@ -126,7 +126,7 @@ async def test_async_browse_media(hass, hass_ws_client, config_entry):
},
]

# Request playlist through WebSocket
# Request browse root through WebSocket
client = await hass_ws_client(hass)
await client.send_json(
{
Expand All @@ -148,7 +148,6 @@ async def browse_children(children):
nonlocal msg_id
for child in children:
if child["can_expand"]:
print("EXPANDING CHILD", child)
await client.send_json(
{
"id": msg_id,
Expand Down Expand Up @@ -177,7 +176,7 @@ async def test_async_browse_media_not_found(hass, hass_ws_client, config_entry):
autospec=True,
) as mock_api:
config_entry.add_to_hass(hass)
await config_entry.async_setup(hass)
await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done()

mock_api.return_value.get_directory.return_value = None
Expand All @@ -186,7 +185,7 @@ async def test_async_browse_media_not_found(hass, hass_ws_client, config_entry):
mock_api.return_value.get_genres.return_value = None
mock_api.return_value.get_playlists.return_value = None

# Request playlist through WebSocket
# Request different types of media through WebSocket
client = await hass_ws_client(hass)
msg_id = 1
for media_type in (
Expand Down Expand Up @@ -229,7 +228,7 @@ async def test_async_browse_image(hass, hass_client, config_entry):
autospec=True,
) as mock_api:
config_entry.add_to_hass(hass)
await config_entry.async_setup(hass)
await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done()
client = await hass_client()
mock_api.return_value.full_url = lambda x: "http://owntone_instance/" + x
Expand Down Expand Up @@ -279,7 +278,7 @@ async def test_async_browse_image_missing(hass, hass_client, config_entry, caplo
autospec=True,
) as mock_api:
config_entry.add_to_hass(hass)
await config_entry.async_setup(hass)
await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done()
client = await hass_client()
mock_api.return_value.full_url = lambda x: "http://owntone_instance/" + x
Expand Down
2 changes: 1 addition & 1 deletion tests/components/forked_daapd/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ async def test_options_flow(hass, config_entry):
) as mock_get_request:
mock_get_request.return_value = SAMPLE_CONFIG
config_entry.add_to_hass(hass)
await config_entry.async_setup(hass)
await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done()

result = await hass.config_entries.options.async_init(config_entry.entry_id)
Expand Down
4 changes: 2 additions & 2 deletions tests/components/forked_daapd/test_media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ async def get_request_side_effect(update_type):
mock_api.return_value.get_pipes.return_value = SAMPLE_PIPES
mock_api.return_value.get_playlists.return_value = SAMPLE_PLAYLISTS
config_entry.add_to_hass(hass)
await config_entry.async_setup(hass)
await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done()

mock_api.return_value.start_websocket_handler.assert_called_once()
Expand Down Expand Up @@ -775,7 +775,7 @@ async def test_invalid_websocket_port(hass, config_entry):
) as mock_api:
mock_api.return_value.get_request.return_value = SAMPLE_CONFIG_NO_WEBSOCKET
config_entry.add_to_hass(hass)
await config_entry.async_setup(hass)
await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done()
assert hass.states.get(TEST_MASTER_ENTITY_NAME).state == STATE_UNAVAILABLE

Expand Down

0 comments on commit b043a6b

Please sign in to comment.