Update pyheos to 0.6.0 (#26191)
This commit is contained in:
1 parent
afab0a9568
commit
677995a05a
11 files changed
+66
-92
No files matched your search
@@ -1,5 +1,5 @@
|
||||
"""Tests for the Heos config flow module."""
|
||||
import asyncio
|
||||
from pyheos import HeosError
|
||||
|
||||
from homeassistant import data_entry_flow
|
||||
from homeassistant.components.heos.config_flow import HeosFlowHandler
|
||||
@@ -31,18 +31,15 @@ async def test_cannot_connect_shows_error_form(hass, controller):
|
||||
"""Test form is shown with error when cannot connect."""
|
||||
flow = HeosFlowHandler()
|
||||
flow.hass = hass
|
||||
|
||||
errors = [ConnectionError, asyncio.TimeoutError]
|
||||
for error in errors:
|
||||
controller.connect.side_effect = error
|
||||
result = await flow.async_step_user({CONF_HOST: "127.0.0.1"})
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
|
||||
assert result["step_id"] == "user"
|
||||
assert result["errors"][CONF_HOST] == "connection_failure"
|
||||
assert controller.connect.call_count == 1
|
||||
assert controller.disconnect.call_count == 1
|
||||
controller.connect.reset_mock()
|
||||
controller.disconnect.reset_mock()
|
||||
controller.connect.side_effect = HeosError()
|
||||
result = await flow.async_step_user({CONF_HOST: "127.0.0.1"})
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
|
||||
assert result["step_id"] == "user"
|
||||
assert result["errors"][CONF_HOST] == "connection_failure"
|
||||
assert controller.connect.call_count == 1
|
||||
assert controller.disconnect.call_count == 1
|
||||
controller.connect.reset_mock()
|
||||
controller.disconnect.reset_mock()
|
||||
|
||||
|
||||
async def test_create_entry_when_host_valid(hass, controller):
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
import asyncio
|
||||
|
||||
from asynctest import Mock, patch
|
||||
from pyheos import CommandError, const
|
||||
from pyheos import CommandFailedError, HeosError, const
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.heos import (
|
||||
@@ -117,31 +117,27 @@ async def test_async_setup_entry_not_signed_in_loads_platforms(
|
||||
async def test_async_setup_entry_connect_failure(hass, config_entry, controller):
|
||||
"""Connection failure raises ConfigEntryNotReady."""
|
||||
config_entry.add_to_hass(hass)
|
||||
errors = [ConnectionError, asyncio.TimeoutError]
|
||||
for error in errors:
|
||||
controller.connect.side_effect = error
|
||||
with pytest.raises(ConfigEntryNotReady):
|
||||
await async_setup_entry(hass, config_entry)
|
||||
await hass.async_block_till_done()
|
||||
assert controller.connect.call_count == 1
|
||||
assert controller.disconnect.call_count == 1
|
||||
controller.connect.reset_mock()
|
||||
controller.disconnect.reset_mock()
|
||||
controller.connect.side_effect = HeosError()
|
||||
with pytest.raises(ConfigEntryNotReady):
|
||||
await async_setup_entry(hass, config_entry)
|
||||
await hass.async_block_till_done()
|
||||
assert controller.connect.call_count == 1
|
||||
assert controller.disconnect.call_count == 1
|
||||
controller.connect.reset_mock()
|
||||
controller.disconnect.reset_mock()
|
||||
|
||||
|
||||
async def test_async_setup_entry_player_failure(hass, config_entry, controller):
|
||||
"""Failure to retrieve players/sources raises ConfigEntryNotReady."""
|
||||
config_entry.add_to_hass(hass)
|
||||
errors = [ConnectionError, asyncio.TimeoutError]
|
||||
for error in errors:
|
||||
controller.get_players.side_effect = error
|
||||
with pytest.raises(ConfigEntryNotReady):
|
||||
await async_setup_entry(hass, config_entry)
|
||||
await hass.async_block_till_done()
|
||||
assert controller.connect.call_count == 1
|
||||
assert controller.disconnect.call_count == 1
|
||||
controller.connect.reset_mock()
|
||||
controller.disconnect.reset_mock()
|
||||
controller.get_players.side_effect = HeosError()
|
||||
with pytest.raises(ConfigEntryNotReady):
|
||||
await async_setup_entry(hass, config_entry)
|
||||
await hass.async_block_till_done()
|
||||
assert controller.connect.call_count == 1
|
||||
assert controller.disconnect.call_count == 1
|
||||
controller.connect.reset_mock()
|
||||
controller.disconnect.reset_mock()
|
||||
|
||||
|
||||
async def test_unload_entry(hass, config_entry, controller):
|
||||
@@ -167,7 +163,7 @@ async def test_update_sources_retry(hass, config_entry, config, controller, capl
|
||||
source_manager = hass.data[DOMAIN][DATA_SOURCE_MANAGER]
|
||||
source_manager.retry_delay = 0
|
||||
source_manager.max_retry_attempts = 1
|
||||
controller.get_favorites.side_effect = CommandError("Test", "test", 0)
|
||||
controller.get_favorites.side_effect = CommandFailedError("Test", "test", 0)
|
||||
controller.dispatcher.send(
|
||||
const.SIGNAL_CONTROLLER_EVENT, const.EVENT_SOURCES_CHANGED, {}
|
||||
)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"""Tests for the Heos Media Player platform."""
|
||||
import asyncio
|
||||
|
||||
from pyheos import CommandError, const
|
||||
from pyheos import CommandFailedError, const
|
||||
|
||||
from homeassistant.components.heos import media_player
|
||||
from homeassistant.components.heos.const import (
|
||||
@@ -179,7 +179,7 @@ async def test_updates_from_connection_event(
|
||||
event.clear()
|
||||
player.reset_mock()
|
||||
controller.load_players.reset_mock()
|
||||
controller.load_players.side_effect = CommandError(None, "Failure", 1)
|
||||
controller.load_players.side_effect = CommandFailedError(None, "Failure", 1)
|
||||
player.available = True
|
||||
player.heos.dispatcher.send(const.SIGNAL_HEOS_EVENT, const.EVENT_CONNECTED)
|
||||
await event.wait()
|
||||
@@ -313,7 +313,7 @@ async def test_clear_playlist(hass, config_entry, config, controller, caplog):
|
||||
)
|
||||
assert player.clear_queue.call_count == 1
|
||||
player.clear_queue.reset_mock()
|
||||
player.clear_queue.side_effect = CommandError(None, "Failure", 1)
|
||||
player.clear_queue.side_effect = CommandFailedError(None, "Failure", 1)
|
||||
assert "Unable to clear playlist: Failure (1)" in caplog.text
|
||||
|
||||
|
||||
@@ -331,7 +331,7 @@ async def test_pause(hass, config_entry, config, controller, caplog):
|
||||
)
|
||||
assert player.pause.call_count == 1
|
||||
player.pause.reset_mock()
|
||||
player.pause.side_effect = CommandError(None, "Failure", 1)
|
||||
player.pause.side_effect = CommandFailedError(None, "Failure", 1)
|
||||
assert "Unable to pause: Failure (1)" in caplog.text
|
||||
|
||||
|
||||
@@ -349,7 +349,7 @@ async def test_play(hass, config_entry, config, controller, caplog):
|
||||
)
|
||||
assert player.play.call_count == 1
|
||||
player.play.reset_mock()
|
||||
player.play.side_effect = CommandError(None, "Failure", 1)
|
||||
player.play.side_effect = CommandFailedError(None, "Failure", 1)
|
||||
assert "Unable to play: Failure (1)" in caplog.text
|
||||
|
||||
|
||||
@@ -367,7 +367,7 @@ async def test_previous_track(hass, config_entry, config, controller, caplog):
|
||||
)
|
||||
assert player.play_previous.call_count == 1
|
||||
player.play_previous.reset_mock()
|
||||
player.play_previous.side_effect = CommandError(None, "Failure", 1)
|
||||
player.play_previous.side_effect = CommandFailedError(None, "Failure", 1)
|
||||
assert "Unable to move to previous track: Failure (1)" in caplog.text
|
||||
|
||||
|
||||
@@ -385,7 +385,7 @@ async def test_next_track(hass, config_entry, config, controller, caplog):
|
||||
)
|
||||
assert player.play_next.call_count == 1
|
||||
player.play_next.reset_mock()
|
||||
player.play_next.side_effect = CommandError(None, "Failure", 1)
|
||||
player.play_next.side_effect = CommandFailedError(None, "Failure", 1)
|
||||
assert "Unable to move to next track: Failure (1)" in caplog.text
|
||||
|
||||
|
||||
@@ -403,7 +403,7 @@ async def test_stop(hass, config_entry, config, controller, caplog):
|
||||
)
|
||||
assert player.stop.call_count == 1
|
||||
player.stop.reset_mock()
|
||||
player.stop.side_effect = CommandError(None, "Failure", 1)
|
||||
player.stop.side_effect = CommandFailedError(None, "Failure", 1)
|
||||
assert "Unable to stop: Failure (1)" in caplog.text
|
||||
|
||||
|
||||
@@ -421,7 +421,7 @@ async def test_volume_mute(hass, config_entry, config, controller, caplog):
|
||||
)
|
||||
assert player.set_mute.call_count == 1
|
||||
player.set_mute.reset_mock()
|
||||
player.set_mute.side_effect = CommandError(None, "Failure", 1)
|
||||
player.set_mute.side_effect = CommandFailedError(None, "Failure", 1)
|
||||
assert "Unable to set mute: Failure (1)" in caplog.text
|
||||
|
||||
|
||||
@@ -439,7 +439,7 @@ async def test_shuffle_set(hass, config_entry, config, controller, caplog):
|
||||
)
|
||||
player.set_play_mode.assert_called_once_with(player.repeat, True)
|
||||
player.set_play_mode.reset_mock()
|
||||
player.set_play_mode.side_effect = CommandError(None, "Failure", 1)
|
||||
player.set_play_mode.side_effect = CommandFailedError(None, "Failure", 1)
|
||||
assert "Unable to set shuffle: Failure (1)" in caplog.text
|
||||
|
||||
|
||||
@@ -457,7 +457,7 @@ async def test_volume_set(hass, config_entry, config, controller, caplog):
|
||||
)
|
||||
player.set_volume.assert_called_once_with(100)
|
||||
player.set_volume.reset_mock()
|
||||
player.set_volume.side_effect = CommandError(None, "Failure", 1)
|
||||
player.set_volume.side_effect = CommandFailedError(None, "Failure", 1)
|
||||
assert "Unable to set volume level: Failure (1)" in caplog.text
|
||||
|
||||
|
||||
@@ -516,7 +516,7 @@ async def test_select_radio_favorite_command_error(
|
||||
player = controller.players[1]
|
||||
# Test set radio preset
|
||||
favorite = favorites[2]
|
||||
player.play_favorite.side_effect = CommandError(None, "Failure", 1)
|
||||
player.play_favorite.side_effect = CommandFailedError(None, "Failure", 1)
|
||||
await hass.services.async_call(
|
||||
MEDIA_PLAYER_DOMAIN,
|
||||
SERVICE_SELECT_SOURCE,
|
||||
@@ -575,7 +575,7 @@ async def test_select_input_command_error(
|
||||
await setup_platform(hass, config_entry, config)
|
||||
player = controller.players[1]
|
||||
input_source = input_sources[0]
|
||||
player.play_input_source.side_effect = CommandError(None, "Failure", 1)
|
||||
player.play_input_source.side_effect = CommandFailedError(None, "Failure", 1)
|
||||
await hass.services.async_call(
|
||||
MEDIA_PLAYER_DOMAIN,
|
||||
SERVICE_SELECT_SOURCE,
|
||||
@@ -615,7 +615,7 @@ async def test_play_media_url(hass, config_entry, config, controller, caplog):
|
||||
)
|
||||
player.play_url.assert_called_once_with(url)
|
||||
player.play_url.reset_mock()
|
||||
player.play_url.side_effect = CommandError(None, "Failure", 1)
|
||||
player.play_url.side_effect = CommandFailedError(None, "Failure", 1)
|
||||
assert "Unable to play media: Failure (1)" in caplog.text
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
"""Tests for the services module."""
|
||||
from pyheos import CommandError, const
|
||||
from pyheos import CommandFailedError, HeosError, const
|
||||
|
||||
from homeassistant.components.heos.const import (
|
||||
ATTR_PASSWORD,
|
||||
@@ -51,7 +51,7 @@ async def test_sign_in_not_connected(hass, config_entry, controller, caplog):
|
||||
async def test_sign_in_failed(hass, config_entry, controller, caplog):
|
||||
"""Test sign-in service logs error when not connected."""
|
||||
await setup_component(hass, config_entry)
|
||||
controller.sign_in.side_effect = CommandError("", "Invalid credentials", 6)
|
||||
controller.sign_in.side_effect = CommandFailedError("", "Invalid credentials", 6)
|
||||
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
@@ -67,7 +67,7 @@ async def test_sign_in_failed(hass, config_entry, controller, caplog):
|
||||
async def test_sign_in_unknown_error(hass, config_entry, controller, caplog):
|
||||
"""Test sign-in service logs error for failure."""
|
||||
await setup_component(hass, config_entry)
|
||||
controller.sign_in.side_effect = ConnectionError
|
||||
controller.sign_in.side_effect = HeosError()
|
||||
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
@@ -103,7 +103,7 @@ async def test_sign_out_not_connected(hass, config_entry, controller, caplog):
|
||||
async def test_sign_out_unknown_error(hass, config_entry, controller, caplog):
|
||||
"""Test the sign-out service."""
|
||||
await setup_component(hass, config_entry)
|
||||
controller.sign_out.side_effect = ConnectionError
|
||||
controller.sign_out.side_effect = HeosError()
|
||||
|
||||
await hass.services.async_call(DOMAIN, SERVICE_SIGN_OUT, {}, blocking=True)
|
||||
|
||||
|
||||
Reference in new issue
Block a user