diff --git a/homeassistant/components/mqtt/models.py b/homeassistant/components/mqtt/models.py index 8c599469ff2..23faa726e09 100644 --- a/homeassistant/components/mqtt/models.py +++ b/homeassistant/components/mqtt/models.py @@ -11,8 +11,6 @@ from enum import StrEnum import logging from typing import TYPE_CHECKING, Any, TypedDict -import attr - from homeassistant.const import ATTR_ENTITY_ID, ATTR_NAME from homeassistant.core import CALLBACK_TYPE, HomeAssistant, callback from homeassistant.helpers import template @@ -44,26 +42,26 @@ ATTR_THIS = "this" PublishPayloadType = str | bytes | int | float | None -@attr.s(slots=True, frozen=True) +@dataclass class PublishMessage: - """MQTT Message.""" + """MQTT Message for publishing.""" - topic: str = attr.ib() - payload: PublishPayloadType = attr.ib() - qos: int = attr.ib() - retain: bool = attr.ib() + topic: str + payload: PublishPayloadType + qos: int + retain: bool -@attr.s(slots=True, frozen=True) +@dataclass class ReceiveMessage: - """MQTT Message.""" + """MQTT Message received.""" - topic: str = attr.ib() - payload: ReceivePayloadType = attr.ib() - qos: int = attr.ib() - retain: bool = attr.ib() - subscribed_topic: str = attr.ib(default=None) - timestamp: dt.datetime = attr.ib(default=None) + topic: str + payload: ReceivePayloadType + qos: int + retain: bool + subscribed_topic: str + timestamp: dt.datetime AsyncMessageCallbackType = Callable[[ReceiveMessage], Coroutine[Any, Any, None]] diff --git a/tests/components/mqtt/test_init.py b/tests/components/mqtt/test_init.py index 48d949ae927..ccd175fe296 100644 --- a/tests/components/mqtt/test_init.py +++ b/tests/components/mqtt/test_init.py @@ -2085,7 +2085,9 @@ async def test_handle_message_callback( callbacks.append(args) mock_mqtt = await mqtt_mock_entry() - msg = ReceiveMessage("some-topic", b"test-payload", 1, False) + msg = ReceiveMessage( + "some-topic", b"test-payload", 1, False, "some-topic", datetime.now() + ) mqtt_client_mock.on_connect(mqtt_client_mock, None, None, 0) await mqtt.async_subscribe(hass, "some-topic", _callback) mqtt_client_mock.on_message(mock_mqtt, None, msg)