diff --git a/homeassistant/components/accuweather/__init__.py b/homeassistant/components/accuweather/__init__.py index b2ec7e0224bed5..90b939ab3b96d1 100644 --- a/homeassistant/components/accuweather/__init__.py +++ b/homeassistant/components/accuweather/__init__.py @@ -8,7 +8,6 @@ from async_timeout import timeout from homeassistant.const import CONF_API_KEY -from homeassistant.core import Config, HomeAssistant from homeassistant.exceptions import ConfigEntryNotReady from homeassistant.helpers.aiohttp_client import async_get_clientsession from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed @@ -26,12 +25,6 @@ PLATFORMS = ["sensor", "weather"] -async def async_setup(hass: HomeAssistant, config: Config) -> bool: - """Set up configured AccuWeather.""" - hass.data.setdefault(DOMAIN, {}) - return True - - async def async_setup_entry(hass, config_entry) -> bool: """Set up AccuWeather as config entry.""" api_key = config_entry.data[CONF_API_KEY] @@ -52,7 +45,7 @@ async def async_setup_entry(hass, config_entry) -> bool: undo_listener = config_entry.add_update_listener(update_listener) - hass.data[DOMAIN][config_entry.entry_id] = { + hass.data.setdefault(DOMAIN, {})[config_entry.entry_id] = { COORDINATOR: coordinator, UNDO_UPDATE_LISTENER: undo_listener, } diff --git a/homeassistant/components/adguard/__init__.py b/homeassistant/components/adguard/__init__.py index 04d266e7d9b325..0f10d20ec593f4 100644 --- a/homeassistant/components/adguard/__init__.py +++ b/homeassistant/components/adguard/__init__.py @@ -34,7 +34,6 @@ from homeassistant.helpers import config_validation as cv from homeassistant.helpers.aiohttp_client import async_get_clientsession from homeassistant.helpers.entity import Entity -from homeassistant.helpers.typing import ConfigType _LOGGER = logging.getLogger(__name__) @@ -49,11 +48,6 @@ PLATFORMS = ["sensor", "switch"] -async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: - """Set up the AdGuard Home components.""" - return True - - async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Set up AdGuard Home from a config entry.""" session = async_get_clientsession(hass, entry.data[CONF_VERIFY_SSL]) diff --git a/homeassistant/components/airnow/__init__.py b/homeassistant/components/airnow/__init__.py index 1732445c566c0d..04e1567e067ab1 100644 --- a/homeassistant/components/airnow/__init__.py +++ b/homeassistant/components/airnow/__init__.py @@ -38,11 +38,6 @@ PLATFORMS = ["sensor"] -async def async_setup(hass: HomeAssistant, config: dict): - """Set up the AirNow component.""" - return True - - async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry): """Set up AirNow from a config entry.""" api_key = entry.data[CONF_API_KEY] diff --git a/homeassistant/components/deconz/__init__.py b/homeassistant/components/deconz/__init__.py index 1b8c47d36a2f41..8b609fe312696d 100644 --- a/homeassistant/components/deconz/__init__.py +++ b/homeassistant/components/deconz/__init__.py @@ -20,11 +20,6 @@ ) -async def async_setup(hass, config): - """Old way of setting up deCONZ integrations.""" - return True - - async def async_setup_entry(hass, config_entry): """Set up a deCONZ bridge for a config entry. diff --git a/homeassistant/components/dsmr/__init__.py b/homeassistant/components/dsmr/__init__.py index 09383f8c4aa90b..f130f500545d61 100644 --- a/homeassistant/components/dsmr/__init__.py +++ b/homeassistant/components/dsmr/__init__.py @@ -9,11 +9,6 @@ from .const import DATA_LISTENER, DATA_TASK, DOMAIN, PLATFORMS -async def async_setup(hass, config: dict): - """Set up the DSMR platform.""" - return True - - async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry): """Set up DSMR from a config entry.""" hass.data.setdefault(DOMAIN, {}) diff --git a/homeassistant/components/elgato/__init__.py b/homeassistant/components/elgato/__init__.py index 4f7731c122d694..22d6040678008e 100644 --- a/homeassistant/components/elgato/__init__.py +++ b/homeassistant/components/elgato/__init__.py @@ -9,16 +9,10 @@ from homeassistant.core import HomeAssistant from homeassistant.exceptions import ConfigEntryNotReady from homeassistant.helpers.aiohttp_client import async_get_clientsession -from homeassistant.helpers.typing import ConfigType from .const import DATA_ELGATO_CLIENT, DOMAIN -async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: - """Set up the Elgato Key Light components.""" - return True - - async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Set up Elgato Key Light from a config entry.""" session = async_get_clientsession(hass) diff --git a/homeassistant/components/esphome/__init__.py b/homeassistant/components/esphome/__init__.py index 0cb6cd94e083c3..02d6309fe7f02f 100644 --- a/homeassistant/components/esphome/__init__.py +++ b/homeassistant/components/esphome/__init__.py @@ -42,7 +42,7 @@ from homeassistant.helpers.service import async_set_service_schema from homeassistant.helpers.storage import Store from homeassistant.helpers.template import Template -from homeassistant.helpers.typing import ConfigType, HomeAssistantType +from homeassistant.helpers.typing import HomeAssistantType # Import config flow so that it's added to the registry from .entry_data import RuntimeEntryData @@ -56,11 +56,6 @@ CONFIG_SCHEMA = vol.Schema({}, extra=vol.ALLOW_EXTRA) -async def async_setup(hass: HomeAssistantType, config: ConfigType) -> bool: - """Stub to allow setting up this component.""" - return True - - async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry) -> bool: """Set up the esphome component.""" hass.data.setdefault(DOMAIN, {}) diff --git a/homeassistant/components/fireservicerota/__init__.py b/homeassistant/components/fireservicerota/__init__.py index 513a572b2c2e44..135653dfd73c5e 100644 --- a/homeassistant/components/fireservicerota/__init__.py +++ b/homeassistant/components/fireservicerota/__init__.py @@ -29,12 +29,6 @@ PLATFORMS = [SENSOR_DOMAIN, BINARYSENSOR_DOMAIN, SWITCH_DOMAIN] -async def async_setup(hass: HomeAssistant, config: dict) -> bool: - """Set up the FireServiceRota component.""" - - return True - - async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Set up FireServiceRota from a config entry.""" diff --git a/homeassistant/components/forked_daapd/__init__.py b/homeassistant/components/forked_daapd/__init__.py index 45cefc739b9055..0186b18ee74f98 100644 --- a/homeassistant/components/forked_daapd/__init__.py +++ b/homeassistant/components/forked_daapd/__init__.py @@ -4,11 +4,6 @@ from .const import DOMAIN, HASS_DATA_REMOVE_LISTENERS_KEY, HASS_DATA_UPDATER_KEY -async def async_setup(hass, config): - """Set up the forked-daapd component.""" - return True - - async def async_setup_entry(hass, entry): """Set up forked-daapd from a config entry by forwarding to platform.""" hass.async_create_task( diff --git a/homeassistant/components/fritzbox_callmonitor/__init__.py b/homeassistant/components/fritzbox_callmonitor/__init__.py index 0527b7164d39f7..0ba0de598497f7 100644 --- a/homeassistant/components/fritzbox_callmonitor/__init__.py +++ b/homeassistant/components/fritzbox_callmonitor/__init__.py @@ -21,11 +21,6 @@ _LOGGER = logging.getLogger(__name__) -async def async_setup(hass, config): - """Set up the fritzbox_callmonitor integration.""" - return True - - async def async_setup_entry(hass, config_entry): """Set up the fritzbox_callmonitor platforms.""" fritzbox_phonebook = FritzBoxPhonebook( diff --git a/homeassistant/components/gios/__init__.py b/homeassistant/components/gios/__init__.py index 005cc4c9c260a6..d95ce6615ebf3c 100644 --- a/homeassistant/components/gios/__init__.py +++ b/homeassistant/components/gios/__init__.py @@ -5,7 +5,6 @@ from async_timeout import timeout from gios import ApiError, Gios, InvalidSensorsData, NoStationError -from homeassistant.core import Config, HomeAssistant from homeassistant.exceptions import ConfigEntryNotReady from homeassistant.helpers.aiohttp_client import async_get_clientsession from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed @@ -15,11 +14,6 @@ _LOGGER = logging.getLogger(__name__) -async def async_setup(hass: HomeAssistant, config: Config) -> bool: - """Set up configured GIOS.""" - return True - - async def async_setup_entry(hass, config_entry): """Set up GIOS as config entry.""" station_id = config_entry.data[CONF_STATION_ID] diff --git a/homeassistant/components/gogogate2/__init__.py b/homeassistant/components/gogogate2/__init__.py index 6d0318b99ad627..90279f68d4b98f 100644 --- a/homeassistant/components/gogogate2/__init__.py +++ b/homeassistant/components/gogogate2/__init__.py @@ -14,11 +14,6 @@ PLATFORMS = [COVER, SENSOR] -async def async_setup(hass: HomeAssistant, base_config: dict) -> bool: - """Set up for Gogogate2 controllers.""" - return True - - async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool: """Do setup of Gogogate2.""" diff --git a/homeassistant/components/squeezebox/__init__.py b/homeassistant/components/squeezebox/__init__.py index e298bee7b07839..f276daac56ac10 100644 --- a/homeassistant/components/squeezebox/__init__.py +++ b/homeassistant/components/squeezebox/__init__.py @@ -11,11 +11,6 @@ _LOGGER = logging.getLogger(__name__) -async def async_setup(hass: HomeAssistant, config: dict): - """Set up the Logitech Squeezebox component.""" - return True - - async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry): """Set up Logitech Squeezebox from a config entry.""" hass.async_create_task( diff --git a/homeassistant/components/starline/__init__.py b/homeassistant/components/starline/__init__.py index 3025a7b4c119c0..2eb729721d3fca 100644 --- a/homeassistant/components/starline/__init__.py +++ b/homeassistant/components/starline/__init__.py @@ -3,7 +3,7 @@ from homeassistant.config_entries import ConfigEntry from homeassistant.const import CONF_SCAN_INTERVAL -from homeassistant.core import Config, HomeAssistant +from homeassistant.core import HomeAssistant from homeassistant.exceptions import ConfigEntryNotReady from .account import StarlineAccount @@ -19,11 +19,6 @@ ) -async def async_setup(hass: HomeAssistant, config: Config) -> bool: - """Set up configured StarLine.""" - return True - - async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool: """Set up the StarLine device from a config entry.""" account = StarlineAccount(hass, config_entry) diff --git a/homeassistant/components/tasmota/__init__.py b/homeassistant/components/tasmota/__init__.py index 0b42725cdcf65f..83baae9c19c563 100644 --- a/homeassistant/components/tasmota/__init__.py +++ b/homeassistant/components/tasmota/__init__.py @@ -24,7 +24,6 @@ EVENT_DEVICE_REGISTRY_UPDATED, async_entries_for_config_entry, ) -from homeassistant.helpers.typing import HomeAssistantType from . import device_automation, discovery from .const import ( @@ -38,11 +37,6 @@ _LOGGER = logging.getLogger(__name__) -async def async_setup(hass: HomeAssistantType, config: dict): - """Set up the Tasmota component.""" - return True - - async def async_setup_entry(hass, entry): """Set up Tasmota from a config entry.""" websocket_api.async_register_command(hass, websocket_remove_device) diff --git a/homeassistant/components/upb/__init__.py b/homeassistant/components/upb/__init__.py index bd591447472944..ba9faeb1797c8c 100644 --- a/homeassistant/components/upb/__init__.py +++ b/homeassistant/components/upb/__init__.py @@ -4,9 +4,8 @@ import upb_lib from homeassistant.const import ATTR_COMMAND, CONF_FILE_PATH, CONF_HOST -from homeassistant.core import HomeAssistant, callback +from homeassistant.core import callback from homeassistant.helpers.entity import Entity -from homeassistant.helpers.typing import ConfigType from .const import ( ATTR_ADDRESS, @@ -19,11 +18,6 @@ PLATFORMS = ["light", "scene"] -async def async_setup(hass: HomeAssistant, hass_config: ConfigType) -> bool: - """Set up the UPB platform.""" - return True - - async def async_setup_entry(hass, config_entry): """Set up a new config_entry for UPB PIM.""" diff --git a/homeassistant/components/volumio/__init__.py b/homeassistant/components/volumio/__init__.py index ec1fdec685a23a..a9c6fb746aaec3 100644 --- a/homeassistant/components/volumio/__init__.py +++ b/homeassistant/components/volumio/__init__.py @@ -14,11 +14,6 @@ PLATFORMS = ["media_player"] -async def async_setup(hass: HomeAssistant, config: dict): - """Set up the Volumio component.""" - return True - - async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry): """Set up Volumio from a config entry.""" diff --git a/homeassistant/components/wiffi/__init__.py b/homeassistant/components/wiffi/__init__.py index 3b85a7ff0f8b71..36f6e641508fb5 100644 --- a/homeassistant/components/wiffi/__init__.py +++ b/homeassistant/components/wiffi/__init__.py @@ -33,11 +33,6 @@ PLATFORMS = ["sensor", "binary_sensor"] -async def async_setup(hass: HomeAssistant, config: dict): - """Set up the wiffi component. config contains data from configuration.yaml.""" - return True - - async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry): """Set up wiffi from a config entry, config_entry contains data from config entry database.""" if not config_entry.update_listeners: diff --git a/homeassistant/components/wled/__init__.py b/homeassistant/components/wled/__init__.py index 2ec029314153bc..069c12a2d061ec 100644 --- a/homeassistant/components/wled/__init__.py +++ b/homeassistant/components/wled/__init__.py @@ -16,7 +16,6 @@ from homeassistant.core import HomeAssistant from homeassistant.exceptions import ConfigEntryNotReady from homeassistant.helpers.aiohttp_client import async_get_clientsession -from homeassistant.helpers.typing import ConfigType from homeassistant.helpers.update_coordinator import ( CoordinatorEntity, DataUpdateCoordinator, @@ -37,11 +36,6 @@ _LOGGER = logging.getLogger(__name__) -async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: - """Set up the WLED components.""" - return True - - async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Set up WLED from a config entry.""" diff --git a/homeassistant/setup.py b/homeassistant/setup.py index c22e660e553b2a..41989f762ac43b 100644 --- a/homeassistant/setup.py +++ b/homeassistant/setup.py @@ -147,7 +147,7 @@ def log_error(msg: str, link: str | None = None) -> None: return False if integration.disabled: - log_error(f"dependency is disabled - {integration.disabled}") + log_error(f"Dependency is disabled - {integration.disabled}") return False # Validate all dependencies exist and there are no circular dependencies @@ -197,6 +197,8 @@ def log_error(msg: str, link: str | None = None) -> None: SLOW_SETUP_WARNING, ) + task = None + result = True try: if hasattr(component, "async_setup"): task = component.async_setup(hass, processed_config) # type: ignore @@ -206,13 +208,14 @@ def log_error(msg: str, link: str | None = None) -> None: task = hass.loop.run_in_executor( None, component.setup, hass, processed_config # type: ignore ) - else: - log_error("No setup function defined.") + elif not hasattr(component, "async_setup_entry"): + log_error("No setup or config entry setup function defined.") hass.data[DATA_SETUP_STARTED].pop(domain) return False - async with hass.timeout.async_timeout(SLOW_SETUP_MAX_WAIT, domain): - result = await task + if task: + async with hass.timeout.async_timeout(SLOW_SETUP_MAX_WAIT, domain): + result = await task except asyncio.TimeoutError: _LOGGER.error( "Setup of %s is taking longer than %s seconds." diff --git a/script/scaffold/templates/config_flow/integration/__init__.py b/script/scaffold/templates/config_flow/integration/__init__.py index 24a0c1d73509c8..6c187d1dafece3 100644 --- a/script/scaffold/templates/config_flow/integration/__init__.py +++ b/script/scaffold/templates/config_flow/integration/__init__.py @@ -2,7 +2,6 @@ from __future__ import annotations import asyncio -from typing import Any from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant @@ -14,11 +13,6 @@ PLATFORMS = ["light"] -async def async_setup(hass: HomeAssistant, config: dict[str, Any]) -> bool: - """Set up the NEW_NAME component.""" - return True - - async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Set up NEW_NAME from a config entry.""" # TODO Store an API object for your platforms to access diff --git a/script/scaffold/templates/config_flow/tests/test_config_flow.py b/script/scaffold/templates/config_flow/tests/test_config_flow.py index 8205fdbeda4960..674cb921cdd8d5 100644 --- a/script/scaffold/templates/config_flow/tests/test_config_flow.py +++ b/script/scaffold/templates/config_flow/tests/test_config_flow.py @@ -20,8 +20,6 @@ async def test_form(hass: HomeAssistant) -> None: "homeassistant.components.NEW_DOMAIN.config_flow.PlaceholderHub.authenticate", return_value=True, ), patch( - "homeassistant.components.NEW_DOMAIN.async_setup", return_value=True - ) as mock_setup, patch( "homeassistant.components.NEW_DOMAIN.async_setup_entry", return_value=True, ) as mock_setup_entry: @@ -42,7 +40,6 @@ async def test_form(hass: HomeAssistant) -> None: "username": "test-username", "password": "test-password", } - assert len(mock_setup.mock_calls) == 1 assert len(mock_setup_entry.mock_calls) == 1 diff --git a/script/scaffold/templates/config_flow_discovery/integration/__init__.py b/script/scaffold/templates/config_flow_discovery/integration/__init__.py index 24a0c1d73509c8..6c187d1dafece3 100644 --- a/script/scaffold/templates/config_flow_discovery/integration/__init__.py +++ b/script/scaffold/templates/config_flow_discovery/integration/__init__.py @@ -2,7 +2,6 @@ from __future__ import annotations import asyncio -from typing import Any from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant @@ -14,11 +13,6 @@ PLATFORMS = ["light"] -async def async_setup(hass: HomeAssistant, config: dict[str, Any]) -> bool: - """Set up the NEW_NAME component.""" - return True - - async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Set up NEW_NAME from a config entry.""" # TODO Store an API object for your platforms to access diff --git a/tests/common.py b/tests/common.py index 984b35716f0de6..32d2742f4d8f66 100644 --- a/tests/common.py +++ b/tests/common.py @@ -566,7 +566,7 @@ def __init__( if platform_schema_base is not None: self.PLATFORM_SCHEMA_BASE = platform_schema_base - if setup is not None: + if setup: # We run this in executor, wrap it in function self.setup = lambda *args: setup(*args) diff --git a/tests/components/airnow/test_config_flow.py b/tests/components/airnow/test_config_flow.py index f7533b7f5ac799..9937e899643d88 100644 --- a/tests/components/airnow/test_config_flow.py +++ b/tests/components/airnow/test_config_flow.py @@ -75,9 +75,7 @@ async def test_form(hass): assert result["type"] == data_entry_flow.RESULT_TYPE_FORM assert result["errors"] == {} - with patch("pyairnow.WebServiceAPI._get", return_value=MOCK_RESPONSE,), patch( - "homeassistant.components.airnow.async_setup", return_value=True - ) as mock_setup, patch( + with patch("pyairnow.WebServiceAPI._get", return_value=MOCK_RESPONSE), patch( "homeassistant.components.airnow.async_setup_entry", return_value=True, ) as mock_setup_entry: @@ -90,7 +88,6 @@ async def test_form(hass): assert result2["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY assert result2["data"] == CONFIG - assert len(mock_setup.mock_calls) == 1 assert len(mock_setup_entry.mock_calls) == 1 diff --git a/tests/components/deconz/test_config_flow.py b/tests/components/deconz/test_config_flow.py index 8f9a597e00c8b5..4380b8c6021634 100644 --- a/tests/components/deconz/test_config_flow.py +++ b/tests/components/deconz/test_config_flow.py @@ -539,8 +539,6 @@ async def test_flow_hassio_discovery(hass): assert result["description_placeholders"] == {"addon": "Mock Addon"} with patch( - "homeassistant.components.deconz.async_setup", return_value=True - ) as mock_setup, patch( "homeassistant.components.deconz.async_setup_entry", return_value=True, ) as mock_setup_entry: @@ -555,7 +553,6 @@ async def test_flow_hassio_discovery(hass): CONF_PORT: 80, CONF_API_KEY: API_KEY, } - assert len(mock_setup.mock_calls) == 1 assert len(mock_setup_entry.mock_calls) == 1 diff --git a/tests/components/dsmr/test_sensor.py b/tests/components/dsmr/test_sensor.py index 9aaa558e92ec00..e037585f8ff4ff 100644 --- a/tests/components/dsmr/test_sensor.py +++ b/tests/components/dsmr/test_sensor.py @@ -39,7 +39,7 @@ async def test_setup_platform(hass, dsmr_connection_fixture): serial_data = {"serial_id": "1234", "serial_id_gas": "5678"} - with patch("homeassistant.components.dsmr.async_setup", return_value=True), patch( + with patch( "homeassistant.components.dsmr.async_setup_entry", return_value=True ), patch( "homeassistant.components.dsmr.config_flow._validate_dsmr_connection", diff --git a/tests/components/fireservicerota/test_config_flow.py b/tests/components/fireservicerota/test_config_flow.py index 69f37bc3ad42a8..752adb2edc53bc 100644 --- a/tests/components/fireservicerota/test_config_flow.py +++ b/tests/components/fireservicerota/test_config_flow.py @@ -78,8 +78,6 @@ async def test_step_user(hass): with patch( "homeassistant.components.fireservicerota.config_flow.FireServiceRota" ) as mock_fsr, patch( - "homeassistant.components.fireservicerota.async_setup", return_value=True - ) as mock_setup, patch( "homeassistant.components.fireservicerota.async_setup_entry", return_value=True, ) as mock_setup_entry: @@ -108,5 +106,4 @@ async def test_step_user(hass): }, } - assert len(mock_setup.mock_calls) == 1 assert len(mock_setup_entry.mock_calls) == 1 diff --git a/tests/components/gogogate2/test_config_flow.py b/tests/components/gogogate2/test_config_flow.py index 2d19ee70609242..621ea4d52328e1 100644 --- a/tests/components/gogogate2/test_config_flow.py +++ b/tests/components/gogogate2/test_config_flow.py @@ -26,11 +26,10 @@ MOCK_MAC_ADDR = "AA:BB:CC:DD:EE:FF" -@patch("homeassistant.components.gogogate2.async_setup", return_value=True) @patch("homeassistant.components.gogogate2.async_setup_entry", return_value=True) @patch("homeassistant.components.gogogate2.common.GogoGate2Api") async def test_auth_fail( - gogogate2api_mock, async_setup_entry_mock, async_setup_mock, hass: HomeAssistant + gogogate2api_mock, async_setup_entry_mock, hass: HomeAssistant ) -> None: """Test authorization failures.""" api: GogoGate2Api = MagicMock(spec=GogoGate2Api) diff --git a/tests/components/squeezebox/test_config_flow.py b/tests/components/squeezebox/test_config_flow.py index 2dae2f78d017c8..cd734e1627cdbc 100644 --- a/tests/components/squeezebox/test_config_flow.py +++ b/tests/components/squeezebox/test_config_flow.py @@ -45,8 +45,6 @@ async def patch_async_query_unauthorized(self, *args): async def test_user_form(hass): """Test user-initiated flow, including discovery and the edit step.""" with patch("pysqueezebox.Server.async_query", return_value={"uuid": UUID},), patch( - "homeassistant.components.squeezebox.async_setup", return_value=True - ) as mock_setup, patch( "homeassistant.components.squeezebox.async_setup_entry", return_value=True, ) as mock_setup_entry, patch( @@ -77,7 +75,6 @@ async def test_user_form(hass): } await hass.async_block_till_done() - assert len(mock_setup.mock_calls) == 1 assert len(mock_setup_entry.mock_calls) == 1 @@ -111,8 +108,6 @@ async def test_user_form_duplicate(hass): "homeassistant.components.squeezebox.config_flow.async_discover", mock_discover, ), patch("homeassistant.components.squeezebox.config_flow.TIMEOUT", 0.1), patch( - "homeassistant.components.squeezebox.async_setup", return_value=True - ), patch( "homeassistant.components.squeezebox.async_setup_entry", return_value=True, ): @@ -204,8 +199,6 @@ async def test_discovery_no_uuid(hass): async def test_import(hass): """Test handling of configuration imported.""" with patch("pysqueezebox.Server.async_query", return_value={"uuid": UUID},), patch( - "homeassistant.components.squeezebox.async_setup", return_value=True - ) as mock_setup, patch( "homeassistant.components.squeezebox.async_setup_entry", return_value=True, ) as mock_setup_entry: @@ -217,7 +210,6 @@ async def test_import(hass): assert result["type"] == RESULT_TYPE_CREATE_ENTRY await hass.async_block_till_done() - assert len(mock_setup.mock_calls) == 1 assert len(mock_setup_entry.mock_calls) == 1 @@ -253,8 +245,6 @@ async def test_import_bad_auth(hass): async def test_import_existing(hass): """Test handling of configuration import of existing server.""" with patch( - "homeassistant.components.squeezebox.async_setup", return_value=True - ), patch( "homeassistant.components.squeezebox.async_setup_entry", return_value=True, ), patch( diff --git a/tests/components/upb/test_config_flow.py b/tests/components/upb/test_config_flow.py index 779c66f08aa02f..1abcaa958b7263 100644 --- a/tests/components/upb/test_config_flow.py +++ b/tests/components/upb/test_config_flow.py @@ -43,8 +43,6 @@ async def test_full_upb_flow_with_serial_port(hass): await setup.async_setup_component(hass, "persistent_notification", {}) with mocked_upb(), patch( - "homeassistant.components.upb.async_setup", return_value=True - ) as mock_setup, patch( "homeassistant.components.upb.async_setup_entry", return_value=True ) as mock_setup_entry: flow = await hass.config_entries.flow.async_init( @@ -69,7 +67,6 @@ async def test_full_upb_flow_with_serial_port(hass): "host": "serial:///dev/ttyS0:115200", "file_path": "upb.upe", } - assert len(mock_setup.mock_calls) == 1 assert len(mock_setup_entry.mock_calls) == 1 @@ -116,8 +113,6 @@ async def test_form_import(hass): await setup.async_setup_component(hass, "persistent_notification", {}) with mocked_upb(), patch( - "homeassistant.components.upb.async_setup", return_value=True - ) as mock_setup, patch( "homeassistant.components.upb.async_setup_entry", return_value=True ) as mock_setup_entry: result = await hass.config_entries.flow.async_init( @@ -131,7 +126,6 @@ async def test_form_import(hass): assert result["title"] == "UPB" assert result["data"] == {"host": "tcp://42.4.2.42", "file_path": "upb.upe"} - assert len(mock_setup.mock_calls) == 1 assert len(mock_setup_entry.mock_calls) == 1 diff --git a/tests/components/volumio/test_config_flow.py b/tests/components/volumio/test_config_flow.py index 86b5027cd3d7f7..a0d3fc85ee34b0 100644 --- a/tests/components/volumio/test_config_flow.py +++ b/tests/components/volumio/test_config_flow.py @@ -42,8 +42,6 @@ async def test_form(hass): "homeassistant.components.volumio.config_flow.Volumio.get_system_info", return_value=TEST_SYSTEM_INFO, ), patch( - "homeassistant.components.volumio.async_setup", return_value=True - ) as mock_setup, patch( "homeassistant.components.volumio.async_setup_entry", return_value=True, ) as mock_setup_entry: @@ -57,7 +55,6 @@ async def test_form(hass): assert result2["title"] == "TestVolumio" assert result2["data"] == {**TEST_SYSTEM_INFO, **TEST_CONNECTION} - assert len(mock_setup.mock_calls) == 1 assert len(mock_setup_entry.mock_calls) == 1 @@ -82,7 +79,7 @@ async def test_form_updates_unique_id(hass): with patch( "homeassistant.components.volumio.config_flow.Volumio.get_system_info", return_value=TEST_SYSTEM_INFO, - ), patch("homeassistant.components.volumio.async_setup", return_value=True), patch( + ), patch( "homeassistant.components.volumio.async_setup_entry", return_value=True, ): @@ -110,8 +107,6 @@ async def test_empty_system_info(hass): "homeassistant.components.volumio.config_flow.Volumio.get_system_info", return_value={}, ), patch( - "homeassistant.components.volumio.async_setup", return_value=True - ) as mock_setup, patch( "homeassistant.components.volumio.async_setup_entry", return_value=True, ) as mock_setup_entry: @@ -130,7 +125,6 @@ async def test_empty_system_info(hass): "id": None, } - assert len(mock_setup.mock_calls) == 1 assert len(mock_setup_entry.mock_calls) == 1 @@ -183,8 +177,6 @@ async def test_discovery(hass): "homeassistant.components.volumio.config_flow.Volumio.get_system_info", return_value=TEST_SYSTEM_INFO, ), patch( - "homeassistant.components.volumio.async_setup", return_value=True - ) as mock_setup, patch( "homeassistant.components.volumio.async_setup_entry", return_value=True, ) as mock_setup_entry: @@ -201,7 +193,6 @@ async def test_discovery(hass): assert result2["result"] assert result2["result"].unique_id == TEST_DISCOVERY_RESULT["id"] - assert len(mock_setup.mock_calls) == 1 assert len(mock_setup_entry.mock_calls) == 1 @@ -257,8 +248,6 @@ async def test_discovery_updates_unique_id(hass): entry.add_to_hass(hass) with patch( - "homeassistant.components.volumio.async_setup", return_value=True - ) as mock_setup, patch( "homeassistant.components.volumio.async_setup_entry", return_value=True, ) as mock_setup_entry: @@ -271,5 +260,4 @@ async def test_discovery_updates_unique_id(hass): assert result["reason"] == "already_configured" assert entry.data == TEST_DISCOVERY_RESULT - assert len(mock_setup.mock_calls) == 1 assert len(mock_setup_entry.mock_calls) == 1 diff --git a/tests/test_setup.py b/tests/test_setup.py index abb8f7569897f4..13c71e045f0731 100644 --- a/tests/test_setup.py +++ b/tests/test_setup.py @@ -3,7 +3,7 @@ import asyncio import os import threading -from unittest.mock import Mock, patch +from unittest.mock import AsyncMock, Mock, patch import pytest import voluptuous as vol @@ -600,3 +600,29 @@ async def test_integration_disabled(hass, caplog): result = await setup.async_setup_component(hass, "test_component1", {}) assert not result assert disabled_reason in caplog.text + + +async def test_integration_no_setup(hass, caplog): + """Test we fail integration setup without setup functions.""" + mock_integration( + hass, + MockModule("test_integration_without_setup", setup=False), + ) + result = await setup.async_setup_component( + hass, "test_integration_without_setup", {} + ) + assert not result + assert "No setup or config entry setup function defined" in caplog.text + + +async def test_integration_only_setup_entry(hass): + """Test we have an integration with only a setup entry method.""" + mock_integration( + hass, + MockModule( + "test_integration_only_entry", + setup=False, + async_setup_entry=AsyncMock(return_value=True), + ), + ) + assert await setup.async_setup_component(hass, "test_integration_only_entry", {})