MqttMonitor/MqttReasonCodes.py

branch
eric7
changeset 99
420cb8adbf7e
child 102
70b8858199f5
equal deleted inserted replaced
98:85d56e77e9df 99:420cb8adbf7e
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2021 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing the translated MQTT v5 reason codes.
8 """
9
10 from PyQt6.QtCore import QCoreApplication
11
12 from paho.mqtt.packettypes import PacketTypes
13
14 MqttReasonCodeNames = {
15 0: {
16 QCoreApplication.translate(
17 "MqttReasonCodeNames", "Success"
18 ): [PacketTypes.CONNACK, PacketTypes.PUBACK, PacketTypes.PUBREC,
19 PacketTypes.PUBREL, PacketTypes.PUBCOMP, PacketTypes.UNSUBACK,
20 PacketTypes.AUTH],
21 QCoreApplication.translate(
22 "MqttReasonCodeNames", "Normal disconnection"
23 ): [PacketTypes.DISCONNECT],
24 QCoreApplication.translate(
25 "MqttReasonCodeNames", "Granted QoS 0"
26 ): [PacketTypes.SUBACK]},
27 1: {
28 QCoreApplication.translate(
29 "MqttReasonCodeNames", "Granted QoS 1"
30 ): [PacketTypes.SUBACK]},
31 2: {
32 QCoreApplication.translate(
33 "MqttReasonCodeNames", "Granted QoS 2"
34 ): [PacketTypes.SUBACK]},
35 4: {
36 QCoreApplication.translate(
37 "MqttReasonCodeNames", "Disconnect with will message"
38 ): [PacketTypes.DISCONNECT]},
39 16: {
40 QCoreApplication.translate(
41 "MqttReasonCodeNames", "No matching subscribers"
42 ): [PacketTypes.PUBACK, PacketTypes.PUBREC]},
43 17: {
44 QCoreApplication.translate(
45 "MqttReasonCodeNames", "No subscription found"
46 ): [PacketTypes.UNSUBACK]},
47 24: {
48 QCoreApplication.translate(
49 "MqttReasonCodeNames", "Continue authentication"
50 ): [PacketTypes.AUTH]},
51 25: {
52 QCoreApplication.translate(
53 "MqttReasonCodeNames", "Re-authenticate"
54 ): [PacketTypes.AUTH]},
55 128: {
56 QCoreApplication.translate(
57 "MqttReasonCodeNames", "Unspecified error"
58 ): [PacketTypes.CONNACK, PacketTypes.PUBACK,
59 PacketTypes.PUBREC, PacketTypes.SUBACK,
60 PacketTypes.UNSUBACK, PacketTypes.DISCONNECT]},
61 129: {
62 QCoreApplication.translate(
63 "MqttReasonCodeNames", "Malformed packet"
64 ): [PacketTypes.CONNACK, PacketTypes.DISCONNECT]},
65 130: {
66 QCoreApplication.translate(
67 "MqttReasonCodeNames", "Protocol error"
68 ): [PacketTypes.CONNACK, PacketTypes.DISCONNECT]},
69 131: {
70 QCoreApplication.translate(
71 "MqttReasonCodeNames", "Implementation specific error"
72 ): [PacketTypes.CONNACK, PacketTypes.PUBACK,
73 PacketTypes.PUBREC, PacketTypes.SUBACK,
74 PacketTypes.UNSUBACK, PacketTypes.DISCONNECT]},
75 132: {
76 QCoreApplication.translate(
77 "MqttReasonCodeNames", "Unsupported protocol version"
78 ): [PacketTypes.CONNACK]},
79 133: {
80 QCoreApplication.translate(
81 "MqttReasonCodeNames", "Client identifier not valid"
82 ): [PacketTypes.CONNACK]},
83 134: {
84 QCoreApplication.translate(
85 "MqttReasonCodeNames", "Bad user name or password"
86 ): [PacketTypes.CONNACK]},
87 135: {
88 QCoreApplication.translate(
89 "MqttReasonCodeNames", "Not authorized"
90 ): [PacketTypes.CONNACK, PacketTypes.PUBACK,
91 PacketTypes.PUBREC, PacketTypes.SUBACK,
92 PacketTypes.UNSUBACK, PacketTypes.DISCONNECT]},
93 136: {
94 QCoreApplication.translate(
95 "MqttReasonCodeNames", "Server unavailable"
96 ): [PacketTypes.CONNACK]},
97 137: {
98 QCoreApplication.translate(
99 "MqttReasonCodeNames", "Server busy"
100 ): [PacketTypes.CONNACK, PacketTypes.DISCONNECT]},
101 138: {
102 QCoreApplication.translate(
103 "MqttReasonCodeNames", "Banned"
104 ): [PacketTypes.CONNACK]},
105 139: {
106 QCoreApplication.translate(
107 "MqttReasonCodeNames", "Server shutting down"
108 ): [PacketTypes.DISCONNECT]},
109 140: {
110 QCoreApplication.translate(
111 "MqttReasonCodeNames", "Bad authentication method"
112 ): [PacketTypes.CONNACK, PacketTypes.DISCONNECT]},
113 141: {
114 QCoreApplication.translate(
115 "MqttReasonCodeNames", "Keep alive timeout"
116 ): [PacketTypes.DISCONNECT]},
117 142: {
118 QCoreApplication.translate(
119 "MqttReasonCodeNames", "Session taken over"
120 ): [PacketTypes.DISCONNECT]},
121 143: {
122 QCoreApplication.translate(
123 "MqttReasonCodeNames", "Topic filter invalid"
124 ): [PacketTypes.SUBACK, PacketTypes.UNSUBACK,
125 PacketTypes.DISCONNECT]},
126 144: {
127 QCoreApplication.translate(
128 "MqttReasonCodeNames", "Topic name invalid"
129 ): [PacketTypes.CONNACK, PacketTypes.PUBACK,
130 PacketTypes.PUBREC, PacketTypes.DISCONNECT]},
131 145: {
132 QCoreApplication.translate(
133 "MqttReasonCodeNames", "Packet identifier in use"
134 ): [PacketTypes.PUBACK, PacketTypes.PUBREC,
135 PacketTypes.SUBACK, PacketTypes.UNSUBACK]},
136 146: {
137 QCoreApplication.translate(
138 "MqttReasonCodeNames", "Packet identifier not found"
139 ): [PacketTypes.PUBREL, PacketTypes.PUBCOMP]},
140 147: {
141 QCoreApplication.translate(
142 "MqttReasonCodeNames", "Receive maximum exceeded"
143 ): [PacketTypes.DISCONNECT]},
144 148: {
145 QCoreApplication.translate(
146 "MqttReasonCodeNames", "Topic alias invalid"
147 ): [PacketTypes.DISCONNECT]},
148 149: {
149 QCoreApplication.translate(
150 "MqttReasonCodeNames", "Packet too large"
151 ): [PacketTypes.CONNACK, PacketTypes.DISCONNECT]},
152 150: {
153 QCoreApplication.translate(
154 "MqttReasonCodeNames", "Message rate too high"
155 ): [PacketTypes.DISCONNECT]},
156 151: {
157 QCoreApplication.translate(
158 "MqttReasonCodeNames", "Quota exceeded"
159 ): [PacketTypes.CONNACK, PacketTypes.PUBACK,
160 PacketTypes.PUBREC, PacketTypes.SUBACK,
161 PacketTypes.DISCONNECT], },
162 152: {
163 QCoreApplication.translate(
164 "MqttReasonCodeNames", "Administrative action"
165 ): [PacketTypes.DISCONNECT]},
166 153: {
167 QCoreApplication.translate(
168 "MqttReasonCodeNames", "Payload format invalid"
169 ): [PacketTypes.PUBACK, PacketTypes.PUBREC, PacketTypes.DISCONNECT]},
170 154: {
171 QCoreApplication.translate(
172 "MqttReasonCodeNames", "Retain not supported"
173 ): [PacketTypes.CONNACK, PacketTypes.DISCONNECT]},
174 155: {
175 QCoreApplication.translate(
176 "MqttReasonCodeNames", "QoS not supported"
177 ): [PacketTypes.CONNACK, PacketTypes.DISCONNECT]},
178 156: {
179 QCoreApplication.translate(
180 "MqttReasonCodeNames", "Use another server"
181 ): [PacketTypes.CONNACK, PacketTypes.DISCONNECT]},
182 157: {
183 QCoreApplication.translate(
184 "MqttReasonCodeNames", "Server moved"
185 ): [PacketTypes.CONNACK, PacketTypes.DISCONNECT]},
186 158: {
187 QCoreApplication.translate(
188 "MqttReasonCodeNames", "Shared subscription not supported"
189 ): [PacketTypes.SUBACK, PacketTypes.DISCONNECT]},
190 159: {
191 QCoreApplication.translate(
192 "MqttReasonCodeNames", "Connection rate exceeded"
193 ): [PacketTypes.CONNACK, PacketTypes.DISCONNECT]},
194 160: {
195 QCoreApplication.translate(
196 "MqttReasonCodeNames", "Maximum connect time"
197 ): [PacketTypes.DISCONNECT]},
198 161: {
199 QCoreApplication.translate(
200 "MqttReasonCodeNames", "Subscription identifiers not supported"
201 ): [PacketTypes.SUBACK, PacketTypes.DISCONNECT]},
202 162: {
203 QCoreApplication.translate(
204 "MqttReasonCodeNames", "Wildcard subscription not supported"
205 ): [PacketTypes.SUBACK, PacketTypes.DISCONNECT]},
206 }
207
208 def mqttReasonCode(rc, packetType):
209 """
210 Function to get the readable reason code string given the result code and
211 the packet type.
212
213 @param rc result code
214 @type int
215 @param packetType packet type
216 @type PacketTypes (= int)
217 """
218 if rc not in MqttReasonCodeNames:
219 return QCoreApplication.translate(
220 "MqttReasonCodeNames", "Unknown result code ({0})").format(rc)
221
222 messages = MqttReasonCodeNames[rc]
223 messagesList = [message for message in messages.keys()
224 if packetType in messages[message]]
225 if len(messagesList) == 0:
226 return QCoreApplication.translate(
227 "MqttReasonCodeNames",
228 "Unknown result code ({0}) for packet type '{1}'"
229 ).format(rc, packetType)
230
231 return messagesList[0]

eric ide

mercurial