Skip to content

Commit

Permalink
Merge pull request #501 from ParadoxAlarmInterface/remove_thread_queu…
Browse files Browse the repository at this point in the history
…e_interface

Get rid of ThreadQueueInterface in Text interfaces #500
  • Loading branch information
yozik04 authored Sep 20, 2024
2 parents 219e508 + 5df1caa commit 1717c92
Show file tree
Hide file tree
Showing 15 changed files with 278 additions and 198 deletions.
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ repos:
- id: trailing-whitespace

- repo: https://github.com/asottile/pyupgrade
rev: v3.15.2
rev: v3.17.0
hooks:
- id: pyupgrade
args: ["--py37-plus"]

- repo: https://github.com/psf/black
rev: 24.4.0
rev: 24.8.0
hooks:
- id: black
args:
Expand All @@ -35,7 +35,7 @@ repos:
- id: isort

- repo: https://github.com/PyCQA/flake8
rev: 7.0.0
rev: 7.1.1
hooks:
- id: flake8
additional_dependencies: [flake8-bugbear]
Expand Down
10 changes: 6 additions & 4 deletions paradox/connections/ip/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down Expand Up @@ -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()
Expand All @@ -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
)

Expand Down Expand Up @@ -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()
)

Expand Down
15 changes: 6 additions & 9 deletions paradox/connections/serial_connection.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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()
Expand Down
11 changes: 3 additions & 8 deletions paradox/interfaces/text/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

from paradox.config import config as cfg
from paradox.event import Event, EventLevel, Notification
from paradox.interfaces import ThreadQueueInterface
from paradox.interfaces import AsyncInterface
from paradox.lib import ps
from paradox.lib.event_filter import EventFilter, EventTagFilter, LiveEventRegexpFilter

logger = logging.getLogger("PAI").getChild(__name__)


class AbstractTextInterface(ThreadQueueInterface):
class AbstractTextInterface(AsyncInterface):
"""Interface Class using any Text interface"""

def __init__(self, alarm, event_filter: EventFilter, min_level=EventLevel.INFO):
Expand All @@ -20,12 +20,7 @@ def __init__(self, alarm, event_filter: EventFilter, min_level=EventLevel.INFO):
self.min_level = min_level
self.alarm = alarm

def stop(self):
super().stop()

def _run(self):
super()._run()

async def run(self):
ps.subscribe(self.handle_panel_event, "events")
ps.subscribe(self.handle_notify, "notifications")

Expand Down
Loading

0 comments on commit 1717c92

Please sign in to comment.