diff --git a/paradox/connections/ip/connection.py b/paradox/connections/ip/connection.py index 46f81265..f0fd7519 100644 --- a/paradox/connections/ip/connection.py +++ b/paradox/connections/ip/connection.py @@ -60,7 +60,7 @@ def __init__(self, host="127.0.0.1", port=10000): self.port = port async def _try_connect(self): - _, self._protocol = await self.loop.create_connection( + _, self._protocol = await asyncio.get_event_loop().create_connection( self._make_protocol, host=self.host, port=self.port ) @@ -90,7 +90,9 @@ def set_key(self, value): self._protocol.key = value def on_ip_message(self, container: Container): - return self.loop.create_task(self.ip_handler_registry.handle(container)) + return asyncio.get_event_loop().create_task( + self.ip_handler_registry.handle(container) + ) async def wait_for_ip_message(self, timeout=cfg.IO_TIMEOUT) -> Container: future = FutureHandler() @@ -115,7 +117,7 @@ def __init__( self.port = port async def _try_connect(self) -> None: - _, self._protocol = await self.loop.create_connection( + _, self._protocol = await asyncio.get_event_loop().create_connection( self._make_protocol, host=self.host, port=self.port ) @@ -146,7 +148,7 @@ def write(self, data: bytes): async def _try_connect(self) -> None: await self.stun_session.connect() - _, self._protocol = await self.loop.create_connection( + _, self._protocol = await asyncio.get_event_loop().create_connection( self._make_protocol, sock=self.stun_session.get_socket() ) diff --git a/paradox/connections/serial_connection.py b/paradox/connections/serial_connection.py index 537307a8..3234b084 100644 --- a/paradox/connections/serial_connection.py +++ b/paradox/connections/serial_connection.py @@ -1,13 +1,10 @@ -# -*- coding: utf-8 -*- - - +import asyncio import logging import os import stat -import typing -import serial_asyncio from serial import SerialException +import serial_asyncio from ..exceptions import SerialConnectionOpenFailed from .connection import Connection @@ -67,12 +64,12 @@ async def connect(self) -> bool: logger.error(f"Failed to update file {self.port_path} permissions") return False - self.connected_future = self.loop.create_future() - open_timeout_handler = self.loop.call_later(5, self.open_timeout) + self.connected_future = asyncio.get_event_loop().create_future() + open_timeout_handler = asyncio.get_event_loop().call_later(5, self.open_timeout) try: _, self._protocol = await serial_asyncio.create_serial_connection( - self.loop, self.make_protocol, self.port_path, self.baud + asyncio.get_event_loop(), self.make_protocol, self.port_path, self.baud ) return await self.connected_future @@ -81,7 +78,7 @@ async def connect(self) -> bool: raise SerialConnectionOpenFailed( "Connection to serial port failed" ) from e # PAICriticalException - except: + except Exception: logger.exception("Unable to connect to Serial") finally: open_timeout_handler.cancel() diff --git a/paradox/interfaces/text/signal.py b/paradox/interfaces/text/signal.py index 6ace577a..81f92e33 100644 --- a/paradox/interfaces/text/signal.py +++ b/paradox/interfaces/text/signal.py @@ -28,12 +28,12 @@ def __init__(self, alarm): ) self.signal = None - self.loop = None + self.glib_loop = None def stop(self): """Stops the Signal Interface Thread""" - if self.loop is not None: - self.loop.quit() + if self.glib_loop is not None: + self.glib_loop.quit() super().stop() @@ -46,11 +46,11 @@ async def run(self): self.signal = bus.get("org.asamk.Signal") self.signal.onMessageReceived = self.handle_message - self.loop = GLib.MainLoop() + self.glib_loop = GLib.MainLoop() logger.debug("Signal Interface Running") - asyncio.get_event_loop().run_in_executor(None, self.loop.run) + asyncio.get_event_loop().run_in_executor(None, self.glib_loop.run) def send_message(self, message: str, level: EventLevel): if self.signal is None: