From b89a51c63d6dec175fa513bb71a6c8b19bbb2229 Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Tue, 24 Jan 2023 18:18:05 +0100 Subject: [PATCH] Improve `google_assistant` typing (#86537) --- homeassistant/components/google_assistant/helpers.py | 4 ++-- homeassistant/components/google_assistant/trait.py | 12 +++++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/homeassistant/components/google_assistant/helpers.py b/homeassistant/components/google_assistant/helpers.py index e1e63f98ec3..2a011679d09 100644 --- a/homeassistant/components/google_assistant/helpers.py +++ b/homeassistant/components/google_assistant/helpers.py @@ -3,7 +3,7 @@ from __future__ import annotations from abc import ABC, abstractmethod from asyncio import gather -from collections.abc import Mapping +from collections.abc import Callable, Mapping from datetime import datetime, timedelta from http import HTTPStatus import logging @@ -85,7 +85,7 @@ def _get_registry_entries( class AbstractConfig(ABC): """Hold the configuration for Google Assistant.""" - _unsub_report_state = None + _unsub_report_state: Callable[[], None] | None = None def __init__(self, hass): """Initialize abstract config.""" diff --git a/homeassistant/components/google_assistant/trait.py b/homeassistant/components/google_assistant/trait.py index 920a63b70f8..71abdf1758d 100644 --- a/homeassistant/components/google_assistant/trait.py +++ b/homeassistant/components/google_assistant/trait.py @@ -2,7 +2,7 @@ from __future__ import annotations import logging -from typing import Any +from typing import Any, TypeVar from homeassistant.components import ( alarm_control_panel, @@ -161,13 +161,15 @@ COMMAND_SELECT_CHANNEL = f"{PREFIX_COMMANDS}selectChannel" COMMAND_LOCATE = f"{PREFIX_COMMANDS}Locate" COMMAND_CHARGE = f"{PREFIX_COMMANDS}Charge" -TRAITS = [] +TRAITS: list[type[_Trait]] = [] 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) return trait @@ -288,7 +290,7 @@ class CameraStreamTrait(_Trait): name = TRAIT_CAMERA_STREAM commands = [COMMAND_GET_CAMERA_STREAM] - stream_info = None + stream_info: dict[str, str] | None = None @staticmethod def supported(domain, features, device_class, _):