Refactor config integration to use normal functions for setup (#110750)

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
J. Nick Koston 2024-02-16 18:12:33 -06:00 committed by GitHub
parent d7f650ed7c
commit 50770ce436
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 40 additions and 40 deletions

View file

@ -26,6 +26,7 @@ from homeassistant.util.yaml.loader import JSON_TYPE
_DataT = TypeVar("_DataT", dict[str, dict[str, Any]], list[dict[str, Any]])
DOMAIN = "config"
SECTIONS = (
"area_registry",
"auth",
@ -50,24 +51,13 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
hass, "config", "config", "hass:cog", require_admin=True
)
async def setup_panel(panel_name: str) -> None:
"""Set up a panel."""
for panel_name in SECTIONS:
panel = importlib.import_module(f".{panel_name}", __name__)
if not panel:
return
success = await panel.async_setup(hass)
if success:
if panel.async_setup(hass):
key = f"{DOMAIN}.{panel_name}"
hass.bus.async_fire(EVENT_COMPONENT_LOADED, {ATTR_COMPONENT: key})
tasks = [asyncio.create_task(setup_panel(panel_name)) for panel_name in SECTIONS]
if tasks:
await asyncio.wait(tasks)
return True

View file

@ -10,7 +10,8 @@ from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.area_registry import AreaEntry, async_get
async def async_setup(hass: HomeAssistant) -> bool:
@callback
def async_setup(hass: HomeAssistant) -> bool:
"""Enable the Area Registry views."""
websocket_api.async_register_command(hass, websocket_list_areas)
websocket_api.async_register_command(hass, websocket_create_area)

View file

@ -7,7 +7,7 @@ import voluptuous as vol
from homeassistant.auth.models import User
from homeassistant.components import websocket_api
from homeassistant.core import HomeAssistant
from homeassistant.core import HomeAssistant, callback
WS_TYPE_LIST = "config/auth/list"
SCHEMA_WS_LIST = websocket_api.BASE_COMMAND_MESSAGE_SCHEMA.extend(
@ -20,7 +20,8 @@ SCHEMA_WS_DELETE = websocket_api.BASE_COMMAND_MESSAGE_SCHEMA.extend(
)
async def async_setup(hass: HomeAssistant) -> bool:
@callback
def async_setup(hass: HomeAssistant) -> bool:
"""Enable the Home Assistant views."""
websocket_api.async_register_command(
hass, WS_TYPE_LIST, websocket_list, SCHEMA_WS_LIST

View file

@ -7,11 +7,12 @@ import voluptuous as vol
from homeassistant.auth.providers import homeassistant as auth_ha
from homeassistant.components import websocket_api
from homeassistant.core import HomeAssistant
from homeassistant.core import HomeAssistant, callback
from homeassistant.exceptions import Unauthorized
async def async_setup(hass: HomeAssistant) -> bool:
@callback
def async_setup(hass: HomeAssistant) -> bool:
"""Enable the Home Assistant views."""
websocket_api.async_register_command(hass, websocket_create)
websocket_api.async_register_command(hass, websocket_delete)

View file

@ -11,13 +11,14 @@ from homeassistant.components.automation.config import (
)
from homeassistant.config import AUTOMATION_CONFIG_PATH
from homeassistant.const import CONF_ID, SERVICE_RELOAD
from homeassistant.core import HomeAssistant
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers import config_validation as cv, entity_registry as er
from . import ACTION_DELETE, EditIdBasedConfigView
async def async_setup(hass: HomeAssistant) -> bool:
@callback
def async_setup(hass: HomeAssistant) -> bool:
"""Set up the Automation config API."""
async def hook(action: str, config_key: str) -> None:

View file

@ -30,7 +30,8 @@ from homeassistant.loader import (
)
async def async_setup(hass: HomeAssistant) -> bool:
@callback
def async_setup(hass: HomeAssistant) -> bool:
"""Enable the Home Assistant views."""
hass.http.register_view(ConfigManagerEntryIndexView)
hass.http.register_view(ConfigManagerEntryResourceView)

View file

@ -9,13 +9,14 @@ import voluptuous as vol
from homeassistant.components import websocket_api
from homeassistant.components.http import HomeAssistantView, require_admin
from homeassistant.components.sensor import async_update_suggested_units
from homeassistant.core import HomeAssistant
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers import check_config, config_validation as cv
from homeassistant.helpers.aiohttp_client import async_get_clientsession
from homeassistant.util import location, unit_system
async def async_setup(hass: HomeAssistant) -> bool:
@callback
def async_setup(hass: HomeAssistant) -> bool:
"""Set up the Hassbian config."""
hass.http.register_view(CheckConfigView)
websocket_api.async_register_command(hass, websocket_update_config)

View file

@ -17,7 +17,8 @@ from homeassistant.helpers.device_registry import (
)
async def async_setup(hass: HomeAssistant) -> bool:
@callback
def async_setup(hass: HomeAssistant) -> bool:
"""Enable the Device Registry views."""
websocket_api.async_register_command(hass, websocket_list_devices)

View file

@ -18,7 +18,8 @@ from homeassistant.helpers import (
from homeassistant.helpers.json import json_dumps
async def async_setup(hass: HomeAssistant) -> bool:
@callback
def async_setup(hass: HomeAssistant) -> bool:
"""Enable the Entity Registry views."""
websocket_api.async_register_command(hass, websocket_get_entities)

View file

@ -7,13 +7,14 @@ import uuid
from homeassistant.components.scene import DOMAIN, PLATFORM_SCHEMA
from homeassistant.config import SCENE_CONFIG_PATH
from homeassistant.const import CONF_ID, SERVICE_RELOAD
from homeassistant.core import DOMAIN as HA_DOMAIN, HomeAssistant
from homeassistant.core import DOMAIN as HA_DOMAIN, HomeAssistant, callback
from homeassistant.helpers import config_validation as cv, entity_registry as er
from . import ACTION_DELETE, EditIdBasedConfigView
async def async_setup(hass: HomeAssistant) -> bool:
@callback
def async_setup(hass: HomeAssistant) -> bool:
"""Set up the Scene config API."""
async def hook(action: str, config_key: str) -> None:

View file

@ -10,13 +10,14 @@ from homeassistant.components.script.config import (
)
from homeassistant.config import SCRIPT_CONFIG_PATH
from homeassistant.const import SERVICE_RELOAD
from homeassistant.core import HomeAssistant
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers import config_validation as cv, entity_registry as er
from . import ACTION_DELETE, EditKeyBasedConfigView
async def async_setup(hass: HomeAssistant) -> bool:
@callback
def async_setup(hass: HomeAssistant) -> bool:
"""Set up the script config API."""
async def hook(action: str, config_key: str) -> None:

View file

@ -10,10 +10,10 @@ from tests.common import ANY
@pytest.fixture
def client(hass, hass_ws_client):
async def client(hass, hass_ws_client):
"""Fixture that can interact with the config manager API."""
hass.loop.run_until_complete(area_registry.async_setup(hass))
return hass.loop.run_until_complete(hass_ws_client(hass))
area_registry.async_setup(hass)
return await hass_ws_client(hass)
async def test_list_areas(

View file

@ -10,9 +10,9 @@ from tests.typing import WebSocketGenerator
@pytest.fixture(autouse=True)
def setup_config(hass, aiohttp_client):
async def setup_config(hass, aiohttp_client):
"""Fixture that sets up the auth provider homeassistant module."""
hass.loop.run_until_complete(auth_config.async_setup(hass))
auth_config.async_setup(hass)
async def test_list_requires_admin(

View file

@ -14,7 +14,7 @@ from tests.typing import WebSocketGenerator
@pytest.fixture(autouse=True)
async def setup_config(hass, local_auth):
"""Fixture that sets up the auth provider ."""
await auth_ha.async_setup(hass)
auth_ha.async_setup(hass)
@pytest.fixture

View file

@ -42,7 +42,7 @@ def mock_test_component(hass):
async def client(hass, hass_client):
"""Fixture that can interact with the config manager API."""
await async_setup_component(hass, "http", {})
await config_entries.async_setup(hass)
config_entries.async_setup(hass)
return await hass_client()

View file

@ -16,10 +16,10 @@ def stub_blueprint_populate_autouse(stub_blueprint_populate: None) -> None:
@pytest.fixture
def client(hass, hass_ws_client):
async def client(hass, hass_ws_client):
"""Fixture that can interact with the config manager API."""
hass.loop.run_until_complete(device_registry.async_setup(hass))
return hass.loop.run_until_complete(hass_ws_client(hass))
device_registry.async_setup(hass)
return await hass_ws_client(hass)
async def test_list_devices(

View file

@ -30,7 +30,7 @@ async def client(
hass: HomeAssistant, hass_ws_client: WebSocketGenerator
) -> MockHAClientWebSocket:
"""Fixture that can interact with the config manager API."""
await entity_registry.async_setup(hass)
entity_registry.async_setup(hass)
return await hass_ws_client(hass)