From 71b67e20e40ce1e4c4917276a290753139c38069 Mon Sep 17 00:00:00 2001 From: Jan Bouwhuis Date: Sun, 12 Feb 2023 21:24:59 +0100 Subject: [PATCH] Improve MQTT `Callable` type hints (#87838) --- homeassistant/components/mqtt/device_trigger.py | 2 +- homeassistant/components/mqtt/text.py | 3 ++- homeassistant/components/mqtt/update.py | 5 ++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/homeassistant/components/mqtt/device_trigger.py b/homeassistant/components/mqtt/device_trigger.py index 1b03316e8ed..0f7123538c8 100644 --- a/homeassistant/components/mqtt/device_trigger.py +++ b/homeassistant/components/mqtt/device_trigger.py @@ -134,7 +134,7 @@ class Trigger: async def add_trigger( self, action: TriggerActionType, trigger_info: TriggerInfo - ) -> Callable: + ) -> Callable[[], None]: """Add MQTT trigger.""" instance = TriggerInstance(action, trigger_info, self) self.trigger_instances.append(instance) diff --git a/homeassistant/components/mqtt/text.py b/homeassistant/components/mqtt/text.py index cc05a2d8db1..01622c10a6d 100644 --- a/homeassistant/components/mqtt/text.py +++ b/homeassistant/components/mqtt/text.py @@ -37,6 +37,7 @@ from .const import ( from .debug_info import log_messages from .mixins import MQTT_ENTITY_COMMON_SCHEMA, MqttEntity, async_setup_entry_helper from .models import ( + MessageCallbackType, MqttCommandTemplate, MqttValueTemplate, PublishPayloadType, @@ -173,7 +174,7 @@ class MqttTextEntity(MqttEntity, TextEntity): topics: dict[str, Any] = {} def add_subscription( - topics: dict[str, Any], topic: str, msg_callback: Callable + topics: dict[str, Any], topic: str, msg_callback: MessageCallbackType ) -> None: if self._config.get(topic) is not None: topics[topic] = { diff --git a/homeassistant/components/mqtt/update.py b/homeassistant/components/mqtt/update.py index f0158be11d7..3ec1c73c25f 100644 --- a/homeassistant/components/mqtt/update.py +++ b/homeassistant/components/mqtt/update.py @@ -1,7 +1,6 @@ """Configure update platform in a device through MQTT topic.""" from __future__ import annotations -from collections.abc import Callable import functools import logging from typing import Any @@ -35,7 +34,7 @@ from .const import ( ) from .debug_info import log_messages from .mixins import MQTT_ENTITY_COMMON_SCHEMA, MqttEntity, async_setup_entry_helper -from .models import MqttValueTemplate, ReceiveMessage +from .models import MessageCallbackType, MqttValueTemplate, ReceiveMessage from .util import get_mqtt_data, valid_publish_topic, valid_subscribe_topic _LOGGER = logging.getLogger(__name__) @@ -148,7 +147,7 @@ class MqttUpdate(MqttEntity, UpdateEntity, RestoreEntity): topics: dict[str, Any] = {} def add_subscription( - topics: dict[str, Any], topic: str, msg_callback: Callable + topics: dict[str, Any], topic: str, msg_callback: MessageCallbackType ) -> None: if self._config.get(topic) is not None: topics[topic] = {