Replace more addon management with aiohasupervisor (#126236)

* Replace start_addon with library call

* restart_addon to library and error issues in tests

* stop_addon to library

* uninstall_addon to library

* Add output typing

Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>

---------

Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
This commit is contained in:
Mike Degatano 2024-09-24 09:47:29 -04:00 committed by GitHub
parent 2fa7113787
commit 7517948900
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
14 changed files with 106 additions and 215 deletions

View File

@ -107,13 +107,9 @@ from .handler import ( # noqa: F401
async_get_yellow_settings, async_get_yellow_settings,
async_install_addon, async_install_addon,
async_reboot_host, async_reboot_host,
async_restart_addon,
async_set_addon_options, async_set_addon_options,
async_set_green_settings, async_set_green_settings,
async_set_yellow_settings, async_set_yellow_settings,
async_start_addon,
async_stop_addon,
async_uninstall_addon,
async_update_addon, async_update_addon,
async_update_core, async_update_core,
async_update_diagnostics, async_update_diagnostics,

View File

@ -25,11 +25,7 @@ from .handler import (
async_get_addon_discovery_info, async_get_addon_discovery_info,
async_get_addon_store_info, async_get_addon_store_info,
async_install_addon, async_install_addon,
async_restart_addon,
async_set_addon_options, async_set_addon_options,
async_start_addon,
async_stop_addon,
async_uninstall_addon,
async_update_addon, async_update_addon,
get_supervisor_client, get_supervisor_client,
) )
@ -208,7 +204,7 @@ class AddonManager:
@api_error("Failed to uninstall the {addon_name} add-on") @api_error("Failed to uninstall the {addon_name} add-on")
async def async_uninstall_addon(self) -> None: async def async_uninstall_addon(self) -> None:
"""Uninstall the managed add-on.""" """Uninstall the managed add-on."""
await async_uninstall_addon(self._hass, self.addon_slug) await get_supervisor_client(self._hass).addons.uninstall_addon(self.addon_slug)
@api_error("Failed to update the {addon_name} add-on") @api_error("Failed to update the {addon_name} add-on")
async def async_update_addon(self) -> None: async def async_update_addon(self) -> None:
@ -229,17 +225,17 @@ class AddonManager:
@api_error("Failed to start the {addon_name} add-on") @api_error("Failed to start the {addon_name} add-on")
async def async_start_addon(self) -> None: async def async_start_addon(self) -> None:
"""Start the managed add-on.""" """Start the managed add-on."""
await async_start_addon(self._hass, self.addon_slug) await get_supervisor_client(self._hass).addons.start_addon(self.addon_slug)
@api_error("Failed to restart the {addon_name} add-on") @api_error("Failed to restart the {addon_name} add-on")
async def async_restart_addon(self) -> None: async def async_restart_addon(self) -> None:
"""Restart the managed add-on.""" """Restart the managed add-on."""
await async_restart_addon(self._hass, self.addon_slug) await get_supervisor_client(self._hass).addons.restart_addon(self.addon_slug)
@api_error("Failed to stop the {addon_name} add-on") @api_error("Failed to stop the {addon_name} add-on")
async def async_stop_addon(self) -> None: async def async_stop_addon(self) -> None:
"""Stop the managed add-on.""" """Stop the managed add-on."""
await async_stop_addon(self._hass, self.addon_slug) await get_supervisor_client(self._hass).addons.stop_addon(self.addon_slug)
@api_error("Failed to create a backup of the {addon_name} add-on") @api_error("Failed to create a backup of the {addon_name} add-on")
async def async_create_backup(self) -> None: async def async_create_backup(self) -> None:

View File

@ -96,18 +96,6 @@ async def async_install_addon(hass: HomeAssistant, slug: str) -> dict:
return await hassio.send_command(command, timeout=None) return await hassio.send_command(command, timeout=None)
@bind_hass
@api_data
async def async_uninstall_addon(hass: HomeAssistant, slug: str) -> dict:
"""Uninstall add-on.
The caller of the function should handle HassioAPIError.
"""
hassio: HassIO = hass.data[DOMAIN]
command = f"/addons/{slug}/uninstall"
return await hassio.send_command(command, timeout=60)
@bind_hass @bind_hass
@api_data @api_data
async def async_update_addon( async def async_update_addon(
@ -128,42 +116,6 @@ async def async_update_addon(
) )
@bind_hass
@api_data
async def async_start_addon(hass: HomeAssistant, slug: str) -> dict:
"""Start add-on.
The caller of the function should handle HassioAPIError.
"""
hassio: HassIO = hass.data[DOMAIN]
command = f"/addons/{slug}/start"
return await hassio.send_command(command, timeout=60)
@bind_hass
@api_data
async def async_restart_addon(hass: HomeAssistant, slug: str) -> dict:
"""Restart add-on.
The caller of the function should handle HassioAPIError.
"""
hassio: HassIO = hass.data[DOMAIN]
command = f"/addons/{slug}/restart"
return await hassio.send_command(command, timeout=None)
@bind_hass
@api_data
async def async_stop_addon(hass: HomeAssistant, slug: str) -> dict:
"""Stop add-on.
The caller of the function should handle HassioAPIError.
"""
hassio: HassIO = hass.data[DOMAIN]
command = f"/addons/{slug}/stop"
return await hassio.send_command(command, timeout=60)
@bind_hass @bind_hass
@api_data @api_data
async def async_set_addon_options( async def async_set_addon_options(

View File

@ -321,12 +321,12 @@ def start_addon_side_effect_fixture(
@pytest.fixture(name="start_addon") @pytest.fixture(name="start_addon")
def start_addon_fixture(start_addon_side_effect: Any | None) -> Generator[AsyncMock]: def start_addon_fixture(
supervisor_client: AsyncMock, start_addon_side_effect: Any | None
) -> AsyncMock:
"""Mock start add-on.""" """Mock start add-on."""
# pylint: disable-next=import-outside-toplevel supervisor_client.addons.start_addon.side_effect = start_addon_side_effect
from .hassio.common import mock_start_addon return supervisor_client.addons.start_addon
yield from mock_start_addon(start_addon_side_effect)
@pytest.fixture(name="restart_addon_side_effect") @pytest.fixture(name="restart_addon_side_effect")
@ -337,22 +337,18 @@ def restart_addon_side_effect_fixture() -> Any | None:
@pytest.fixture(name="restart_addon") @pytest.fixture(name="restart_addon")
def restart_addon_fixture( def restart_addon_fixture(
supervisor_client: AsyncMock,
restart_addon_side_effect: Any | None, restart_addon_side_effect: Any | None,
) -> Generator[AsyncMock]: ) -> AsyncMock:
"""Mock restart add-on.""" """Mock restart add-on."""
# pylint: disable-next=import-outside-toplevel supervisor_client.addons.restart_addon.side_effect = restart_addon_side_effect
from .hassio.common import mock_restart_addon return supervisor_client.addons.restart_addon
yield from mock_restart_addon(restart_addon_side_effect)
@pytest.fixture(name="stop_addon") @pytest.fixture(name="stop_addon")
def stop_addon_fixture() -> Generator[AsyncMock]: def stop_addon_fixture(supervisor_client: AsyncMock) -> AsyncMock:
"""Mock stop add-on.""" """Mock stop add-on."""
# pylint: disable-next=import-outside-toplevel return supervisor_client.addons.stop_addon
from .hassio.common import mock_stop_addon
yield from mock_stop_addon()
@pytest.fixture(name="addon_options") @pytest.fixture(name="addon_options")
@ -387,12 +383,9 @@ def set_addon_options_fixture(
@pytest.fixture(name="uninstall_addon") @pytest.fixture(name="uninstall_addon")
def uninstall_addon_fixture() -> Generator[AsyncMock]: def uninstall_addon_fixture(supervisor_client: AsyncMock) -> AsyncMock:
"""Mock uninstall add-on.""" """Mock uninstall add-on."""
# pylint: disable-next=import-outside-toplevel return supervisor_client.addons.uninstall_addon
from .hassio.common import mock_uninstall_addon
yield from mock_uninstall_addon()
@pytest.fixture(name="create_backup") @pytest.fixture(name="create_backup")

View File

@ -166,7 +166,7 @@ def mock_start_addon_side_effect(
) -> Any | None: ) -> Any | None:
"""Return the start add-on options side effect.""" """Return the start add-on options side effect."""
async def start_addon(hass: HomeAssistant, slug): async def start_addon(addon: str) -> None:
"""Mock start add-on.""" """Mock start add-on."""
addon_store_info.return_value = { addon_store_info.return_value = {
"available": True, "available": True,
@ -180,40 +180,6 @@ def mock_start_addon_side_effect(
return start_addon return start_addon
def mock_start_addon(start_addon_side_effect: Any | None) -> Generator[AsyncMock]:
"""Mock start add-on."""
with patch(
"homeassistant.components.hassio.addon_manager.async_start_addon",
side_effect=start_addon_side_effect,
) as start_addon:
yield start_addon
def mock_stop_addon() -> Generator[AsyncMock]:
"""Mock stop add-on."""
with patch(
"homeassistant.components.hassio.addon_manager.async_stop_addon"
) as stop_addon:
yield stop_addon
def mock_restart_addon(restart_addon_side_effect: Any | None) -> Generator[AsyncMock]:
"""Mock restart add-on."""
with patch(
"homeassistant.components.hassio.addon_manager.async_restart_addon",
side_effect=restart_addon_side_effect,
) as restart_addon:
yield restart_addon
def mock_uninstall_addon() -> Generator[AsyncMock]:
"""Mock uninstall add-on."""
with patch(
"homeassistant.components.hassio.addon_manager.async_uninstall_addon"
) as uninstall_addon:
yield uninstall_addon
def mock_addon_options(addon_info: AsyncMock) -> dict[str, Any]: def mock_addon_options(addon_info: AsyncMock) -> dict[str, Any]:
"""Mock add-on options.""" """Mock add-on options."""
return addon_info.return_value.options return addon_info.return_value.options

View File

@ -6,6 +6,7 @@ import asyncio
from typing import Any from typing import Any
from unittest.mock import AsyncMock, call from unittest.mock import AsyncMock, call
from aiohasupervisor import SupervisorError
import pytest import pytest
from homeassistant.components.hassio.addon_manager import ( from homeassistant.components.hassio.addon_manager import (
@ -136,7 +137,7 @@ async def test_get_addon_info(
"addon_store_info_error", "addon_store_info_error",
"addon_store_info_calls", "addon_store_info_calls",
), ),
[(HassioAPIError("Boom"), 1, None, 1), (None, 0, HassioAPIError("Boom"), 1)], [(SupervisorError("Boom"), 1, None, 1), (None, 0, HassioAPIError("Boom"), 1)],
) )
async def test_get_addon_info_error( async def test_get_addon_info_error(
addon_manager: AddonManager, addon_manager: AddonManager,
@ -303,7 +304,7 @@ async def test_uninstall_addon_error(
addon_manager: AddonManager, uninstall_addon: AsyncMock addon_manager: AddonManager, uninstall_addon: AsyncMock
) -> None: ) -> None:
"""Test uninstall addon raises error.""" """Test uninstall addon raises error."""
uninstall_addon.side_effect = HassioAPIError("Boom") uninstall_addon.side_effect = SupervisorError("Boom")
with pytest.raises(AddonError) as err: with pytest.raises(AddonError) as err:
await addon_manager.async_uninstall_addon() await addon_manager.async_uninstall_addon()
@ -324,7 +325,7 @@ async def test_start_addon_error(
addon_manager: AddonManager, start_addon: AsyncMock addon_manager: AddonManager, start_addon: AsyncMock
) -> None: ) -> None:
"""Test start addon raises error.""" """Test start addon raises error."""
start_addon.side_effect = HassioAPIError("Boom") start_addon.side_effect = SupervisorError("Boom")
with pytest.raises(AddonError) as err: with pytest.raises(AddonError) as err:
await addon_manager.async_start_addon() await addon_manager.async_start_addon()
@ -366,7 +367,7 @@ async def test_schedule_start_addon_error(
start_addon: AsyncMock, start_addon: AsyncMock,
) -> None: ) -> None:
"""Test schedule start addon raises error.""" """Test schedule start addon raises error."""
start_addon.side_effect = HassioAPIError("Boom") start_addon.side_effect = SupervisorError("Boom")
with pytest.raises(AddonError) as err: with pytest.raises(AddonError) as err:
await addon_manager.async_schedule_start_addon() await addon_manager.async_schedule_start_addon()
@ -383,7 +384,7 @@ async def test_schedule_start_addon_logs_error(
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test schedule start addon logs error.""" """Test schedule start addon logs error."""
start_addon.side_effect = HassioAPIError("Boom") start_addon.side_effect = SupervisorError("Boom")
await addon_manager.async_schedule_start_addon(catch_error=True) await addon_manager.async_schedule_start_addon(catch_error=True)
@ -404,7 +405,7 @@ async def test_restart_addon_error(
addon_manager: AddonManager, restart_addon: AsyncMock addon_manager: AddonManager, restart_addon: AsyncMock
) -> None: ) -> None:
"""Test restart addon raises error.""" """Test restart addon raises error."""
restart_addon.side_effect = HassioAPIError("Boom") restart_addon.side_effect = SupervisorError("Boom")
with pytest.raises(AddonError) as err: with pytest.raises(AddonError) as err:
await addon_manager.async_restart_addon() await addon_manager.async_restart_addon()
@ -446,7 +447,7 @@ async def test_schedule_restart_addon_error(
restart_addon: AsyncMock, restart_addon: AsyncMock,
) -> None: ) -> None:
"""Test schedule restart addon raises error.""" """Test schedule restart addon raises error."""
restart_addon.side_effect = HassioAPIError("Boom") restart_addon.side_effect = SupervisorError("Boom")
with pytest.raises(AddonError) as err: with pytest.raises(AddonError) as err:
await addon_manager.async_schedule_restart_addon() await addon_manager.async_schedule_restart_addon()
@ -463,7 +464,7 @@ async def test_schedule_restart_addon_logs_error(
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test schedule restart addon logs error.""" """Test schedule restart addon logs error."""
restart_addon.side_effect = HassioAPIError("Boom") restart_addon.side_effect = SupervisorError("Boom")
await addon_manager.async_schedule_restart_addon(catch_error=True) await addon_manager.async_schedule_restart_addon(catch_error=True)
@ -482,7 +483,7 @@ async def test_stop_addon_error(
addon_manager: AddonManager, stop_addon: AsyncMock addon_manager: AddonManager, stop_addon: AsyncMock
) -> None: ) -> None:
"""Test stop addon raises error.""" """Test stop addon raises error."""
stop_addon.side_effect = HassioAPIError("Boom") stop_addon.side_effect = SupervisorError("Boom")
with pytest.raises(AddonError) as err: with pytest.raises(AddonError) as err:
await addon_manager.async_stop_addon() await addon_manager.async_stop_addon()
@ -811,7 +812,7 @@ async def test_schedule_install_setup_addon(
1, 1,
None, None,
1, 1,
HassioAPIError("Boom"), SupervisorError("Boom"),
1, 1,
"Failed to start the Test add-on: Boom", "Failed to start the Test add-on: Boom",
), ),
@ -880,7 +881,7 @@ async def test_schedule_install_setup_addon_error(
1, 1,
None, None,
1, 1,
HassioAPIError("Boom"), SupervisorError("Boom"),
1, 1,
"Failed to start the Test add-on: Boom", "Failed to start the Test add-on: Boom",
), ),
@ -964,7 +965,7 @@ async def test_schedule_setup_addon(
( (
None, None,
1, 1,
HassioAPIError("Boom"), SupervisorError("Boom"),
1, 1,
"Failed to start the Test add-on: Boom", "Failed to start the Test add-on: Boom",
), ),
@ -1013,7 +1014,7 @@ async def test_schedule_setup_addon_error(
( (
None, None,
1, 1,
HassioAPIError("Boom"), SupervisorError("Boom"),
1, 1,
"Failed to start the Test add-on: Boom", "Failed to start the Test add-on: Boom",
), ),

View File

@ -47,12 +47,3 @@ def mock_zha_get_last_network_settings() -> Generator[None]:
AsyncMock(return_value=None), AsyncMock(return_value=None),
): ):
yield yield
@pytest.fixture(name="stop_addon")
def stop_addon_fixture():
"""Mock stop add-on."""
with patch(
"homeassistant.components.hassio.addon_manager.async_stop_addon"
) as stop_addon:
yield stop_addon

View File

@ -6,6 +6,7 @@ from collections.abc import Generator
from typing import Any from typing import Any
from unittest.mock import AsyncMock, Mock, patch from unittest.mock import AsyncMock, Mock, patch
from aiohasupervisor import SupervisorError
import pytest import pytest
from homeassistant.components.hassio import ( from homeassistant.components.hassio import (
@ -265,7 +266,7 @@ async def test_option_flow_install_multi_pan_addon(
) )
await hass.async_block_till_done() await hass.async_block_till_done()
start_addon.assert_called_once_with(hass, "core_silabs_multiprotocol") start_addon.assert_called_once_with("core_silabs_multiprotocol")
result = await hass.config_entries.options.async_configure(result["flow_id"]) result = await hass.config_entries.options.async_configure(result["flow_id"])
assert result["type"] is FlowResultType.CREATE_ENTRY assert result["type"] is FlowResultType.CREATE_ENTRY
@ -360,7 +361,7 @@ async def test_option_flow_install_multi_pan_addon_zha(
assert zha_config_entry.title == "Test Multiprotocol" assert zha_config_entry.title == "Test Multiprotocol"
await hass.async_block_till_done() await hass.async_block_till_done()
start_addon.assert_called_once_with(hass, "core_silabs_multiprotocol") start_addon.assert_called_once_with("core_silabs_multiprotocol")
result = await hass.config_entries.options.async_configure(result["flow_id"]) result = await hass.config_entries.options.async_configure(result["flow_id"])
assert result["type"] is FlowResultType.CREATE_ENTRY assert result["type"] is FlowResultType.CREATE_ENTRY
@ -436,7 +437,7 @@ async def test_option_flow_install_multi_pan_addon_zha_other_radio(
) )
await hass.async_block_till_done() await hass.async_block_till_done()
start_addon.assert_called_once_with(hass, "core_silabs_multiprotocol") start_addon.assert_called_once_with("core_silabs_multiprotocol")
result = await hass.config_entries.options.async_configure(result["flow_id"]) result = await hass.config_entries.options.async_configure(result["flow_id"])
assert result["type"] is FlowResultType.CREATE_ENTRY assert result["type"] is FlowResultType.CREATE_ENTRY
@ -699,7 +700,7 @@ async def test_option_flow_addon_installed_same_device_uninstall(
assert result["progress_action"] == "uninstall_multiprotocol_addon" assert result["progress_action"] == "uninstall_multiprotocol_addon"
await hass.async_block_till_done() await hass.async_block_till_done()
uninstall_addon.assert_called_once_with(hass, "core_silabs_multiprotocol") uninstall_addon.assert_called_once_with("core_silabs_multiprotocol")
result = await hass.config_entries.options.async_configure(result["flow_id"]) result = await hass.config_entries.options.async_configure(result["flow_id"])
assert result["type"] is FlowResultType.SHOW_PROGRESS assert result["type"] is FlowResultType.SHOW_PROGRESS
@ -864,7 +865,7 @@ async def test_option_flow_addon_installed_same_device_flasher_already_installed
assert result["progress_action"] == "uninstall_multiprotocol_addon" assert result["progress_action"] == "uninstall_multiprotocol_addon"
await hass.async_block_till_done() await hass.async_block_till_done()
uninstall_addon.assert_called_once_with(hass, "core_silabs_multiprotocol") uninstall_addon.assert_called_once_with("core_silabs_multiprotocol")
result = await hass.config_entries.options.async_configure(result["flow_id"]) result = await hass.config_entries.options.async_configure(result["flow_id"])
assert result["type"] is FlowResultType.SHOW_PROGRESS assert result["type"] is FlowResultType.SHOW_PROGRESS
@ -996,10 +997,10 @@ async def test_option_flow_flasher_addon_flash_failure(
assert result["step_id"] == "uninstall_multiprotocol_addon" assert result["step_id"] == "uninstall_multiprotocol_addon"
assert result["progress_action"] == "uninstall_multiprotocol_addon" assert result["progress_action"] == "uninstall_multiprotocol_addon"
start_addon.side_effect = HassioAPIError("Boom") start_addon.side_effect = SupervisorError("Boom")
await hass.async_block_till_done() await hass.async_block_till_done()
uninstall_addon.assert_called_once_with(hass, "core_silabs_multiprotocol") uninstall_addon.assert_called_once_with("core_silabs_multiprotocol")
result = await hass.config_entries.options.async_configure(result["flow_id"]) result = await hass.config_entries.options.async_configure(result["flow_id"])
assert result["type"] is FlowResultType.SHOW_PROGRESS assert result["type"] is FlowResultType.SHOW_PROGRESS
@ -1133,7 +1134,7 @@ async def test_option_flow_uninstall_migration_finish_failure(
) )
await hass.async_block_till_done() await hass.async_block_till_done()
uninstall_addon.assert_called_once_with(hass, "core_silabs_multiprotocol") uninstall_addon.assert_called_once_with("core_silabs_multiprotocol")
result = await hass.config_entries.options.async_configure(result["flow_id"]) result = await hass.config_entries.options.async_configure(result["flow_id"])
assert result["type"] is FlowResultType.SHOW_PROGRESS assert result["type"] is FlowResultType.SHOW_PROGRESS
@ -1230,7 +1231,7 @@ async def test_option_flow_install_multi_pan_addon_start_fails(
) -> None: ) -> None:
"""Test installing the multi pan addon.""" """Test installing the multi pan addon."""
start_addon.side_effect = HassioAPIError("Boom") start_addon.side_effect = SupervisorError("Boom")
# Setup the config entry # Setup the config entry
config_entry = MockConfigEntry( config_entry = MockConfigEntry(
@ -1275,7 +1276,7 @@ async def test_option_flow_install_multi_pan_addon_start_fails(
) )
await hass.async_block_till_done() await hass.async_block_till_done()
start_addon.assert_called_once_with(hass, "core_silabs_multiprotocol") start_addon.assert_called_once_with("core_silabs_multiprotocol")
result = await hass.config_entries.options.async_configure(result["flow_id"]) result = await hass.config_entries.options.async_configure(result["flow_id"])
assert result["type"] is FlowResultType.ABORT assert result["type"] is FlowResultType.ABORT
@ -1470,7 +1471,7 @@ async def test_option_flow_install_multi_pan_addon_zha_migration_fails_step_2(
) )
await hass.async_block_till_done() await hass.async_block_till_done()
start_addon.assert_called_once_with(hass, "core_silabs_multiprotocol") start_addon.assert_called_once_with("core_silabs_multiprotocol")
result = await hass.config_entries.options.async_configure(result["flow_id"]) result = await hass.config_entries.options.async_configure(result["flow_id"])
assert result["type"] is FlowResultType.ABORT assert result["type"] is FlowResultType.ABORT
@ -1678,7 +1679,7 @@ async def test_check_multi_pan_addon_auto_start(
with pytest.raises(HomeAssistantError): with pytest.raises(HomeAssistantError):
await silabs_multiprotocol_addon.check_multi_pan_addon(hass) await silabs_multiprotocol_addon.check_multi_pan_addon(hass)
start_addon.assert_called_once_with(hass, "core_silabs_multiprotocol") start_addon.assert_called_once_with("core_silabs_multiprotocol")
async def test_check_multi_pan_addon( async def test_check_multi_pan_addon(

View File

@ -47,12 +47,3 @@ def mock_zha_get_last_network_settings() -> Generator[None]:
AsyncMock(return_value=None), AsyncMock(return_value=None),
): ):
yield yield
@pytest.fixture(name="stop_addon")
def stop_addon_fixture():
"""Mock stop add-on."""
with patch(
"homeassistant.components.hassio.addon_manager.async_stop_addon"
) as stop_addon:
yield stop_addon

View File

@ -6,6 +6,7 @@ from collections.abc import Generator
from ipaddress import ip_address from ipaddress import ip_address
from unittest.mock import AsyncMock, MagicMock, call, patch from unittest.mock import AsyncMock, MagicMock, call, patch
from aiohasupervisor import SupervisorError
from matter_server.client.exceptions import CannotConnect, InvalidServerVersion from matter_server.client.exceptions import CannotConnect, InvalidServerVersion
import pytest import pytest
@ -380,7 +381,7 @@ async def test_zeroconf_not_onboarded_installed(
await hass.async_block_till_done() await hass.async_block_till_done()
assert addon_info.call_count == 1 assert addon_info.call_count == 1
assert start_addon.call_args == call(hass, "core_matter_server") assert start_addon.call_args == call("core_matter_server")
assert client_connect.call_count == 1 assert client_connect.call_count == 1
assert result["type"] is FlowResultType.CREATE_ENTRY assert result["type"] is FlowResultType.CREATE_ENTRY
assert result["title"] == "Matter" assert result["title"] == "Matter"
@ -418,7 +419,7 @@ async def test_zeroconf_not_onboarded_not_installed(
assert addon_info.call_count == 0 assert addon_info.call_count == 0
assert addon_store_info.call_count == 2 assert addon_store_info.call_count == 2
assert install_addon.call_args == call(hass, "core_matter_server") assert install_addon.call_args == call(hass, "core_matter_server")
assert start_addon.call_args == call(hass, "core_matter_server") assert start_addon.call_args == call("core_matter_server")
assert client_connect.call_count == 1 assert client_connect.call_count == 1
assert result["type"] is FlowResultType.CREATE_ENTRY assert result["type"] is FlowResultType.CREATE_ENTRY
assert result["title"] == "Matter" assert result["title"] == "Matter"
@ -468,7 +469,7 @@ async def test_supervisor_discovery(
@pytest.mark.parametrize( @pytest.mark.parametrize(
("discovery_info", "error"), ("discovery_info", "error"),
[({"config": ADDON_DISCOVERY_INFO}, HassioAPIError())], [({"config": ADDON_DISCOVERY_INFO}, SupervisorError())],
) )
async def test_supervisor_discovery_addon_info_failed( async def test_supervisor_discovery_addon_info_failed(
hass: HomeAssistant, hass: HomeAssistant,
@ -682,7 +683,7 @@ async def test_supervisor_discovery_addon_not_running(
result = await hass.config_entries.flow.async_configure(result["flow_id"]) result = await hass.config_entries.flow.async_configure(result["flow_id"])
await hass.async_block_till_done() await hass.async_block_till_done()
assert start_addon.call_args == call(hass, "core_matter_server") assert start_addon.call_args == call("core_matter_server")
assert client_connect.call_count == 1 assert client_connect.call_count == 1
assert result["type"] is FlowResultType.CREATE_ENTRY assert result["type"] is FlowResultType.CREATE_ENTRY
assert result["title"] == "Matter" assert result["title"] == "Matter"
@ -740,7 +741,7 @@ async def test_supervisor_discovery_addon_not_installed(
result = await hass.config_entries.flow.async_configure(result["flow_id"]) result = await hass.config_entries.flow.async_configure(result["flow_id"])
await hass.async_block_till_done() await hass.async_block_till_done()
assert start_addon.call_args == call(hass, "core_matter_server") assert start_addon.call_args == call("core_matter_server")
assert client_connect.call_count == 1 assert client_connect.call_count == 1
assert result["type"] is FlowResultType.CREATE_ENTRY assert result["type"] is FlowResultType.CREATE_ENTRY
assert result["title"] == "Matter" assert result["title"] == "Matter"
@ -868,7 +869,7 @@ async def test_addon_running(
{"config": ADDON_DISCOVERY_INFO}, {"config": ADDON_DISCOVERY_INFO},
None, None,
None, None,
HassioAPIError(), SupervisorError(),
"addon_info_failed", "addon_info_failed",
False, False,
False, False,
@ -954,7 +955,7 @@ async def test_addon_running_failures(
{"config": ADDON_DISCOVERY_INFO}, {"config": ADDON_DISCOVERY_INFO},
None, None,
None, None,
HassioAPIError(), SupervisorError(),
"addon_info_failed", "addon_info_failed",
False, False,
False, False,
@ -1062,7 +1063,7 @@ async def test_addon_installed(
result = await hass.config_entries.flow.async_configure(result["flow_id"]) result = await hass.config_entries.flow.async_configure(result["flow_id"])
await hass.async_block_till_done() await hass.async_block_till_done()
assert start_addon.call_args == call(hass, "core_matter_server") assert start_addon.call_args == call("core_matter_server")
assert result["type"] is FlowResultType.CREATE_ENTRY assert result["type"] is FlowResultType.CREATE_ENTRY
assert result["title"] == "Matter" assert result["title"] == "Matter"
assert result["data"] == { assert result["data"] == {
@ -1084,7 +1085,7 @@ async def test_addon_installed(
[ [
( (
{"config": ADDON_DISCOVERY_INFO}, {"config": ADDON_DISCOVERY_INFO},
HassioAPIError(), SupervisorError(),
None, None,
False, False,
False, False,
@ -1140,7 +1141,7 @@ async def test_addon_installed_failures(
await hass.async_block_till_done() await hass.async_block_till_done()
result = await hass.config_entries.flow.async_configure(result["flow_id"]) result = await hass.config_entries.flow.async_configure(result["flow_id"])
assert start_addon.call_args == call(hass, "core_matter_server") assert start_addon.call_args == call("core_matter_server")
assert get_addon_discovery_info.called is discovery_info_called assert get_addon_discovery_info.called is discovery_info_called
assert client_connect.called is client_connect_called assert client_connect.called is client_connect_called
assert result["type"] is FlowResultType.ABORT assert result["type"] is FlowResultType.ABORT
@ -1159,7 +1160,7 @@ async def test_addon_installed_failures(
[ [
( (
{"config": ADDON_DISCOVERY_INFO}, {"config": ADDON_DISCOVERY_INFO},
HassioAPIError(), SupervisorError(),
None, None,
False, False,
False, False,
@ -1205,7 +1206,7 @@ async def test_addon_installed_failures_zeroconf(
await hass.async_block_till_done() await hass.async_block_till_done()
assert addon_info.call_count == 1 assert addon_info.call_count == 1
assert start_addon.call_args == call(hass, "core_matter_server") assert start_addon.call_args == call("core_matter_server")
assert get_addon_discovery_info.called is discovery_info_called assert get_addon_discovery_info.called is discovery_info_called
assert client_connect.called is client_connect_called assert client_connect.called is client_connect_called
assert result["type"] is FlowResultType.ABORT assert result["type"] is FlowResultType.ABORT
@ -1250,7 +1251,7 @@ async def test_addon_installed_already_configured(
result = await hass.config_entries.flow.async_configure(result["flow_id"]) result = await hass.config_entries.flow.async_configure(result["flow_id"])
await hass.async_block_till_done() await hass.async_block_till_done()
assert start_addon.call_args == call(hass, "core_matter_server") assert start_addon.call_args == call("core_matter_server")
assert result["type"] is FlowResultType.ABORT assert result["type"] is FlowResultType.ABORT
assert result["reason"] == "reconfiguration_successful" assert result["reason"] == "reconfiguration_successful"
assert entry.data["url"] == "ws://host1:5581/ws" assert entry.data["url"] == "ws://host1:5581/ws"
@ -1298,7 +1299,7 @@ async def test_addon_not_installed(
result = await hass.config_entries.flow.async_configure(result["flow_id"]) result = await hass.config_entries.flow.async_configure(result["flow_id"])
await hass.async_block_till_done() await hass.async_block_till_done()
assert start_addon.call_args == call(hass, "core_matter_server") assert start_addon.call_args == call("core_matter_server")
assert result["type"] is FlowResultType.CREATE_ENTRY assert result["type"] is FlowResultType.CREATE_ENTRY
assert result["title"] == "Matter" assert result["title"] == "Matter"
assert result["data"] == { assert result["data"] == {
@ -1417,7 +1418,7 @@ async def test_addon_not_installed_already_configured(
result = await hass.config_entries.flow.async_configure(result["flow_id"]) result = await hass.config_entries.flow.async_configure(result["flow_id"])
await hass.async_block_till_done() await hass.async_block_till_done()
assert start_addon.call_args == call(hass, "core_matter_server") assert start_addon.call_args == call("core_matter_server")
assert client_connect.call_count == 1 assert client_connect.call_count == 1
assert result["type"] is FlowResultType.ABORT assert result["type"] is FlowResultType.ABORT
assert result["reason"] == "reconfiguration_successful" assert result["reason"] == "reconfiguration_successful"

View File

@ -6,6 +6,7 @@ import asyncio
from collections.abc import Generator from collections.abc import Generator
from unittest.mock import AsyncMock, MagicMock, call, patch from unittest.mock import AsyncMock, MagicMock, call, patch
from aiohasupervisor import SupervisorError
from matter_server.client.exceptions import ( from matter_server.client.exceptions import (
CannotConnect, CannotConnect,
ServerVersionTooNew, ServerVersionTooNew,
@ -298,7 +299,7 @@ async def test_start_addon(
assert addon_info.call_count == 1 assert addon_info.call_count == 1
assert install_addon.call_count == 0 assert install_addon.call_count == 0
assert start_addon.call_count == 1 assert start_addon.call_count == 1
assert start_addon.call_args == call(hass, "core_matter_server") assert start_addon.call_args == call("core_matter_server")
async def test_install_addon( async def test_install_addon(
@ -327,7 +328,7 @@ async def test_install_addon(
assert install_addon.call_count == 1 assert install_addon.call_count == 1
assert install_addon.call_args == call(hass, "core_matter_server") assert install_addon.call_args == call(hass, "core_matter_server")
assert start_addon.call_count == 1 assert start_addon.call_count == 1
assert start_addon.call_args == call(hass, "core_matter_server") assert start_addon.call_args == call("core_matter_server")
async def test_addon_info_failure( async def test_addon_info_failure(
@ -338,7 +339,7 @@ async def test_addon_info_failure(
start_addon: AsyncMock, start_addon: AsyncMock,
) -> None: ) -> None:
"""Test failure to get add-on info for Matter add-on during entry setup.""" """Test failure to get add-on info for Matter add-on during entry setup."""
addon_info.side_effect = HassioAPIError("Boom") addon_info.side_effect = SupervisorError("Boom")
entry = MockConfigEntry( entry = MockConfigEntry(
domain=DOMAIN, domain=DOMAIN,
title="Matter", title="Matter",
@ -492,7 +493,7 @@ async def test_issue_registry_invalid_version(
("stop_addon_side_effect", "entry_state"), ("stop_addon_side_effect", "entry_state"),
[ [
(None, ConfigEntryState.NOT_LOADED), (None, ConfigEntryState.NOT_LOADED),
(HassioAPIError("Boom"), ConfigEntryState.LOADED), (SupervisorError("Boom"), ConfigEntryState.LOADED),
], ],
) )
async def test_stop_addon( async def test_stop_addon(
@ -531,7 +532,7 @@ async def test_stop_addon(
assert entry.state == entry_state assert entry.state == entry_state
assert stop_addon.call_count == 1 assert stop_addon.call_count == 1
assert stop_addon.call_args == call(hass, "core_matter_server") assert stop_addon.call_args == call("core_matter_server")
async def test_remove_entry( async def test_remove_entry(
@ -570,7 +571,7 @@ async def test_remove_entry(
await hass.config_entries.async_remove(entry.entry_id) await hass.config_entries.async_remove(entry.entry_id)
assert stop_addon.call_count == 1 assert stop_addon.call_count == 1
assert stop_addon.call_args == call(hass, "core_matter_server") assert stop_addon.call_args == call("core_matter_server")
assert create_backup.call_count == 1 assert create_backup.call_count == 1
assert create_backup.call_args == call( assert create_backup.call_args == call(
hass, hass,
@ -578,7 +579,7 @@ async def test_remove_entry(
partial=True, partial=True,
) )
assert uninstall_addon.call_count == 1 assert uninstall_addon.call_count == 1
assert uninstall_addon.call_args == call(hass, "core_matter_server") assert uninstall_addon.call_args == call("core_matter_server")
assert entry.state is ConfigEntryState.NOT_LOADED assert entry.state is ConfigEntryState.NOT_LOADED
assert len(hass.config_entries.async_entries(DOMAIN)) == 0 assert len(hass.config_entries.async_entries(DOMAIN)) == 0
stop_addon.reset_mock() stop_addon.reset_mock()
@ -588,12 +589,12 @@ async def test_remove_entry(
# test add-on stop failure # test add-on stop failure
entry.add_to_hass(hass) entry.add_to_hass(hass)
assert len(hass.config_entries.async_entries(DOMAIN)) == 1 assert len(hass.config_entries.async_entries(DOMAIN)) == 1
stop_addon.side_effect = HassioAPIError() stop_addon.side_effect = SupervisorError()
await hass.config_entries.async_remove(entry.entry_id) await hass.config_entries.async_remove(entry.entry_id)
assert stop_addon.call_count == 1 assert stop_addon.call_count == 1
assert stop_addon.call_args == call(hass, "core_matter_server") assert stop_addon.call_args == call("core_matter_server")
assert create_backup.call_count == 0 assert create_backup.call_count == 0
assert uninstall_addon.call_count == 0 assert uninstall_addon.call_count == 0
assert entry.state is ConfigEntryState.NOT_LOADED assert entry.state is ConfigEntryState.NOT_LOADED
@ -612,7 +613,7 @@ async def test_remove_entry(
await hass.config_entries.async_remove(entry.entry_id) await hass.config_entries.async_remove(entry.entry_id)
assert stop_addon.call_count == 1 assert stop_addon.call_count == 1
assert stop_addon.call_args == call(hass, "core_matter_server") assert stop_addon.call_args == call("core_matter_server")
assert create_backup.call_count == 1 assert create_backup.call_count == 1
assert create_backup.call_args == call( assert create_backup.call_args == call(
hass, hass,
@ -631,12 +632,12 @@ async def test_remove_entry(
# test add-on uninstall failure # test add-on uninstall failure
entry.add_to_hass(hass) entry.add_to_hass(hass)
assert len(hass.config_entries.async_entries(DOMAIN)) == 1 assert len(hass.config_entries.async_entries(DOMAIN)) == 1
uninstall_addon.side_effect = HassioAPIError() uninstall_addon.side_effect = SupervisorError()
await hass.config_entries.async_remove(entry.entry_id) await hass.config_entries.async_remove(entry.entry_id)
assert stop_addon.call_count == 1 assert stop_addon.call_count == 1
assert stop_addon.call_args == call(hass, "core_matter_server") assert stop_addon.call_args == call("core_matter_server")
assert create_backup.call_count == 1 assert create_backup.call_count == 1
assert create_backup.call_args == call( assert create_backup.call_args == call(
hass, hass,
@ -644,7 +645,7 @@ async def test_remove_entry(
partial=True, partial=True,
) )
assert uninstall_addon.call_count == 1 assert uninstall_addon.call_count == 1
assert uninstall_addon.call_args == call(hass, "core_matter_server") assert uninstall_addon.call_args == call("core_matter_server")
assert entry.state is ConfigEntryState.NOT_LOADED assert entry.state is ConfigEntryState.NOT_LOADED
assert len(hass.config_entries.async_entries(DOMAIN)) == 0 assert len(hass.config_entries.async_entries(DOMAIN)) == 0
assert "Failed to uninstall the Matter Server add-on" in caplog.text assert "Failed to uninstall the Matter Server add-on" in caplog.text

View File

@ -8,6 +8,7 @@ from typing import Any
from unittest.mock import AsyncMock, MagicMock, patch from unittest.mock import AsyncMock, MagicMock, patch
from uuid import uuid4 from uuid import uuid4
from aiohasupervisor import SupervisorError
import pytest import pytest
import voluptuous as vol import voluptuous as vol
@ -671,7 +672,7 @@ async def test_addon_not_running_api_error(
Case: The Mosquitto add-on start fails on a API error. Case: The Mosquitto add-on start fails on a API error.
""" """
start_addon.side_effect = HassioAPIError() start_addon.side_effect = SupervisorError()
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(
"mqtt", context={"source": config_entries.SOURCE_USER} "mqtt", context={"source": config_entries.SOURCE_USER}
@ -758,7 +759,7 @@ async def test_addon_info_error(
Case: The Mosquitto add-on info could not be retrieved. Case: The Mosquitto add-on info could not be retrieved.
""" """
addon_info.side_effect = AddonError() addon_info.side_effect = SupervisorError()
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(
"mqtt", context={"source": config_entries.SOURCE_USER} "mqtt", context={"source": config_entries.SOURCE_USER}

View File

@ -632,7 +632,7 @@ async def test_usb_discovery(
result = await hass.config_entries.flow.async_configure(result["flow_id"]) result = await hass.config_entries.flow.async_configure(result["flow_id"])
await hass.async_block_till_done() await hass.async_block_till_done()
assert start_addon.call_args == call(hass, "core_zwave_js") assert start_addon.call_args == call("core_zwave_js")
assert result["type"] is FlowResultType.CREATE_ENTRY assert result["type"] is FlowResultType.CREATE_ENTRY
assert result["title"] == TITLE assert result["title"] == TITLE
@ -733,7 +733,7 @@ async def test_usb_discovery_addon_not_running(
result = await hass.config_entries.flow.async_configure(result["flow_id"]) result = await hass.config_entries.flow.async_configure(result["flow_id"])
await hass.async_block_till_done() await hass.async_block_till_done()
assert start_addon.call_args == call(hass, "core_zwave_js") assert start_addon.call_args == call("core_zwave_js")
assert result["type"] is FlowResultType.CREATE_ENTRY assert result["type"] is FlowResultType.CREATE_ENTRY
assert result["title"] == TITLE assert result["title"] == TITLE
@ -828,7 +828,7 @@ async def test_discovery_addon_not_running(
result = await hass.config_entries.flow.async_configure(result["flow_id"]) result = await hass.config_entries.flow.async_configure(result["flow_id"])
await hass.async_block_till_done() await hass.async_block_till_done()
assert start_addon.call_args == call(hass, "core_zwave_js") assert start_addon.call_args == call("core_zwave_js")
assert result["type"] is FlowResultType.CREATE_ENTRY assert result["type"] is FlowResultType.CREATE_ENTRY
assert result["title"] == TITLE assert result["title"] == TITLE
@ -931,7 +931,7 @@ async def test_discovery_addon_not_installed(
result = await hass.config_entries.flow.async_configure(result["flow_id"]) result = await hass.config_entries.flow.async_configure(result["flow_id"])
await hass.async_block_till_done() await hass.async_block_till_done()
assert start_addon.call_args == call(hass, "core_zwave_js") assert start_addon.call_args == call("core_zwave_js")
assert result["type"] is FlowResultType.CREATE_ENTRY assert result["type"] is FlowResultType.CREATE_ENTRY
assert result["title"] == TITLE assert result["title"] == TITLE
@ -1344,7 +1344,7 @@ async def test_addon_installed(
result = await hass.config_entries.flow.async_configure(result["flow_id"]) result = await hass.config_entries.flow.async_configure(result["flow_id"])
await hass.async_block_till_done() await hass.async_block_till_done()
assert start_addon.call_args == call(hass, "core_zwave_js") assert start_addon.call_args == call("core_zwave_js")
assert result["type"] is FlowResultType.CREATE_ENTRY assert result["type"] is FlowResultType.CREATE_ENTRY
assert result["title"] == TITLE assert result["title"] == TITLE
@ -1428,7 +1428,7 @@ async def test_addon_installed_start_failure(
await hass.async_block_till_done() await hass.async_block_till_done()
result = await hass.config_entries.flow.async_configure(result["flow_id"]) result = await hass.config_entries.flow.async_configure(result["flow_id"])
assert start_addon.call_args == call(hass, "core_zwave_js") assert start_addon.call_args == call("core_zwave_js")
assert result["type"] is FlowResultType.ABORT assert result["type"] is FlowResultType.ABORT
assert result["reason"] == "addon_start_failed" assert result["reason"] == "addon_start_failed"
@ -1507,7 +1507,7 @@ async def test_addon_installed_failures(
await hass.async_block_till_done() await hass.async_block_till_done()
result = await hass.config_entries.flow.async_configure(result["flow_id"]) result = await hass.config_entries.flow.async_configure(result["flow_id"])
assert start_addon.call_args == call(hass, "core_zwave_js") assert start_addon.call_args == call("core_zwave_js")
assert result["type"] is FlowResultType.ABORT assert result["type"] is FlowResultType.ABORT
assert result["reason"] == "addon_start_failed" assert result["reason"] == "addon_start_failed"
@ -1655,7 +1655,7 @@ async def test_addon_installed_already_configured(
await hass.async_block_till_done() await hass.async_block_till_done()
result = await hass.config_entries.flow.async_configure(result["flow_id"]) result = await hass.config_entries.flow.async_configure(result["flow_id"])
assert start_addon.call_args == call(hass, "core_zwave_js") assert start_addon.call_args == call("core_zwave_js")
assert result["type"] is FlowResultType.ABORT assert result["type"] is FlowResultType.ABORT
assert result["reason"] == "already_configured" assert result["reason"] == "already_configured"
@ -1750,7 +1750,7 @@ async def test_addon_not_installed(
result = await hass.config_entries.flow.async_configure(result["flow_id"]) result = await hass.config_entries.flow.async_configure(result["flow_id"])
await hass.async_block_till_done() await hass.async_block_till_done()
assert start_addon.call_args == call(hass, "core_zwave_js") assert start_addon.call_args == call("core_zwave_js")
assert result["type"] is FlowResultType.CREATE_ENTRY assert result["type"] is FlowResultType.CREATE_ENTRY
assert result["title"] == TITLE assert result["title"] == TITLE
@ -2007,7 +2007,7 @@ async def test_options_addon_running(
result = await hass.config_entries.options.async_configure(result["flow_id"]) result = await hass.config_entries.options.async_configure(result["flow_id"])
await hass.async_block_till_done() await hass.async_block_till_done()
assert restart_addon.call_args == call(hass, "core_zwave_js") assert restart_addon.call_args == call("core_zwave_js")
assert result["type"] is FlowResultType.CREATE_ENTRY assert result["type"] is FlowResultType.CREATE_ENTRY
assert entry.data["url"] == "ws://host1:3001" assert entry.data["url"] == "ws://host1:3001"
@ -2286,7 +2286,7 @@ async def test_options_different_device(
await hass.async_block_till_done() await hass.async_block_till_done()
assert restart_addon.call_count == 1 assert restart_addon.call_count == 1
assert restart_addon.call_args == call(hass, "core_zwave_js") assert restart_addon.call_args == call("core_zwave_js")
result = await hass.config_entries.options.async_configure(result["flow_id"]) result = await hass.config_entries.options.async_configure(result["flow_id"])
await hass.async_block_till_done() await hass.async_block_till_done()
@ -2308,7 +2308,7 @@ async def test_options_different_device(
await hass.async_block_till_done() await hass.async_block_till_done()
assert restart_addon.call_count == 2 assert restart_addon.call_count == 2
assert restart_addon.call_args == call(hass, "core_zwave_js") assert restart_addon.call_args == call("core_zwave_js")
result = await hass.config_entries.options.async_configure(result["flow_id"]) result = await hass.config_entries.options.async_configure(result["flow_id"])
await hass.async_block_till_done() await hass.async_block_till_done()
@ -2452,7 +2452,7 @@ async def test_options_addon_restart_failed(
await hass.async_block_till_done() await hass.async_block_till_done()
assert restart_addon.call_count == 1 assert restart_addon.call_count == 1
assert restart_addon.call_args == call(hass, "core_zwave_js") assert restart_addon.call_args == call("core_zwave_js")
result = await hass.config_entries.options.async_configure(result["flow_id"]) result = await hass.config_entries.options.async_configure(result["flow_id"])
await hass.async_block_till_done() await hass.async_block_till_done()
@ -2471,7 +2471,7 @@ async def test_options_addon_restart_failed(
await hass.async_block_till_done() await hass.async_block_till_done()
assert restart_addon.call_count == 2 assert restart_addon.call_count == 2
assert restart_addon.call_args == call(hass, "core_zwave_js") assert restart_addon.call_args == call("core_zwave_js")
result = await hass.config_entries.options.async_configure(result["flow_id"]) result = await hass.config_entries.options.async_configure(result["flow_id"])
await hass.async_block_till_done() await hass.async_block_till_done()
@ -2709,7 +2709,7 @@ async def test_options_addon_not_installed(
await hass.async_block_till_done() await hass.async_block_till_done()
assert start_addon.call_count == 1 assert start_addon.call_count == 1
assert start_addon.call_args == call(hass, "core_zwave_js") assert start_addon.call_args == call("core_zwave_js")
result = await hass.config_entries.options.async_configure(result["flow_id"]) result = await hass.config_entries.options.async_configure(result["flow_id"])
await hass.async_block_till_done() await hass.async_block_till_done()

View File

@ -5,6 +5,7 @@ from copy import deepcopy
import logging import logging
from unittest.mock import AsyncMock, call, patch from unittest.mock import AsyncMock, call, patch
from aiohasupervisor import SupervisorError
import pytest import pytest
from zwave_js_server.client import Client from zwave_js_server.client import Client
from zwave_js_server.event import Event from zwave_js_server.event import Event
@ -556,7 +557,7 @@ async def test_start_addon(
hass, "core_zwave_js", {"options": addon_options} hass, "core_zwave_js", {"options": addon_options}
) )
assert start_addon.call_count == 1 assert start_addon.call_count == 1
assert start_addon.call_args == call(hass, "core_zwave_js") assert start_addon.call_args == call("core_zwave_js")
async def test_install_addon( async def test_install_addon(
@ -605,7 +606,7 @@ async def test_install_addon(
hass, "core_zwave_js", {"options": addon_options} hass, "core_zwave_js", {"options": addon_options}
) )
assert start_addon.call_count == 1 assert start_addon.call_count == 1
assert start_addon.call_args == call(hass, "core_zwave_js") assert start_addon.call_args == call("core_zwave_js")
@pytest.mark.parametrize("addon_info_side_effect", [HassioAPIError("Boom")]) @pytest.mark.parametrize("addon_info_side_effect", [HassioAPIError("Boom")])
@ -845,7 +846,7 @@ async def test_issue_registry(
("stop_addon_side_effect", "entry_state"), ("stop_addon_side_effect", "entry_state"),
[ [
(None, ConfigEntryState.NOT_LOADED), (None, ConfigEntryState.NOT_LOADED),
(HassioAPIError("Boom"), ConfigEntryState.LOADED), (SupervisorError("Boom"), ConfigEntryState.LOADED),
], ],
) )
async def test_stop_addon( async def test_stop_addon(
@ -888,7 +889,7 @@ async def test_stop_addon(
assert entry.state == entry_state assert entry.state == entry_state
assert stop_addon.call_count == 1 assert stop_addon.call_count == 1
assert stop_addon.call_args == call(hass, "core_zwave_js") assert stop_addon.call_args == call("core_zwave_js")
async def test_remove_entry( async def test_remove_entry(
@ -927,7 +928,7 @@ async def test_remove_entry(
await hass.config_entries.async_remove(entry.entry_id) await hass.config_entries.async_remove(entry.entry_id)
assert stop_addon.call_count == 1 assert stop_addon.call_count == 1
assert stop_addon.call_args == call(hass, "core_zwave_js") assert stop_addon.call_args == call("core_zwave_js")
assert create_backup.call_count == 1 assert create_backup.call_count == 1
assert create_backup.call_args == call( assert create_backup.call_args == call(
hass, hass,
@ -935,7 +936,7 @@ async def test_remove_entry(
partial=True, partial=True,
) )
assert uninstall_addon.call_count == 1 assert uninstall_addon.call_count == 1
assert uninstall_addon.call_args == call(hass, "core_zwave_js") assert uninstall_addon.call_args == call("core_zwave_js")
assert entry.state is ConfigEntryState.NOT_LOADED assert entry.state is ConfigEntryState.NOT_LOADED
assert len(hass.config_entries.async_entries(DOMAIN)) == 0 assert len(hass.config_entries.async_entries(DOMAIN)) == 0
stop_addon.reset_mock() stop_addon.reset_mock()
@ -945,12 +946,12 @@ async def test_remove_entry(
# test add-on stop failure # test add-on stop failure
entry.add_to_hass(hass) entry.add_to_hass(hass)
assert len(hass.config_entries.async_entries(DOMAIN)) == 1 assert len(hass.config_entries.async_entries(DOMAIN)) == 1
stop_addon.side_effect = HassioAPIError() stop_addon.side_effect = SupervisorError()
await hass.config_entries.async_remove(entry.entry_id) await hass.config_entries.async_remove(entry.entry_id)
assert stop_addon.call_count == 1 assert stop_addon.call_count == 1
assert stop_addon.call_args == call(hass, "core_zwave_js") assert stop_addon.call_args == call("core_zwave_js")
assert create_backup.call_count == 0 assert create_backup.call_count == 0
assert uninstall_addon.call_count == 0 assert uninstall_addon.call_count == 0
assert entry.state is ConfigEntryState.NOT_LOADED assert entry.state is ConfigEntryState.NOT_LOADED
@ -969,7 +970,7 @@ async def test_remove_entry(
await hass.config_entries.async_remove(entry.entry_id) await hass.config_entries.async_remove(entry.entry_id)
assert stop_addon.call_count == 1 assert stop_addon.call_count == 1
assert stop_addon.call_args == call(hass, "core_zwave_js") assert stop_addon.call_args == call("core_zwave_js")
assert create_backup.call_count == 1 assert create_backup.call_count == 1
assert create_backup.call_args == call( assert create_backup.call_args == call(
hass, hass,
@ -988,12 +989,12 @@ async def test_remove_entry(
# test add-on uninstall failure # test add-on uninstall failure
entry.add_to_hass(hass) entry.add_to_hass(hass)
assert len(hass.config_entries.async_entries(DOMAIN)) == 1 assert len(hass.config_entries.async_entries(DOMAIN)) == 1
uninstall_addon.side_effect = HassioAPIError() uninstall_addon.side_effect = SupervisorError()
await hass.config_entries.async_remove(entry.entry_id) await hass.config_entries.async_remove(entry.entry_id)
assert stop_addon.call_count == 1 assert stop_addon.call_count == 1
assert stop_addon.call_args == call(hass, "core_zwave_js") assert stop_addon.call_args == call("core_zwave_js")
assert create_backup.call_count == 1 assert create_backup.call_count == 1
assert create_backup.call_args == call( assert create_backup.call_args == call(
hass, hass,
@ -1001,7 +1002,7 @@ async def test_remove_entry(
partial=True, partial=True,
) )
assert uninstall_addon.call_count == 1 assert uninstall_addon.call_count == 1
assert uninstall_addon.call_args == call(hass, "core_zwave_js") assert uninstall_addon.call_args == call("core_zwave_js")
assert entry.state is ConfigEntryState.NOT_LOADED assert entry.state is ConfigEntryState.NOT_LOADED
assert len(hass.config_entries.async_entries(DOMAIN)) == 0 assert len(hass.config_entries.async_entries(DOMAIN)) == 0
assert "Failed to uninstall the Z-Wave JS add-on" in caplog.text assert "Failed to uninstall the Z-Wave JS add-on" in caplog.text