LIRC libraries
Linux Infrared Remote Control
Loading...
Searching...
No Matches
async_client.py
Go to the documentation of this file.
1
''' Asynchronous python bindings for the lircd socket interface. '''
2
8
9
39
40
# pylint: disable=W0613
41
42
import
asyncio
43
from
lirc.client
import
AbstractConnection
as
AbstractConnection
44
45
46
class
AsyncConnection(object):
47
''' Asynchronous read interface on top of an AbstractConnection.
48
49
Parameters:
50
- connection: Typically a lirc.RawConnection or lirc.LircdConnection.
51
- loop: AbstractEventLoop, typically obtained using
52
asyncio.get_event_loop().
53
'''
54
55
def
__init__(self, connection: AbstractConnection,
56
loop: asyncio.AbstractEventLoop):
57
58
def
read_from_fd():
59
''' Read data from the connection fd and put into queue. '''
60
line = self.
_conn
.
readline
(0)
61
if
line:
62
asyncio.ensure_future(self.
_queue
.put(line))
63
64
self.
_conn
= connection
65
self.
_loop
= loop
66
self.
_queue
= asyncio.Queue()
67
self.
_loop
.add_reader(self.
_conn
.fileno(), read_from_fd)
68
69
def
close
(self):
70
''' Clean up loop and the base connection. '''
71
self.
_loop
.remove_reader(self.
_conn
.fileno())
72
73
async def
readline
(self) -> str:
74
''' Asynchronous get next line from the connection. '''
75
return
await self.
_queue
.get()
76
77
def
__aiter__
(self):
78
''' Return async iterator. '''
79
return
self
80
81
async def
__anext__
(self):
82
''' Implement async iterator.next(). '''
83
return
await self.
_queue
.get()
84
85
async def
__aenter__
(self):
86
''' Implement "async with". '''
87
return
self
88
89
async def
__aexit__
(self, exc_type, exc, traceback):
90
''' Implement exit from "async with". '''
91
self.
close
()
92
93
lirc.async_client.AsyncConnection.__anext__
__anext__(self)
Definition
async_client.py:81
lirc.async_client.AsyncConnection._queue
_queue
Definition
async_client.py:66
lirc.async_client.AsyncConnection.close
close(self)
Clean up loop and the base connection.
Definition
async_client.py:70
lirc.async_client.AsyncConnection._conn
_conn
Definition
async_client.py:64
lirc.async_client.AsyncConnection.__aenter__
__aenter__(self)
Definition
async_client.py:85
lirc.async_client.AsyncConnection._loop
_loop
Definition
async_client.py:65
lirc.async_client.AsyncConnection.__aiter__
__aiter__(self)
Return async iterator.
Definition
async_client.py:78
lirc.async_client.AsyncConnection.readline
str readline(self)
Definition
async_client.py:73
lirc.async_client.AsyncConnection.__aexit__
__aexit__(self, exc_type, exc, traceback)
Definition
async_client.py:89
lirc.client
Definition
client.py:1
python-pkg
lirc
async_client.py
Generated by
1.14.0