power: replace references of ioloop with EventLoop
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
parent
78e10cf7f8
commit
c61cfa325f
|
@ -11,9 +11,8 @@ import logging
|
||||||
import json
|
import json
|
||||||
import struct
|
import struct
|
||||||
import socket
|
import socket
|
||||||
from tornado.ioloop import IOLoop
|
import asyncio
|
||||||
from tornado.iostream import IOStream
|
from tornado.iostream import IOStream
|
||||||
from tornado.locks import Lock
|
|
||||||
from tornado.httpclient import AsyncHTTPClient
|
from tornado.httpclient import AsyncHTTPClient
|
||||||
from tornado.escape import json_decode
|
from tornado.escape import json_decode
|
||||||
|
|
||||||
|
@ -107,7 +106,8 @@ class PrinterPower:
|
||||||
self.server.register_event_handler(
|
self.server.register_event_handler(
|
||||||
"server:klippy_shutdown", self._handle_klippy_shutdown)
|
"server:klippy_shutdown", self._handle_klippy_shutdown)
|
||||||
self.server.register_notification("power:power_changed")
|
self.server.register_notification("power:power_changed")
|
||||||
IOLoop.current().spawn_callback(
|
event_loop = self.server.get_event_loop()
|
||||||
|
event_loop.register_callback(
|
||||||
self._initalize_devices, list(self.devices.values()))
|
self._initalize_devices, list(self.devices.values()))
|
||||||
|
|
||||||
async def _check_klippy_printing(self) -> bool:
|
async def _check_klippy_printing(self) -> bool:
|
||||||
|
@ -219,8 +219,8 @@ class PrinterPower:
|
||||||
if device not in self.devices:
|
if device not in self.devices:
|
||||||
logging.info(f"No device found: {device}")
|
logging.info(f"No device found: {device}")
|
||||||
return
|
return
|
||||||
ioloop = IOLoop.current()
|
event_loop = self.server.get_event_loop()
|
||||||
ioloop.spawn_callback(
|
event_loop.register_callback(
|
||||||
self._process_request, self.devices[device], status)
|
self._process_request, self.devices[device], status)
|
||||||
|
|
||||||
async def add_device(self, name: str, device: PowerDevice) -> None:
|
async def add_device(self, name: str, device: PowerDevice) -> None:
|
||||||
|
@ -276,10 +276,10 @@ class PowerDevice:
|
||||||
|
|
||||||
def run_power_changed_action(self) -> None:
|
def run_power_changed_action(self) -> None:
|
||||||
if self.state == "on" and self.klipper_restart:
|
if self.state == "on" and self.klipper_restart:
|
||||||
ioloop = IOLoop.current()
|
event_loop = self.server.get_event_loop()
|
||||||
kapis: APIComp = self.server.lookup_component("klippy_apis")
|
kapis: APIComp = self.server.lookup_component("klippy_apis")
|
||||||
ioloop.call_later(
|
event_loop.delay_callback(
|
||||||
self.restart_delay, kapis.do_restart, # type:ignore
|
self.restart_delay, kapis.do_restart,
|
||||||
"FIRMWARE_RESTART")
|
"FIRMWARE_RESTART")
|
||||||
|
|
||||||
def has_off_when_shutdown(self) -> bool:
|
def has_off_when_shutdown(self) -> bool:
|
||||||
|
@ -307,7 +307,7 @@ class HTTPDevice(PowerDevice):
|
||||||
) -> None:
|
) -> None:
|
||||||
super().__init__(config)
|
super().__init__(config)
|
||||||
self.client = AsyncHTTPClient()
|
self.client = AsyncHTTPClient()
|
||||||
self.request_mutex = Lock()
|
self.request_mutex = asyncio.Lock()
|
||||||
self.addr: str = config.get("address")
|
self.addr: str = config.get("address")
|
||||||
self.port = config.getint("port", default_port)
|
self.port = config.getint("port", default_port)
|
||||||
self.user = config.get("user", default_user)
|
self.user = config.get("user", default_user)
|
||||||
|
@ -456,7 +456,7 @@ class TPLinkSmartPlug(PowerDevice):
|
||||||
START_KEY = 0xAB
|
START_KEY = 0xAB
|
||||||
def __init__(self, config: ConfigHelper) -> None:
|
def __init__(self, config: ConfigHelper) -> None:
|
||||||
super().__init__(config)
|
super().__init__(config)
|
||||||
self.request_mutex = Lock()
|
self.request_mutex = asyncio.Lock()
|
||||||
self.addr: List[str] = config.get("address").split('/')
|
self.addr: List[str] = config.get("address").split('/')
|
||||||
self.port = config.getint("port", 9999)
|
self.port = config.getint("port", 9999)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue