Coverage for src / zmqtt / _internal / packets / subscribe.py: 100%
28 statements
« prev ^ index » next coverage.py v7.13.4, created at 2026-11-12 08:49 +0000
« prev ^ index » next coverage.py v7.13.4, created at 2026-11-12 08:49 +0000
1from dataclasses import dataclass
2from typing import ClassVar
4from zmqtt._internal.packets.properties import (
5 SubAckProperties,
6 SubscribeProperties,
7 UnsubAckProperties,
8 UnsubscribeProperties,
9)
10from zmqtt._internal.packets.types import Packet, PacketType
11from zmqtt._internal.types.qos import QoS
12from zmqtt._internal.types.retain_handling import RetainHandling
15@dataclass(frozen=True, slots=True, kw_only=True)
16class SubscriptionRequest:
17 """A single topic subscription within a SUBSCRIBE packet."""
19 topic_filter: str
20 qos: QoS
21 no_local: bool = False # v5 only
22 retain_as_published: bool = False # v5 only
23 retain_handling: RetainHandling = RetainHandling.SEND_ON_SUBSCRIBE # v5 only
26@dataclass(frozen=True, slots=True, kw_only=True)
27class Subscribe(Packet):
28 packet_type: ClassVar[PacketType] = PacketType.SUBSCRIBE
30 packet_id: int
31 subscriptions: tuple[SubscriptionRequest, ...]
32 properties: SubscribeProperties | None = None # v5 only
35@dataclass(frozen=True, slots=True, kw_only=True)
36class SubAck(Packet):
37 packet_type: ClassVar[PacketType] = PacketType.SUBACK
39 packet_id: int
40 return_codes: tuple[
41 int,
42 ...,
43 ] # per sub: 0x00/0x01/0x02 = QoS granted, 0x80 = failure
44 properties: SubAckProperties | None = None # v5 only
47@dataclass(frozen=True, slots=True, kw_only=True)
48class Unsubscribe(Packet):
49 packet_type: ClassVar[PacketType] = PacketType.UNSUBSCRIBE
51 packet_id: int
52 topic_filters: tuple[str, ...]
53 properties: UnsubscribeProperties | None = None # v5 only
56@dataclass(frozen=True, slots=True, kw_only=True)
57class UnsubAck(Packet):
58 packet_type: ClassVar[PacketType] = PacketType.UNSUBACK
60 packet_id: int
61 reason_codes: tuple[int, ...] = () # v5 only — one per unsubscribed topic
62 properties: UnsubAckProperties | None = None # v5 only