From 2f16c3aa80cb3ae230c58f2fd15fcc9bd35de115 Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Sat, 25 May 2024 18:59:29 +0200 Subject: [PATCH] Fix mqtt callback typing (#118104) --- homeassistant/components/mqtt/client.py | 7 +++---- homeassistant/components/mqtt/models.py | 3 +-- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/homeassistant/components/mqtt/client.py b/homeassistant/components/mqtt/client.py index b3fde3f8320..59762e5cb92 100644 --- a/homeassistant/components/mqtt/client.py +++ b/homeassistant/components/mqtt/client.py @@ -77,7 +77,6 @@ from .const import ( ) from .models import ( DATA_MQTT, - AsyncMessageCallbackType, MessageCallbackType, MqttData, PublishMessage, @@ -184,7 +183,7 @@ async def async_publish( async def async_subscribe( hass: HomeAssistant, topic: str, - msg_callback: AsyncMessageCallbackType | MessageCallbackType, + msg_callback: Callable[[ReceiveMessage], Coroutine[Any, Any, None] | None], qos: int = DEFAULT_QOS, encoding: str | None = DEFAULT_ENCODING, ) -> CALLBACK_TYPE: @@ -832,7 +831,7 @@ class MQTT: def _exception_message( self, - msg_callback: AsyncMessageCallbackType | MessageCallbackType, + msg_callback: Callable[[ReceiveMessage], Coroutine[Any, Any, None] | None], msg: ReceiveMessage, ) -> str: """Return a string with the exception message.""" @@ -844,7 +843,7 @@ class MQTT: async def async_subscribe( self, topic: str, - msg_callback: AsyncMessageCallbackType | MessageCallbackType, + msg_callback: Callable[[ReceiveMessage], Coroutine[Any, Any, None] | None], qos: int, encoding: str | None = None, ) -> Callable[[], None]: diff --git a/homeassistant/components/mqtt/models.py b/homeassistant/components/mqtt/models.py index bee33b21bca..83248d85135 100644 --- a/homeassistant/components/mqtt/models.py +++ b/homeassistant/components/mqtt/models.py @@ -5,7 +5,7 @@ from __future__ import annotations from ast import literal_eval import asyncio from collections import deque -from collections.abc import Callable, Coroutine +from collections.abc import Callable from dataclasses import dataclass, field from enum import StrEnum import logging @@ -70,7 +70,6 @@ class ReceiveMessage: timestamp: float -type AsyncMessageCallbackType = Callable[[ReceiveMessage], Coroutine[Any, Any, None]] type MessageCallbackType = Callable[[ReceiveMessage], None]