Use dataclass instead of attr slots for mqtt PublishMessage and ReceiveMessage (#101062)
Use dataclass instead of attr slots
This commit is contained in:
parent
77c519220d
commit
0ded0ef4ee
2 changed files with 17 additions and 17 deletions
|
@ -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]]
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Reference in a new issue