Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor config integration to use normal functions for setup #110750

Merged
merged 3 commits into from Feb 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 3 additions & 13 deletions homeassistant/components/config/__init__.py
Expand Up @@ -26,6 +26,7 @@
_DataT = TypeVar("_DataT", dict[str, dict[str, Any]], list[dict[str, Any]])

DOMAIN = "config"

SECTIONS = (
"area_registry",
"auth",
Expand All @@ -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


Expand Down
3 changes: 2 additions & 1 deletion homeassistant/components/config/area_registry.py
Expand Up @@ -10,7 +10,8 @@
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)
Expand Down
5 changes: 3 additions & 2 deletions homeassistant/components/config/auth.py
Expand Up @@ -7,7 +7,7 @@

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(
Expand All @@ -20,7 +20,8 @@
)


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
Expand Down
Expand Up @@ -7,11 +7,12 @@

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)
Expand Down
5 changes: 3 additions & 2 deletions homeassistant/components/config/automation.py
Expand Up @@ -11,13 +11,14 @@
)
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:
Expand Down
3 changes: 2 additions & 1 deletion homeassistant/components/config/config_entries.py
Expand Up @@ -30,7 +30,8 @@
)


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)
Expand Down
5 changes: 3 additions & 2 deletions homeassistant/components/config/core.py
Expand Up @@ -9,13 +9,14 @@
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)
Expand Down
3 changes: 2 additions & 1 deletion homeassistant/components/config/device_registry.py
Expand Up @@ -17,7 +17,8 @@
)


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)
Expand Down
3 changes: 2 additions & 1 deletion homeassistant/components/config/entity_registry.py
Expand Up @@ -18,7 +18,8 @@
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)
Expand Down
5 changes: 3 additions & 2 deletions homeassistant/components/config/scene.py
Expand Up @@ -7,13 +7,14 @@
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:
Expand Down
5 changes: 3 additions & 2 deletions homeassistant/components/config/script.py
Expand Up @@ -10,13 +10,14 @@
)
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:
Expand Down
6 changes: 3 additions & 3 deletions tests/components/config/test_area_registry.py
Expand Up @@ -10,10 +10,10 @@


@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(
Expand Down
4 changes: 2 additions & 2 deletions tests/components/config/test_auth.py
Expand Up @@ -10,9 +10,9 @@


@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(
Expand Down
Expand Up @@ -14,7 +14,7 @@
@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
Expand Down
2 changes: 1 addition & 1 deletion tests/components/config/test_config_entries.py
Expand Up @@ -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()


Expand Down
6 changes: 3 additions & 3 deletions tests/components/config/test_device_registry.py
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion tests/components/config/test_entity_registry.py
Expand Up @@ -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)


Expand Down