mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 08:47:57 +00:00
Handle None received from pyforked-daapd (#35830)
* Handle None received from API in forked-daapd * Bump pyforked-daapd version in requirements * Add test
This commit is contained in:
parent
53a9d39a81
commit
b3459d9190
@ -3,7 +3,7 @@
|
||||
"name": "forked-daapd",
|
||||
"documentation": "https://www.home-assistant.io/integrations/forked-daapd",
|
||||
"codeowners": ["@uvjustin"],
|
||||
"requirements": ["pyforked-daapd==0.1.8", "pylibrespot-java==0.1.0"],
|
||||
"requirements": ["pyforked-daapd==0.1.9", "pylibrespot-java==0.1.0"],
|
||||
"config_flow": true,
|
||||
"zeroconf": ["_daap._tcp.local."]
|
||||
}
|
||||
|
@ -794,26 +794,29 @@ class ForkedDaapdUpdater:
|
||||
"queue" in update_types
|
||||
): # update queue, queue before player for async_play_media
|
||||
queue = await self._api.get_request("queue")
|
||||
update_events["queue"] = asyncio.Event()
|
||||
async_dispatcher_send(
|
||||
self.hass,
|
||||
SIGNAL_UPDATE_QUEUE.format(self._entry_id),
|
||||
queue,
|
||||
update_events["queue"],
|
||||
)
|
||||
if queue:
|
||||
update_events["queue"] = asyncio.Event()
|
||||
async_dispatcher_send(
|
||||
self.hass,
|
||||
SIGNAL_UPDATE_QUEUE.format(self._entry_id),
|
||||
queue,
|
||||
update_events["queue"],
|
||||
)
|
||||
# order of below don't matter
|
||||
if not {"outputs", "volume"}.isdisjoint(update_types): # update outputs
|
||||
outputs = (await self._api.get_request("outputs"))["outputs"]
|
||||
update_events[
|
||||
"outputs"
|
||||
] = asyncio.Event() # only for master, zones should ignore
|
||||
async_dispatcher_send(
|
||||
self.hass,
|
||||
SIGNAL_UPDATE_OUTPUTS.format(self._entry_id),
|
||||
outputs,
|
||||
update_events["outputs"],
|
||||
)
|
||||
self._add_zones(outputs)
|
||||
outputs = await self._api.get_request("outputs")
|
||||
if outputs:
|
||||
outputs = outputs["outputs"]
|
||||
update_events[
|
||||
"outputs"
|
||||
] = asyncio.Event() # only for master, zones should ignore
|
||||
async_dispatcher_send(
|
||||
self.hass,
|
||||
SIGNAL_UPDATE_OUTPUTS.format(self._entry_id),
|
||||
outputs,
|
||||
update_events["outputs"],
|
||||
)
|
||||
self._add_zones(outputs)
|
||||
if not {"database"}.isdisjoint(update_types):
|
||||
pipes, playlists = await asyncio.gather(
|
||||
self._api.get_pipes(), self._api.get_playlists()
|
||||
@ -832,17 +835,18 @@ class ForkedDaapdUpdater:
|
||||
update_types
|
||||
): # update player
|
||||
player = await self._api.get_request("player")
|
||||
update_events["player"] = asyncio.Event()
|
||||
if update_events.get("queue"):
|
||||
await update_events[
|
||||
"queue"
|
||||
].wait() # make sure queue done before player for async_play_media
|
||||
async_dispatcher_send(
|
||||
self.hass,
|
||||
SIGNAL_UPDATE_PLAYER.format(self._entry_id),
|
||||
player,
|
||||
update_events["player"],
|
||||
)
|
||||
if player:
|
||||
update_events["player"] = asyncio.Event()
|
||||
if update_events.get("queue"):
|
||||
await update_events[
|
||||
"queue"
|
||||
].wait() # make sure queue done before player for async_play_media
|
||||
async_dispatcher_send(
|
||||
self.hass,
|
||||
SIGNAL_UPDATE_PLAYER.format(self._entry_id),
|
||||
player,
|
||||
update_events["player"],
|
||||
)
|
||||
if update_events:
|
||||
await asyncio.wait(
|
||||
[event.wait() for event in update_events.values()]
|
||||
|
@ -1332,7 +1332,7 @@ pyflunearyou==1.0.7
|
||||
pyfnip==0.2
|
||||
|
||||
# homeassistant.components.forked_daapd
|
||||
pyforked-daapd==0.1.8
|
||||
pyforked-daapd==0.1.9
|
||||
|
||||
# homeassistant.components.fritzbox
|
||||
pyfritzhome==0.4.2
|
||||
|
@ -560,7 +560,7 @@ pyflume==0.4.0
|
||||
pyflunearyou==1.0.7
|
||||
|
||||
# homeassistant.components.forked_daapd
|
||||
pyforked-daapd==0.1.8
|
||||
pyforked-daapd==0.1.9
|
||||
|
||||
# homeassistant.components.fritzbox
|
||||
pyfritzhome==0.4.2
|
||||
|
@ -8,6 +8,9 @@ from homeassistant.components.forked_daapd.const import (
|
||||
CONF_TTS_PAUSE_TIME,
|
||||
CONF_TTS_VOLUME,
|
||||
DOMAIN,
|
||||
SIGNAL_UPDATE_OUTPUTS,
|
||||
SIGNAL_UPDATE_PLAYER,
|
||||
SIGNAL_UPDATE_QUEUE,
|
||||
SOURCE_NAME_CLEAR,
|
||||
SOURCE_NAME_DEFAULT,
|
||||
SUPPORTED_FEATURES,
|
||||
@ -63,7 +66,7 @@ from homeassistant.const import (
|
||||
)
|
||||
|
||||
from tests.async_mock import patch
|
||||
from tests.common import MockConfigEntry
|
||||
from tests.common import MockConfigEntry, async_mock_signal
|
||||
|
||||
TEST_MASTER_ENTITY_NAME = "media_player.forked_daapd_server"
|
||||
TEST_ZONE_ENTITY_NAMES = [
|
||||
@ -369,6 +372,32 @@ def test_master_state(hass, mock_api_object):
|
||||
assert not state.attributes[ATTR_MEDIA_SHUFFLE]
|
||||
|
||||
|
||||
async def test_no_update_when_get_request_returns_none(
|
||||
hass, config_entry, mock_api_object
|
||||
):
|
||||
"""Test when get request returns None."""
|
||||
|
||||
async def get_request_side_effect(update_type):
|
||||
return None
|
||||
|
||||
mock_api_object.get_request.side_effect = get_request_side_effect
|
||||
updater_update = mock_api_object.start_websocket_handler.call_args[0][2]
|
||||
signal_output_call = async_mock_signal(
|
||||
hass, SIGNAL_UPDATE_OUTPUTS.format(config_entry.entry_id)
|
||||
)
|
||||
signal_player_call = async_mock_signal(
|
||||
hass, SIGNAL_UPDATE_PLAYER.format(config_entry.entry_id)
|
||||
)
|
||||
signal_queue_call = async_mock_signal(
|
||||
hass, SIGNAL_UPDATE_QUEUE.format(config_entry.entry_id)
|
||||
)
|
||||
await updater_update(["outputs", "player", "queue"])
|
||||
await hass.async_block_till_done()
|
||||
assert len(signal_output_call) == 0
|
||||
assert len(signal_player_call) == 0
|
||||
assert len(signal_queue_call) == 0
|
||||
|
||||
|
||||
async def _service_call(
|
||||
hass, entity_name, service, additional_service_data=None, blocking=True
|
||||
):
|
||||
|
Loading…
x
Reference in New Issue
Block a user