@@ -65,7 +65,7 @@ def __init__(
65
65
)
66
66
self ._mqtt_client = None
67
67
self .mqtt_connect = None
68
- self .mqtt_publish = None
68
+ self ._mqtt_publish = None
69
69
70
70
def init_io_mqtt (self ):
71
71
"""Initialize MQTT for Adafruit IO"""
@@ -101,7 +101,7 @@ def init_mqtt(
101
101
if use_io :
102
102
self ._mqtt_client = IO_MQTT (self ._mqtt_client )
103
103
self .mqtt_connect = self ._mqtt_client .connect
104
- self .mqtt_publish = self ._mqtt_client .publish
104
+ self ._mqtt_publish = self ._mqtt_client .publish
105
105
106
106
return self ._mqtt_client
107
107
@@ -120,6 +120,14 @@ def mqtt_loop(self):
120
120
except MQTT .MMQTTException as err :
121
121
print ("MMQTTException: {0}" .format (err ))
122
122
123
+ def mqtt_publish (self , * args , ** kwargs ):
124
+ """Publish to MQTT"""
125
+ try :
126
+ if self ._mqtt_client is not None :
127
+ self ._mqtt_publish (* args , ** kwargs )
128
+ except OSError as err :
129
+ print ("OSError: {0}" .format (err ))
130
+
123
131
@property
124
132
def on_mqtt_connect (self ):
125
133
"""
@@ -147,8 +155,7 @@ def on_mqtt_disconnect(self):
147
155
148
156
@on_mqtt_disconnect .setter
149
157
def on_mqtt_disconnect (self , value ):
150
- self ._get_mqtt_client ()
151
- self ._mqtt_client .on_disconnect = value
158
+ self ._get_mqtt_client ().on_disconnect = value
152
159
153
160
@property
154
161
def on_mqtt_subscribe (self ):
@@ -162,8 +169,21 @@ def on_mqtt_subscribe(self):
162
169
163
170
@on_mqtt_subscribe .setter
164
171
def on_mqtt_subscribe (self , value ):
165
- self ._get_mqtt_client ()
166
- self ._mqtt_client .on_subscribe = value
172
+ self ._get_mqtt_client ().on_subscribe = value
173
+
174
+ @property
175
+ def on_mqtt_unsubscribe (self ):
176
+ """
177
+ Get or Set the MQTT Unsubscribe Handler
178
+
179
+ """
180
+ if self ._mqtt_client :
181
+ return self ._mqtt_client .on_unsubscribe
182
+ return None
183
+
184
+ @on_mqtt_unsubscribe .setter
185
+ def on_mqtt_unsubscribe (self , value ):
186
+ self ._get_mqtt_client ().on_unsubscribe = value
167
187
168
188
@property
169
189
def on_mqtt_message (self ):
@@ -177,8 +197,7 @@ def on_mqtt_message(self):
177
197
178
198
@on_mqtt_message .setter
179
199
def on_mqtt_message (self , value ):
180
- self ._get_mqtt_client ()
181
- self ._mqtt_client .on_message = value
200
+ self ._get_mqtt_client ().on_message = value
182
201
183
202
@property
184
203
def enabled (self ):
0 commit comments