Revize 7d28568e
Přidáno uživatelem Martin Forejt před téměř 4 roky(ů)
aswi2021vochomurka/service/mqtt/mqtt_subscriber.py | ||
---|---|---|
7 | 7 |
|
8 | 8 |
|
9 | 9 |
class MQTTSubscriber(Subscriber): |
10 |
client: mqtt.Client = None |
|
10 | 11 |
|
11 | 12 |
# The callback for when the client receives a CONNACK response from the server. |
12 | 13 |
def on_connect(self, client, userdata, flags, rc, properties=None): |
... | ... | |
40 | 41 |
def start(self): |
41 | 42 |
super().start() |
42 | 43 |
client = mqtt.Client() |
44 |
self.client = client |
|
43 | 45 |
client.on_connect = self.on_connect |
44 | 46 |
client.on_message = self.on_message |
45 | 47 |
client.on_disconnect = self.on_disconnect |
... | ... | |
63 | 65 |
return |
64 | 66 |
|
65 | 67 |
client.loop_forever() |
68 |
|
|
69 |
def stop(self): |
|
70 |
super().stop() |
|
71 |
if self.client is not None: |
|
72 |
logging.info("Disconnecting from broker") |
|
73 |
client = self.client |
|
74 |
self.client = None |
|
75 |
client.disconnect() |
Také k dispozici: Unified diff
Re: #8921 - settings dialog