Remove homeassistant_green config entry if hassio is not present (#109685)
parent
40166ed51e
commit
048d9e75e6
|
@ -1,7 +1,7 @@
|
|||
"""The Home Assistant Green 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.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import ConfigEntryNotReady
|
||||
|
@ -9,6 +9,11 @@ from homeassistant.exceptions import ConfigEntryNotReady
|
|||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""Set up a Home Assistant Green 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_green",
|
||||
"name": "Home Assistant Green",
|
||||
"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_green",
|
||||
"integration_type": "hardware"
|
||||
}
|
||||
|
|
|
@ -3,9 +3,11 @@ from unittest.mock import patch
|
|||
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.hassio import DOMAIN as HASSIO_DOMAIN
|
||||
from homeassistant.components.homeassistant_green.const import 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
|
||||
|
||||
|
@ -36,6 +38,7 @@ def mock_set_green_settings():
|
|||
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_green.async_setup_entry",
|
||||
|
@ -60,6 +63,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(
|
||||
|
@ -115,6 +119,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(
|
||||
|
@ -146,6 +151,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(
|
||||
|
@ -171,6 +177,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(
|
||||
|
@ -196,6 +203,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_green.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(
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
"""Test the Home Assistant Green integration."""
|
||||
from unittest.mock import patch
|
||||
|
||||
from homeassistant.components.hassio import DOMAIN as HASSIO_DOMAIN
|
||||
from homeassistant.components.homeassistant_green.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
|
||||
|
||||
|
@ -11,6 +13,7 @@ from tests.common import MockConfigEntry, MockModule, mock_integration
|
|||
async def test_setup_entry(hass: HomeAssistant) -> None:
|
||||
"""Test setup of a config entry."""
|
||||
mock_integration(hass, MockModule("hassio"))
|
||||
await async_setup_component(hass, HASSIO_DOMAIN, {})
|
||||
|
||||
# Setup the config entry
|
||||
config_entry = MockConfigEntry(
|
||||
|
@ -32,9 +35,32 @@ async def test_setup_entry(hass: HomeAssistant) -> None:
|
|||
assert await hass.config_entries.async_unload(config_entry.entry_id)
|
||||
|
||||
|
||||
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 Green",
|
||||
)
|
||||
config_entry.add_to_hass(hass)
|
||||
assert len(hass.config_entries.async_entries()) == 1
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.homeassistant_green.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(
|
||||
|
@ -60,6 +86,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(
|
||||
|
|
Loading…
Reference in New Issue