Improve reload helper typing (#68558)

This commit is contained in:
Martin Hjelmare 2022-03-23 12:10:42 +01:00 committed by GitHub
parent 44d3a7e459
commit 04843a975e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -8,13 +8,15 @@ from typing import Any
from homeassistant import config as conf_util
from homeassistant.const import SERVICE_RELOAD
from homeassistant.core import Event, HomeAssistant, callback
from homeassistant.core import HomeAssistant, ServiceCall, callback
from homeassistant.exceptions import HomeAssistantError
from homeassistant.loader import async_get_integration
from homeassistant.setup import async_setup_component
from . import config_per_platform
from .entity_component import EntityComponent
from .entity_platform import EntityPlatform, async_get_platforms
from .service import async_register_admin_service
from .typing import ConfigType
_LOGGER = logging.getLogger(__name__)
@ -64,7 +66,7 @@ async def _resetup_platform(
if not conf:
return
root_config: dict[str, Any] = {integration_platform: []}
root_config: dict[str, list[ConfigType]] = {integration_platform: []}
# Extract only the config for template, ignore the rest.
for p_type, p_config in config_per_platform(conf, integration_platform):
if p_type != integration_name:
@ -113,7 +115,7 @@ async def _async_setup_platform(
)
return
entity_component = hass.data[integration_platform]
entity_component: EntityComponent = hass.data[integration_platform]
tasks = [
entity_component.async_setup_platform(integration_name, p_config)
for p_config in platform_configs
@ -163,14 +165,12 @@ async def async_setup_reload_service(
if hass.services.has_service(domain, SERVICE_RELOAD):
return
async def _reload_config(call: Event) -> None:
async def _reload_config(call: ServiceCall) -> None:
"""Reload the platforms."""
await async_reload_integration_platforms(hass, domain, platforms)
hass.bus.async_fire(f"event_{domain}_reloaded", context=call.context)
hass.helpers.service.async_register_admin_service(
domain, SERVICE_RELOAD, _reload_config
)
async_register_admin_service(hass, domain, SERVICE_RELOAD, _reload_config)
def setup_reload_service(