File tree Expand file tree Collapse file tree 6 files changed +30
-6
lines changed
Expand file tree Collapse file tree 6 files changed +30
-6
lines changed Original file line number Diff line number Diff line change 1313from .remote import Remote
1414from .tv import Tv
1515from .trigger import Trigger
16+ from .util import cec_init
1617
1718
1819class 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 ):
Original file line number Diff line number Diff line change 66from time import sleep
77import cec
88from cecdaemon .const import USER_CONTROL_CODES
9-
9+ from . util import cec_init
1010
1111def 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
Original file line number Diff line number Diff line change 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 ()
Original file line number Diff line number Diff line change 55from time import sleep
66import cec
77from cecdaemon .remote import Remote
8+ from cecdaemon .util import cec_init
89
910CONF = {
1011 '0' : 'KEY_ENTER' ,
1617
1718logging .basicConfig (stream = sys .stdout , level = logging .DEBUG )
1819
19- cec . init ()
20+ cec_init ()
2021
2122remote = Remote (cec , CONF )
2223
Original file line number Diff line number Diff line change 55from time import sleep
66import cec
77from cecdaemon .trigger import Trigger
8+ from cecdaemon .util import cec_init
89
910CONF = {'standby' : '/usr/bin/whoami' , 'wake' : '/usr/bin/whoami' ,}
1011logging .basicConfig (stream = sys .stdout , level = logging .DEBUG )
1112
1213trigger = Trigger (cec , CONF )
13- cec . init ()
14+ cec_init ()
1415
1516while True :
1617 sleep (1 )
Original file line number Diff line number Diff line change 66from time import sleep
77import cec
88from cecdaemon .tv import Tv
9+ from cecdaemon .util import cec_init
910
1011CONF = {'name' : 'TESTSAT' }
1112
1213logging .basicConfig (stream = sys .stdout , level = logging .DEBUG )
1314
14- cec . init ()
15+ cec_init ()
1516television = Tv (cec , CONF )
1617
1718while True :
You can’t perform that action at this time.
0 commit comments