mqtt: replace references to ioloop with eventloop
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
parent
8382b90682
commit
05e2389dc1
|
@ -12,7 +12,6 @@ import json
|
||||||
import pathlib
|
import pathlib
|
||||||
from collections import deque
|
from collections import deque
|
||||||
import paho.mqtt.client as paho_mqtt
|
import paho.mqtt.client as paho_mqtt
|
||||||
from tornado.ioloop import IOLoop
|
|
||||||
from websockets import WebRequest, JsonRPC, APITransport
|
from websockets import WebRequest, JsonRPC, APITransport
|
||||||
|
|
||||||
# Annotation imports
|
# Annotation imports
|
||||||
|
@ -135,6 +134,7 @@ class AIOHelper:
|
||||||
class MQTTClient(APITransport):
|
class MQTTClient(APITransport):
|
||||||
def __init__(self, config: ConfigHelper) -> None:
|
def __init__(self, config: ConfigHelper) -> None:
|
||||||
self.server = config.get_server()
|
self.server = config.get_server()
|
||||||
|
self.event_loop = self.server.get_event_loop()
|
||||||
self.address: str = config.get('address')
|
self.address: str = config.get('address')
|
||||||
self.port: int = config.getint('port', 1883)
|
self.port: int = config.getint('port', 1883)
|
||||||
self.user_name = config.get('username', None)
|
self.user_name = config.get('username', None)
|
||||||
|
@ -205,7 +205,7 @@ class MQTTClient(APITransport):
|
||||||
f"Moonraker API topics - Request: {self.api_request_topic}, "
|
f"Moonraker API topics - Request: {self.api_request_topic}, "
|
||||||
f"Response: {self.api_resp_topic}")
|
f"Response: {self.api_resp_topic}")
|
||||||
|
|
||||||
IOLoop.current().spawn_callback(self._initialize)
|
self.event_loop.register_callback(self._initialize)
|
||||||
|
|
||||||
async def _initialize(self) -> None:
|
async def _initialize(self) -> None:
|
||||||
# We must wait for the IOLoop (asyncio event loop) to start
|
# We must wait for the IOLoop (asyncio event loop) to start
|
||||||
|
@ -242,8 +242,8 @@ class MQTTClient(APITransport):
|
||||||
if topic in self.subscribed_topics:
|
if topic in self.subscribed_topics:
|
||||||
cb_hdls = self.subscribed_topics[topic][1]
|
cb_hdls = self.subscribed_topics[topic][1]
|
||||||
for hdl in cb_hdls:
|
for hdl in cb_hdls:
|
||||||
IOLoop.current().spawn_callback(
|
self.event_loop.register_callback(
|
||||||
hdl.callback, message.payload) # type: ignore
|
hdl.callback, message.payload)
|
||||||
else:
|
else:
|
||||||
logging.debug(
|
logging.debug(
|
||||||
f"Unregistered MQTT Topic Received: {topic}, "
|
f"Unregistered MQTT Topic Received: {topic}, "
|
||||||
|
|
Loading…
Reference in New Issue