1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
|
From 6a5efeba398383ab40d7aef3a02ad646ad78c850 Mon Sep 17 00:00:00 2001
From: Ewout van Mansom <ewout@vanmansom.name>
Date: Mon, 1 May 2023 21:02:19 +0200
Subject: [PATCH] Add workaround utility function to support new Linux CEC
kernel subsystem
---
cecdaemon/cecdaemon.py | 3 ++-
cecdaemon/cecusercodes.py | 4 ++--
cecdaemon/util.py | 20 ++++++++++++++++++++
requirements.txt | 1 +
tests/remotetest.py | 3 ++-
tests/triggertest.py | 3 ++-
tests/tvtest.py | 3 ++-
7 files changed, 31 insertions(+), 6 deletions(-)
create mode 100644 cecdaemon/util.py
diff --git a/cecdaemon/cecdaemon.py b/cecdaemon/cecdaemon.py
index fc7b887..f7665ef 100644
--- a/cecdaemon/cecdaemon.py
+++ b/cecdaemon/cecdaemon.py
@@ -13,6 +13,7 @@
from .remote import Remote
from .tv import Tv
from .trigger import Trigger
+from .util import cec_init
class CecDaemon():
@@ -25,7 +26,7 @@ def __init__(self):
self._parse_args()
self._setup_logging()
logging.info('Initializing CEC device, please wait...')
- cec.init()
+ cec_init()
logging.info('CEC Initialized')
if os.path.isfile(self.args.conffile):
diff --git a/cecdaemon/cecusercodes.py b/cecdaemon/cecusercodes.py
index 1024397..8443581 100644
--- a/cecdaemon/cecusercodes.py
+++ b/cecdaemon/cecusercodes.py
@@ -6,7 +6,7 @@
from time import sleep
import cec
from cecdaemon.const import USER_CONTROL_CODES
-
+from .util import cec_init
def print_keycode(event, *data):
""" Takes a python-cec cec.EVENT_COMMAND callback and prints the user control code
@@ -32,7 +32,7 @@ def main():
"""
print('Initializing CEC, please wait...')
print('If this takes too long ensure the device is not already in use')
- cec.init()
+ cec_init()
cec.add_callback(print_keycode, 2)
print('CEC device initialized, press remote keys or hit ^C to quit')
diff --git a/cecdaemon/util.py b/cecdaemon/util.py
new file mode 100644
index 0000000..8afe024
--- /dev/null
+++ b/cecdaemon/util.py
@@ -0,0 +1,20 @@
+""" Utility functions
+"""
+
+import pyudev
+import cec
+
+def cec_init():
+ """ libcec gained support for the new CEC Linux kernel subsystem. However,
+ it currently doesn't use this by default. So we check for the existence
+ of the device created by the new kernel module and then tell libcec
+ to specifically use the new "Linux" interface.
+ """
+
+ context = pyudev.Context()
+ devices = list(context.list_devices(subsystem='cec'))
+
+ if len(devices) > 0:
+ cec.init('Linux')
+ else:
+ cec.init()
\ No newline at end of file
diff --git a/requirements.txt b/requirements.txt
index 7dbebc7..ef4a9b0 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,2 +1,3 @@
python-uinput>=0.11.2
cec>=0.2.6
+pyudev>=0.8
\ No newline at end of file
diff --git a/tests/remotetest.py b/tests/remotetest.py
index 7538112..95d3363 100755
--- a/tests/remotetest.py
+++ b/tests/remotetest.py
@@ -5,6 +5,7 @@
from time import sleep
import cec
from cecdaemon.remote import Remote
+from cecdaemon.util import cec_init
CONF = {
'0': 'KEY_ENTER',
@@ -16,7 +17,7 @@
logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
-cec.init()
+cec_init()
remote = Remote(cec, CONF)
diff --git a/tests/triggertest.py b/tests/triggertest.py
index 4be7672..1a4b1ad 100755
--- a/tests/triggertest.py
+++ b/tests/triggertest.py
@@ -5,12 +5,13 @@
from time import sleep
import cec
from cecdaemon.trigger import Trigger
+from cecdaemon.util import cec_init
CONF = {'standby': '/usr/bin/whoami', 'wake': '/usr/bin/whoami',}
logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
trigger = Trigger(cec, CONF)
-cec.init()
+cec_init()
while True:
sleep(1)
diff --git a/tests/tvtest.py b/tests/tvtest.py
index a5b6687..d56f2b0 100755
--- a/tests/tvtest.py
+++ b/tests/tvtest.py
@@ -6,12 +6,13 @@
from time import sleep
import cec
from cecdaemon.tv import Tv
+from cecdaemon.util import cec_init
CONF = {'name': 'TESTSAT'}
logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
-cec.init()
+cec_init()
television = Tv(cec, CONF)
while True:
|