Skip to content

Commit 2ec1ce5

Browse files
authored
Merge pull request #7 from makermelissa/main
MQTT function improvements
2 parents 10025c6 + ace5b9b commit 2ec1ce5

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

adafruit_funhouse/network.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ def __init__(
6565
)
6666
self._mqtt_client = None
6767
self.mqtt_connect = None
68-
self._mqtt_publish = None
6968

7069
def init_io_mqtt(self):
7170
"""Initialize MQTT for Adafruit IO"""
@@ -101,7 +100,6 @@ def init_mqtt(
101100
if use_io:
102101
self._mqtt_client = IO_MQTT(self._mqtt_client)
103102
self.mqtt_connect = self._mqtt_client.connect
104-
self._mqtt_publish = self._mqtt_client.publish
105103

106104
return self._mqtt_client
107105

@@ -112,19 +110,21 @@ def _get_mqtt_client(self):
112110
return self._mqtt_client
113111
raise RuntimeError("Please initialize MQTT before using")
114112

115-
def mqtt_loop(self):
113+
def mqtt_loop(self, *args, **kwargs):
116114
"""Run the MQTT Loop"""
117115
try:
118116
if self._mqtt_client is not None:
119-
self._mqtt_client.loop()
117+
self._mqtt_client.loop(*args, **kwargs)
120118
except MQTT.MMQTTException as err:
121119
print("MMQTTException: {0}".format(err))
120+
except OSError as err:
121+
print("OSError: {0}".format(err))
122122

123123
def mqtt_publish(self, *args, **kwargs):
124124
"""Publish to MQTT"""
125125
try:
126126
if self._mqtt_client is not None:
127-
self._mqtt_publish(*args, **kwargs)
127+
self._mqtt_client.publish(*args, **kwargs)
128128
except OSError as err:
129129
print("OSError: {0}".format(err))
130130

0 commit comments

Comments
 (0)