hass-core/homeassistant/components/mqtt/models.py

26 lines
648 B
Python
Raw Normal View History

"""Modesl used by multiple MQTT modules."""
2021-03-18 13:07:04 +01:00
from __future__ import annotations
import datetime as dt
from typing import Awaitable, Callable, Union
import attr
PublishPayloadType = Union[str, bytes, int, float, None]
@attr.s(slots=True, frozen=True)
class Message:
"""MQTT Message."""
2020-07-14 20:30:30 +03:00
topic: str = attr.ib()
payload: PublishPayloadType = attr.ib()
qos: int = attr.ib()
retain: bool = attr.ib()
2021-03-18 13:07:04 +01:00
subscribed_topic: str | None = attr.ib(default=None)
timestamp: dt.datetime | None = attr.ib(default=None)
AsyncMessageCallbackType = Callable[[Message], Awaitable[None]]
MessageCallbackType = Callable[[Message], None]