Improve type hints in rest integration (#81291)
This commit is contained in:
parent
be68412c64
commit
fbc8f0a2cf
1 changed files with 11 additions and 9 deletions
|
@ -2,9 +2,11 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
from collections.abc import Coroutine
|
||||
import contextlib
|
||||
from datetime import timedelta
|
||||
import logging
|
||||
from typing import Any
|
||||
|
||||
import httpx
|
||||
import voluptuous as vol
|
||||
|
@ -88,15 +90,15 @@ async def _async_process_config(hass: HomeAssistant, config: ConfigType) -> bool
|
|||
if DOMAIN not in config:
|
||||
return True
|
||||
|
||||
refresh_tasks = []
|
||||
load_tasks = []
|
||||
refresh_coroutines: list[Coroutine[Any, Any, None]] = []
|
||||
load_coroutines: list[Coroutine[Any, Any, None]] = []
|
||||
rest_config: list[ConfigType] = config[DOMAIN]
|
||||
for rest_idx, conf in enumerate(rest_config):
|
||||
scan_interval: timedelta = conf.get(CONF_SCAN_INTERVAL, DEFAULT_SCAN_INTERVAL)
|
||||
resource_template: template.Template | None = conf.get(CONF_RESOURCE_TEMPLATE)
|
||||
rest = create_rest_data_from_config(hass, conf)
|
||||
coordinator = _rest_coordinator(hass, rest, resource_template, scan_interval)
|
||||
refresh_tasks.append(coordinator.async_refresh())
|
||||
refresh_coroutines.append(coordinator.async_refresh())
|
||||
hass.data[DOMAIN][REST_DATA].append({REST: rest, COORDINATOR: coordinator})
|
||||
|
||||
for platform_domain in COORDINATOR_AWARE_PLATFORMS:
|
||||
|
@ -107,20 +109,20 @@ async def _async_process_config(hass: HomeAssistant, config: ConfigType) -> bool
|
|||
hass.data[DOMAIN][platform_domain].append(platform_conf)
|
||||
platform_idx = len(hass.data[DOMAIN][platform_domain]) - 1
|
||||
|
||||
load = discovery.async_load_platform(
|
||||
load_coroutine = discovery.async_load_platform(
|
||||
hass,
|
||||
platform_domain,
|
||||
DOMAIN,
|
||||
{REST_IDX: rest_idx, PLATFORM_IDX: platform_idx},
|
||||
config,
|
||||
)
|
||||
load_tasks.append(load)
|
||||
load_coroutines.append(load_coroutine)
|
||||
|
||||
if refresh_tasks:
|
||||
await asyncio.gather(*refresh_tasks)
|
||||
if refresh_coroutines:
|
||||
await asyncio.gather(*refresh_coroutines)
|
||||
|
||||
if load_tasks:
|
||||
await asyncio.gather(*load_tasks)
|
||||
if load_coroutines:
|
||||
await asyncio.gather(*load_coroutines)
|
||||
|
||||
return True
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue