mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Improve type hints in rest integration (#81291)
This commit is contained in:
parent
be68412c64
commit
fbc8f0a2cf
@ -2,9 +2,11 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
|
from collections.abc import Coroutine
|
||||||
import contextlib
|
import contextlib
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import logging
|
import logging
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
import httpx
|
import httpx
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
@ -88,15 +90,15 @@ async def _async_process_config(hass: HomeAssistant, config: ConfigType) -> bool
|
|||||||
if DOMAIN not in config:
|
if DOMAIN not in config:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
refresh_tasks = []
|
refresh_coroutines: list[Coroutine[Any, Any, None]] = []
|
||||||
load_tasks = []
|
load_coroutines: list[Coroutine[Any, Any, None]] = []
|
||||||
rest_config: list[ConfigType] = config[DOMAIN]
|
rest_config: list[ConfigType] = config[DOMAIN]
|
||||||
for rest_idx, conf in enumerate(rest_config):
|
for rest_idx, conf in enumerate(rest_config):
|
||||||
scan_interval: timedelta = conf.get(CONF_SCAN_INTERVAL, DEFAULT_SCAN_INTERVAL)
|
scan_interval: timedelta = conf.get(CONF_SCAN_INTERVAL, DEFAULT_SCAN_INTERVAL)
|
||||||
resource_template: template.Template | None = conf.get(CONF_RESOURCE_TEMPLATE)
|
resource_template: template.Template | None = conf.get(CONF_RESOURCE_TEMPLATE)
|
||||||
rest = create_rest_data_from_config(hass, conf)
|
rest = create_rest_data_from_config(hass, conf)
|
||||||
coordinator = _rest_coordinator(hass, rest, resource_template, scan_interval)
|
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})
|
hass.data[DOMAIN][REST_DATA].append({REST: rest, COORDINATOR: coordinator})
|
||||||
|
|
||||||
for platform_domain in COORDINATOR_AWARE_PLATFORMS:
|
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)
|
hass.data[DOMAIN][platform_domain].append(platform_conf)
|
||||||
platform_idx = len(hass.data[DOMAIN][platform_domain]) - 1
|
platform_idx = len(hass.data[DOMAIN][platform_domain]) - 1
|
||||||
|
|
||||||
load = discovery.async_load_platform(
|
load_coroutine = discovery.async_load_platform(
|
||||||
hass,
|
hass,
|
||||||
platform_domain,
|
platform_domain,
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
{REST_IDX: rest_idx, PLATFORM_IDX: platform_idx},
|
{REST_IDX: rest_idx, PLATFORM_IDX: platform_idx},
|
||||||
config,
|
config,
|
||||||
)
|
)
|
||||||
load_tasks.append(load)
|
load_coroutines.append(load_coroutine)
|
||||||
|
|
||||||
if refresh_tasks:
|
if refresh_coroutines:
|
||||||
await asyncio.gather(*refresh_tasks)
|
await asyncio.gather(*refresh_coroutines)
|
||||||
|
|
||||||
if load_tasks:
|
if load_coroutines:
|
||||||
await asyncio.gather(*load_tasks)
|
await asyncio.gather(*load_coroutines)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user