Improve google_assistant typing (#86537)

This commit is contained in:
Marc Mueller 2023-01-24 18:18:05 +01:00 committed by GitHub
parent 949c88930f
commit b89a51c63d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 7 deletions

View File

@ -3,7 +3,7 @@ from __future__ import annotations
from abc import ABC, abstractmethod from abc import ABC, abstractmethod
from asyncio import gather from asyncio import gather
from collections.abc import Mapping from collections.abc import Callable, Mapping
from datetime import datetime, timedelta from datetime import datetime, timedelta
from http import HTTPStatus from http import HTTPStatus
import logging import logging
@ -85,7 +85,7 @@ def _get_registry_entries(
class AbstractConfig(ABC): class AbstractConfig(ABC):
"""Hold the configuration for Google Assistant.""" """Hold the configuration for Google Assistant."""
_unsub_report_state = None _unsub_report_state: Callable[[], None] | None = None
def __init__(self, hass): def __init__(self, hass):
"""Initialize abstract config.""" """Initialize abstract config."""

View File

@ -2,7 +2,7 @@
from __future__ import annotations from __future__ import annotations
import logging import logging
from typing import Any from typing import Any, TypeVar
from homeassistant.components import ( from homeassistant.components import (
alarm_control_panel, alarm_control_panel,
@ -161,13 +161,15 @@ COMMAND_SELECT_CHANNEL = f"{PREFIX_COMMANDS}selectChannel"
COMMAND_LOCATE = f"{PREFIX_COMMANDS}Locate" COMMAND_LOCATE = f"{PREFIX_COMMANDS}Locate"
COMMAND_CHARGE = f"{PREFIX_COMMANDS}Charge" COMMAND_CHARGE = f"{PREFIX_COMMANDS}Charge"
TRAITS = [] TRAITS: list[type[_Trait]] = []
FAN_SPEED_MAX_SPEED_COUNT = 5 FAN_SPEED_MAX_SPEED_COUNT = 5
_TraitT = TypeVar("_TraitT", bound="_Trait")
def register_trait(trait):
"""Decorate a function to register a trait.""" def register_trait(trait: type[_TraitT]) -> type[_TraitT]:
"""Decorate a class to register a trait."""
TRAITS.append(trait) TRAITS.append(trait)
return trait return trait
@ -288,7 +290,7 @@ class CameraStreamTrait(_Trait):
name = TRAIT_CAMERA_STREAM name = TRAIT_CAMERA_STREAM
commands = [COMMAND_GET_CAMERA_STREAM] commands = [COMMAND_GET_CAMERA_STREAM]
stream_info = None stream_info: dict[str, str] | None = None
@staticmethod @staticmethod
def supported(domain, features, device_class, _): def supported(domain, features, device_class, _):