diff --git a/homeassistant/components/raspberry_pi/__init__.py b/homeassistant/components/raspberry_pi/__init__.py index 3750a1c7068..19697d9b69d 100644 --- a/homeassistant/components/raspberry_pi/__init__.py +++ b/homeassistant/components/raspberry_pi/__init__.py @@ -1,7 +1,7 @@ """The Raspberry Pi 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 Raspberry Pi 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 diff --git a/homeassistant/components/raspberry_pi/manifest.json b/homeassistant/components/raspberry_pi/manifest.json index d30c637d2c3..5ed68154ce1 100644 --- a/homeassistant/components/raspberry_pi/manifest.json +++ b/homeassistant/components/raspberry_pi/manifest.json @@ -1,9 +1,10 @@ { "domain": "raspberry_pi", "name": "Raspberry Pi", + "after_dependencies": ["hassio"], "codeowners": ["@home-assistant/core"], "config_flow": false, - "dependencies": ["hardware", "hassio"], + "dependencies": ["hardware"], "documentation": "https://www.home-assistant.io/integrations/raspberry_pi", "integration_type": "hardware" } diff --git a/tests/components/raspberry_pi/test_hardware.py b/tests/components/raspberry_pi/test_hardware.py index 77236040486..d41fbf2f5e1 100644 --- a/tests/components/raspberry_pi/test_hardware.py +++ b/tests/components/raspberry_pi/test_hardware.py @@ -3,8 +3,10 @@ from unittest.mock import patch import pytest +from homeassistant.components.hassio import DOMAIN as HASSIO_DOMAIN from homeassistant.components.raspberry_pi.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( diff --git a/tests/components/raspberry_pi/test_init.py b/tests/components/raspberry_pi/test_init.py index b0e9ef89582..88518cc00b0 100644 --- a/tests/components/raspberry_pi/test_init.py +++ b/tests/components/raspberry_pi/test_init.py @@ -3,9 +3,11 @@ from unittest.mock import patch import pytest +from homeassistant.components.hassio import DOMAIN as HASSIO_DOMAIN from homeassistant.components.raspberry_pi.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 @@ -23,6 +25,7 @@ def mock_rpi_power(): 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( @@ -46,9 +49,30 @@ async def test_setup_entry(hass: HomeAssistant) -> None: assert len(hass.config_entries.async_entries("rpi_power")) == 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="Raspberry Pi", + ) + config_entry.add_to_hass(hass) + assert len(hass.config_entries.async_entries()) == 1 + + with patch("homeassistant.components.raspberry_pi.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( @@ -74,6 +98,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(