Remove homeassistant_yellow config entry if hassio is not present (#109686)
This commit is contained in:
parent
048d9e75e6
commit
f1d3c417f9
5 changed files with 54 additions and 2 deletions
|
@ -1,7 +1,7 @@
|
|||
"""The Home Assistant Yellow integration."""
|
||||
from __future__ import annotations
|
||||
|
||||
from homeassistant.components.hassio import get_os_info
|
||||
from homeassistant.components.hassio import get_os_info, is_hassio
|
||||
from homeassistant.components.homeassistant_hardware.silabs_multiprotocol_addon import (
|
||||
check_multi_pan_addon,
|
||||
get_zigbee_socket,
|
||||
|
@ -16,6 +16,11 @@ from .const import RADIO_DEVICE, ZHA_HW_DISCOVERY_DATA
|
|||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""Set up a Home Assistant Yellow config entry."""
|
||||
if not is_hassio(hass):
|
||||
# Not running under supervisor, Home Assistant may have been migrated
|
||||
hass.async_create_task(hass.config_entries.async_remove(entry.entry_id))
|
||||
return False
|
||||
|
||||
if (os_info := get_os_info(hass)) is None:
|
||||
# The hassio integration has not yet fetched data from the supervisor
|
||||
raise ConfigEntryNotReady
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
{
|
||||
"domain": "homeassistant_yellow",
|
||||
"name": "Home Assistant Yellow",
|
||||
"after_dependencies": ["hassio"],
|
||||
"codeowners": ["@home-assistant/core"],
|
||||
"config_flow": false,
|
||||
"dependencies": ["hardware", "hassio", "homeassistant_hardware"],
|
||||
"dependencies": ["hardware", "homeassistant_hardware"],
|
||||
"documentation": "https://www.home-assistant.io/integrations/homeassistant_yellow",
|
||||
"integration_type": "hardware"
|
||||
}
|
||||
|
|
|
@ -4,10 +4,12 @@ from unittest.mock import Mock, patch
|
|||
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.hassio import DOMAIN as HASSIO_DOMAIN
|
||||
from homeassistant.components.homeassistant_yellow.const import DOMAIN
|
||||
from homeassistant.components.zha.core.const import DOMAIN as ZHA_DOMAIN
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.data_entry_flow import FlowResultType
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from tests.common import MockConfigEntry, MockModule, mock_integration
|
||||
|
||||
|
@ -52,6 +54,7 @@ def mock_reboot_host():
|
|||
async def test_config_flow(hass: HomeAssistant) -> None:
|
||||
"""Test the config flow."""
|
||||
mock_integration(hass, MockModule("hassio"))
|
||||
await async_setup_component(hass, HASSIO_DOMAIN, {})
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.homeassistant_yellow.async_setup_entry",
|
||||
|
@ -76,6 +79,7 @@ async def test_config_flow(hass: HomeAssistant) -> None:
|
|||
async def test_config_flow_single_entry(hass: HomeAssistant) -> None:
|
||||
"""Test only a single entry is allowed."""
|
||||
mock_integration(hass, MockModule("hassio"))
|
||||
await async_setup_component(hass, HASSIO_DOMAIN, {})
|
||||
|
||||
# Setup the config entry
|
||||
config_entry = MockConfigEntry(
|
||||
|
@ -109,6 +113,7 @@ async def test_option_flow_install_multi_pan_addon(
|
|||
) -> None:
|
||||
"""Test installing the multi pan addon."""
|
||||
mock_integration(hass, MockModule("hassio"))
|
||||
await async_setup_component(hass, HASSIO_DOMAIN, {})
|
||||
|
||||
# Setup the config entry
|
||||
config_entry = MockConfigEntry(
|
||||
|
@ -179,6 +184,7 @@ async def test_option_flow_install_multi_pan_addon_zha(
|
|||
) -> None:
|
||||
"""Test installing the multi pan addon when a zha config entry exists."""
|
||||
mock_integration(hass, MockModule("hassio"))
|
||||
await async_setup_component(hass, HASSIO_DOMAIN, {})
|
||||
|
||||
# Setup the config entry
|
||||
config_entry = MockConfigEntry(
|
||||
|
@ -270,6 +276,7 @@ async def test_option_flow_led_settings(
|
|||
) -> None:
|
||||
"""Test updating LED settings."""
|
||||
mock_integration(hass, MockModule("hassio"))
|
||||
await async_setup_component(hass, HASSIO_DOMAIN, {})
|
||||
|
||||
# Setup the config entry
|
||||
config_entry = MockConfigEntry(
|
||||
|
@ -315,6 +322,7 @@ async def test_option_flow_led_settings_unchanged(
|
|||
) -> None:
|
||||
"""Test updating LED settings."""
|
||||
mock_integration(hass, MockModule("hassio"))
|
||||
await async_setup_component(hass, HASSIO_DOMAIN, {})
|
||||
|
||||
# Setup the config entry
|
||||
config_entry = MockConfigEntry(
|
||||
|
@ -346,6 +354,7 @@ async def test_option_flow_led_settings_unchanged(
|
|||
async def test_option_flow_led_settings_fail_1(hass: HomeAssistant) -> None:
|
||||
"""Test updating LED settings."""
|
||||
mock_integration(hass, MockModule("hassio"))
|
||||
await async_setup_component(hass, HASSIO_DOMAIN, {})
|
||||
|
||||
# Setup the config entry
|
||||
config_entry = MockConfigEntry(
|
||||
|
@ -377,6 +386,7 @@ async def test_option_flow_led_settings_fail_2(
|
|||
) -> None:
|
||||
"""Test updating LED settings."""
|
||||
mock_integration(hass, MockModule("hassio"))
|
||||
await async_setup_component(hass, HASSIO_DOMAIN, {})
|
||||
|
||||
# Setup the config entry
|
||||
config_entry = MockConfigEntry(
|
||||
|
|
|
@ -3,8 +3,10 @@ from unittest.mock import patch
|
|||
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.hassio import DOMAIN as HASSIO_DOMAIN
|
||||
from homeassistant.components.homeassistant_yellow.const import DOMAIN
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from tests.common import MockConfigEntry, MockModule, mock_integration
|
||||
from tests.typing import WebSocketGenerator
|
||||
|
@ -15,6 +17,7 @@ async def test_hardware_info(
|
|||
) -> None:
|
||||
"""Test we can get the board info."""
|
||||
mock_integration(hass, MockModule("hassio"))
|
||||
await async_setup_component(hass, HASSIO_DOMAIN, {})
|
||||
|
||||
# Setup the config entry
|
||||
config_entry = MockConfigEntry(
|
||||
|
@ -66,6 +69,7 @@ async def test_hardware_info_fail(
|
|||
) -> None:
|
||||
"""Test async_info raises if os_info is not as expected."""
|
||||
mock_integration(hass, MockModule("hassio"))
|
||||
await async_setup_component(hass, HASSIO_DOMAIN, {})
|
||||
|
||||
# Setup the config entry
|
||||
config_entry = MockConfigEntry(
|
||||
|
|
|
@ -4,10 +4,12 @@ from unittest.mock import patch
|
|||
import pytest
|
||||
|
||||
from homeassistant.components import zha
|
||||
from homeassistant.components.hassio import DOMAIN as HASSIO_DOMAIN
|
||||
from homeassistant.components.hassio.handler import HassioAPIError
|
||||
from homeassistant.components.homeassistant_yellow.const import DOMAIN
|
||||
from homeassistant.config_entries import ConfigEntryState
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from tests.common import MockConfigEntry, MockModule, mock_integration
|
||||
|
||||
|
@ -20,6 +22,7 @@ async def test_setup_entry(
|
|||
) -> None:
|
||||
"""Test setup of a config entry, including setup of zha."""
|
||||
mock_integration(hass, MockModule("hassio"))
|
||||
await async_setup_component(hass, HASSIO_DOMAIN, {})
|
||||
|
||||
# Setup the config entry
|
||||
config_entry = MockConfigEntry(
|
||||
|
@ -62,6 +65,7 @@ async def test_setup_entry(
|
|||
async def test_setup_zha(hass: HomeAssistant, addon_store_info) -> None:
|
||||
"""Test zha gets the right config."""
|
||||
mock_integration(hass, MockModule("hassio"))
|
||||
await async_setup_component(hass, HASSIO_DOMAIN, {})
|
||||
|
||||
# Setup the config entry
|
||||
config_entry = MockConfigEntry(
|
||||
|
@ -110,6 +114,7 @@ async def test_setup_zha_multipan(
|
|||
) -> None:
|
||||
"""Test zha gets the right config."""
|
||||
mock_integration(hass, MockModule("hassio"))
|
||||
await async_setup_component(hass, HASSIO_DOMAIN, {})
|
||||
|
||||
addon_info.return_value["options"]["device"] = "/dev/ttyAMA1"
|
||||
|
||||
|
@ -160,6 +165,7 @@ async def test_setup_zha_multipan_other_device(
|
|||
) -> None:
|
||||
"""Test zha gets the right config."""
|
||||
mock_integration(hass, MockModule("hassio"))
|
||||
await async_setup_component(hass, HASSIO_DOMAIN, {})
|
||||
|
||||
addon_info.return_value["options"]["device"] = "/dev/not_yellow_radio"
|
||||
|
||||
|
@ -205,9 +211,32 @@ async def test_setup_zha_multipan_other_device(
|
|||
assert config_entry.title == "Yellow"
|
||||
|
||||
|
||||
async def test_setup_entry_no_hassio(hass: HomeAssistant) -> None:
|
||||
"""Test setup of a config entry without hassio."""
|
||||
# Setup the config entry
|
||||
config_entry = MockConfigEntry(
|
||||
data={},
|
||||
domain=DOMAIN,
|
||||
options={},
|
||||
title="Home Assistant Yellow",
|
||||
)
|
||||
config_entry.add_to_hass(hass)
|
||||
assert len(hass.config_entries.async_entries()) == 1
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.homeassistant_yellow.get_os_info"
|
||||
) as mock_get_os_info:
|
||||
assert not await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert len(mock_get_os_info.mock_calls) == 0
|
||||
assert len(hass.config_entries.async_entries()) == 0
|
||||
|
||||
|
||||
async def test_setup_entry_wrong_board(hass: HomeAssistant) -> None:
|
||||
"""Test setup of a config entry with wrong board type."""
|
||||
mock_integration(hass, MockModule("hassio"))
|
||||
await async_setup_component(hass, HASSIO_DOMAIN, {})
|
||||
|
||||
# Setup the config entry
|
||||
config_entry = MockConfigEntry(
|
||||
|
@ -233,6 +262,7 @@ async def test_setup_entry_wrong_board(hass: HomeAssistant) -> None:
|
|||
async def test_setup_entry_wait_hassio(hass: HomeAssistant) -> None:
|
||||
"""Test setup of a config entry when hassio has not fetched os_info."""
|
||||
mock_integration(hass, MockModule("hassio"))
|
||||
await async_setup_component(hass, HASSIO_DOMAIN, {})
|
||||
|
||||
# Setup the config entry
|
||||
config_entry = MockConfigEntry(
|
||||
|
@ -258,6 +288,7 @@ async def test_setup_entry_addon_info_fails(
|
|||
) -> None:
|
||||
"""Test setup of a config entry when fetching addon info fails."""
|
||||
mock_integration(hass, MockModule("hassio"))
|
||||
await async_setup_component(hass, HASSIO_DOMAIN, {})
|
||||
addon_store_info.side_effect = HassioAPIError("Boom")
|
||||
|
||||
# Setup the config entry
|
||||
|
@ -285,6 +316,7 @@ async def test_setup_entry_addon_not_running(
|
|||
) -> None:
|
||||
"""Test the addon is started if it is not running."""
|
||||
mock_integration(hass, MockModule("hassio"))
|
||||
await async_setup_component(hass, HASSIO_DOMAIN, {})
|
||||
|
||||
# Setup the config entry
|
||||
config_entry = MockConfigEntry(
|
||||
|
|
Loading…
Add table
Reference in a new issue