@@ -44,13 +44,6 @@ def __init__(self, hostname: str, port: Optional[int] = None):
44
44
self ._sub_client .on_connect = self .on_connect
45
45
self ._sub_client .on_disconnect = self .on_disconnect
46
46
47
- if self ._port is None :
48
- self ._sub_client .connect (self ._hostname )
49
- self ._pub_client .connect (self ._hostname )
50
- else :
51
- self ._sub_client .connect (self ._hostname , self ._port )
52
- self ._pub_client .connect (self ._hostname , self ._port )
53
-
54
47
def on_connect (self , client , userdata , flags , rc ):
55
48
if rc == 0 :
56
49
logger .debug ("Mqtt native connection OK!" )
@@ -64,13 +57,18 @@ def on_connect(self, client, userdata, flags, rc):
64
57
def on_disconnect (self , client , userdata , rc ):
65
58
logger .debug ("Mqtt native is disconnected with reason: %d" , rc )
66
59
60
+ async def init (self ):
61
+ if self ._port is None :
62
+ self ._sub_client .connect (self ._hostname )
63
+ self ._pub_client .connect (self ._hostname )
64
+ else :
65
+ self ._sub_client .connect (self ._hostname , self ._port )
66
+ self ._pub_client .connect (self ._hostname , self ._port )
67
+
67
68
async def run (self ):
68
69
self ._sub_client .loop_start ()
69
70
self ._pub_client .loop_start ()
70
71
71
- async def init (self ):
72
- """Do nothing"""
73
-
74
72
async def subscribe_topic (self , topic , coro ):
75
73
self ._topics_to_subscribe .append (MqttTopicSubscription (topic , coro ))
76
74
if self ._sub_client .is_connected ():
0 commit comments