Improve gogogate2 generic typing (#84632)

This commit is contained in:
Marc Mueller 2022-12-27 20:44:39 +01:00 committed by GitHub
parent 653805584b
commit c99025be26
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -4,9 +4,15 @@ from __future__ import annotations
from collections.abc import Awaitable, Callable, Mapping from collections.abc import Awaitable, Callable, Mapping
from datetime import timedelta from datetime import timedelta
import logging import logging
from typing import Any, NamedTuple from typing import Any, NamedTuple, Union
from ismartgate import AbstractGateApi, GogoGate2Api, ISmartGateApi from ismartgate import (
AbstractGateApi,
GogoGate2Api,
GogoGate2InfoResponse,
ISmartGateApi,
ISmartGateInfoResponse,
)
from ismartgate.common import AbstractDoor, get_door_by_id from ismartgate.common import AbstractDoor, get_door_by_id
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
@ -39,7 +45,9 @@ class StateData(NamedTuple):
door: AbstractDoor | None door: AbstractDoor | None
class DeviceDataUpdateCoordinator(DataUpdateCoordinator): class DeviceDataUpdateCoordinator(
DataUpdateCoordinator[Union[GogoGate2InfoResponse, ISmartGateInfoResponse]]
):
"""Manages polling for state changes from the device.""" """Manages polling for state changes from the device."""
def __init__( def __init__(
@ -50,7 +58,10 @@ class DeviceDataUpdateCoordinator(DataUpdateCoordinator):
*, *,
name: str, name: str,
update_interval: timedelta, update_interval: timedelta,
update_method: Callable[[], Awaitable] | None = None, update_method: Callable[
[], Awaitable[GogoGate2InfoResponse | ISmartGateInfoResponse]
]
| None = None,
request_refresh_debouncer: Debouncer | None = None, request_refresh_debouncer: Debouncer | None = None,
) -> None: ) -> None:
"""Initialize the data update coordinator.""" """Initialize the data update coordinator."""
@ -131,7 +142,7 @@ def get_data_update_coordinator(
if DATA_UPDATE_COORDINATOR not in config_entry_data: if DATA_UPDATE_COORDINATOR not in config_entry_data:
api = get_api(hass, config_entry.data) api = get_api(hass, config_entry.data)
async def async_update_data(): async def async_update_data() -> GogoGate2InfoResponse | ISmartGateInfoResponse:
try: try:
return await api.async_info() return await api.async_info()
except Exception as exception: except Exception as exception: