Skip to content

Commit acfdd41

Browse files
committed
Add workaround utility function to support new Linux CEC kernel subsystem
1 parent 444ee75 commit acfdd41

File tree

6 files changed

+30
-6
lines changed

6 files changed

+30
-6
lines changed

cecdaemon/cecdaemon.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from .remote import Remote
1414
from .tv import Tv
1515
from .trigger import Trigger
16+
from .util import cec_init
1617

1718

1819
class CecDaemon():
@@ -25,7 +26,7 @@ def __init__(self):
2526
self._parse_args()
2627
self._setup_logging()
2728
logging.info('Initializing CEC device, please wait...')
28-
cec.init()
29+
cec_init()
2930
logging.info('CEC Initialized')
3031

3132
if os.path.isfile(self.args.conffile):

cecdaemon/cecusercodes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from time import sleep
77
import cec
88
from cecdaemon.const import USER_CONTROL_CODES
9-
9+
from .util import cec_init
1010

1111
def print_keycode(event, *data):
1212
""" Takes a python-cec cec.EVENT_COMMAND callback and prints the user control code
@@ -32,7 +32,7 @@ def main():
3232
"""
3333
print('Initializing CEC, please wait...')
3434
print('If this takes too long ensure the device is not already in use')
35-
cec.init()
35+
cec_init()
3636
cec.add_callback(print_keycode, 2)
3737
print('CEC device initialized, press remote keys or hit ^C to quit')
3838

cecdaemon/util.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
""" Utility functions
2+
"""
3+
4+
import pyudev
5+
import cec
6+
7+
def cec_init():
8+
""" libcec gained support for the new CEC Linux kernel subsystem. However,
9+
it currently doesn't use this by default. So we check for the existence
10+
of the device created by the new kernel module and then use it if it's
11+
found.
12+
"""
13+
14+
context = pyudev.Context()
15+
devices = list(context.list_devices(subsystem='cec'))
16+
17+
if len(devices) > 0:
18+
cec.init('Linux')
19+
else:
20+
cec.init()

tests/remotetest.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from time import sleep
66
import cec
77
from cecdaemon.remote import Remote
8+
from cecdaemon.util import cec_init
89

910
CONF = {
1011
'0': 'KEY_ENTER',
@@ -16,7 +17,7 @@
1617

1718
logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
1819

19-
cec.init()
20+
cec_init()
2021

2122
remote = Remote(cec, CONF)
2223

tests/triggertest.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55
from time import sleep
66
import cec
77
from cecdaemon.trigger import Trigger
8+
from cecdaemon.util import cec_init
89

910
CONF = {'standby': '/usr/bin/whoami', 'wake': '/usr/bin/whoami',}
1011
logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
1112

1213
trigger = Trigger(cec, CONF)
13-
cec.init()
14+
cec_init()
1415

1516
while True:
1617
sleep(1)

tests/tvtest.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66
from time import sleep
77
import cec
88
from cecdaemon.tv import Tv
9+
from cecdaemon.util import cec_init
910

1011
CONF = {'name': 'TESTSAT'}
1112

1213
logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
1314

14-
cec.init()
15+
cec_init()
1516
television = Tv(cec, CONF)
1617

1718
while True:

0 commit comments

Comments
 (0)