core/homeassistant/components/mqtt/models.py

23 lines
553 B
Python
Raw Normal View History

"""Modesl used by multiple MQTT modules."""
import datetime as dt
2020-07-14 17:30:30 +00:00
from typing import Callable, Optional, Union
import attr
PublishPayloadType = Union[str, bytes, int, float, None]
@attr.s(slots=True, frozen=True)
class Message:
"""MQTT Message."""
2020-07-14 17:30:30 +00:00
topic: str = attr.ib()
payload: PublishPayloadType = attr.ib()
qos: int = attr.ib()
retain: bool = attr.ib()
subscribed_topic: Optional[str] = attr.ib(default=None)
timestamp: Optional[dt.datetime] = attr.ib(default=None)
MessageCallbackType = Callable[[Message], None]