pyqttier 0.2.0__tar.gz → 0.2.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyqttier
3
- Version: 0.2.0
3
+ Version: 0.2.2
4
4
  Summary: Convenient wrapper around Paho MQTT
5
5
  Author-email: Jacob Brunson <github@jacobbrunson.com>
6
6
  License-File: LICENSE
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "pyqttier"
3
- version = "0.2.0"
3
+ version = "0.2.2"
4
4
  description = "Convenient wrapper around Paho MQTT"
5
5
  readme = "README.md"
6
6
  authors = [
@@ -23,6 +23,7 @@ class Mqtt5Connection(IBrokerConnection):
23
23
  class PendingSubscription:
24
24
  topic: str
25
25
  subscription_id: int
26
+ qos: int
26
27
 
27
28
  @dataclass
28
29
  class PendingPublish:
@@ -115,6 +116,10 @@ class Mqtt5Connection(IBrokerConnection):
115
116
  if sub_id in self._subscription_callbacks:
116
117
  self._subscription_callbacks[sub_id](message)
117
118
  return
119
+ else:
120
+ self._logger.debug("No specific callback for subscription ID %d", sub_id)
121
+ else:
122
+ self._logger.warning("No subscription ID found in message properties. This is not usual because we always provide one when subscribing.")
118
123
  with self._message_handling_lock:
119
124
  for callback in self._message_callbacks:
120
125
  callback(message)
@@ -132,12 +137,12 @@ class Mqtt5Connection(IBrokerConnection):
132
137
  break
133
138
  else:
134
139
  self._logger.debug(
135
- "Connected and subscribing to %s", pending_subscr.topic
140
+ "Connected and subscribing to %s as subscription_id=%d", pending_subscr.topic, pending_subscr.subscription_id
136
141
  )
137
142
  sub_props = MqttProperties(PacketTypes.SUBSCRIBE)
138
143
  sub_props.SubscriptionIdentifier = pending_subscr.subscription_id
139
144
  self._client.subscribe(
140
- pending_subscr.topic, qos=1, properties=sub_props
145
+ pending_subscr.topic, qos=pending_subscr.qos, properties=sub_props
141
146
  )
142
147
  while not self._queued_messages.empty():
143
148
  try:
@@ -179,7 +184,7 @@ class Mqtt5Connection(IBrokerConnection):
179
184
  self._queued_messages.put(pending_pub)
180
185
  return fut
181
186
 
182
- def subscribe(self, topic: str, callback: Optional[MessageCallback] = None) -> int:
187
+ def subscribe(self, topic: str, callback: Optional[MessageCallback] = None, qos: int = 1) -> int:
183
188
  """Subscribes to a topic. If the connection is not established, the subscription is queued.
184
189
  Returns the subscription ID.
185
190
  """
@@ -188,12 +193,14 @@ class Mqtt5Connection(IBrokerConnection):
188
193
  self._logger.debug("Subscribing to %s", topic)
189
194
  sub_props = MqttProperties(PacketTypes.SUBSCRIBE)
190
195
  sub_props.SubscriptionIdentifier = sub_id
191
- self._client.subscribe(topic, qos=1, properties=sub_props)
196
+ self._client.subscribe(topic, qos=qos, properties=sub_props)
192
197
  else:
193
198
  self._logger.debug("Pending subscription to %s", topic)
194
- self._queued_subscriptions.put(self.PendingSubscription(topic, sub_id))
199
+ self._queued_subscriptions.put(self.PendingSubscription(topic, sub_id, qos))
195
200
  if callback is not None:
196
201
  self._subscription_callbacks[sub_id] = callback
202
+ else:
203
+ self._logger.warning("No callback provided for subscription to %s", topic)
197
204
  return sub_id
198
205
 
199
206
  def is_topic_sub(self, topic: str, sub: str) -> bool:
@@ -17,7 +17,7 @@ class IBrokerConnection(ABC):
17
17
  pass
18
18
 
19
19
  @abstractmethod
20
- def subscribe(self, topic: str, callback: Optional[MessageCallback] = None) -> int:
20
+ def subscribe(self, topic: str, callback: Optional[MessageCallback] = None, qos: int = 1) -> int:
21
21
  """
22
22
  Subscribes to the provided topic. May queue the subscription until the connection to the broker is established.
23
23
  When a message is received on the topic, the provided callback will be executed if provided.
@@ -63,4 +63,6 @@ class Message:
63
63
  msg_obj.response_topic = properties["ResponseTopic"]
64
64
  if "MessageExpiryInterval" in properties:
65
65
  msg_obj.message_expiry_interval = properties["MessageExpiryInterval"]
66
+ if "SubscriptionIdentifier" in properties:
67
+ msg_obj.subscription_id = properties["SubscriptionIdentifier"]
66
68
  return msg_obj
@@ -716,7 +716,7 @@ wheels = [
716
716
 
717
717
  [[package]]
718
718
  name = "pyqttier"
719
- version = "0.2.0"
719
+ version = "0.3.0"
720
720
  source = { editable = "." }
721
721
  dependencies = [
722
722
  { name = "paho-mqtt" },
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes