Remove hardkernel config entry if hassio is not present (#109680)

This commit is contained in:
Erik Montnemery 2024-02-05 12:25:26 +01:00 committed by GitHub
parent c096ac56db
commit 93e0810938
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 37 additions and 2 deletions

View file

@ -2,8 +2,10 @@
from unittest.mock import patch
from homeassistant.components.hardkernel.const import DOMAIN
from homeassistant.components.hassio import DOMAIN as HASSIO_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(
@ -30,9 +33,30 @@ async def test_setup_entry(hass: HomeAssistant) -> None:
assert len(mock_get_os_info.mock_calls) == 1
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="Hardkernel",
)
config_entry.add_to_hass(hass)
assert len(hass.config_entries.async_entries()) == 1
with patch("homeassistant.components.hardkernel.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(
@ -58,6 +82,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(