Debian Codegraph @

daemon/openrazer_daemon/dbus_services/dbus_methods/all.py

raw
1 # SPDX-License-Identifier: GPL-2.0-or-later
2
3 """
4 DBus methods available for all devices.
5 """
6 import os
7 from openrazer_daemon.dbus_services import endpoint
8
9 # Keyboard layout IDs
10 # There are more than listed here, but others are not known yet.
11 layout_ids = {
12 "01": "en_US",
13 "02": "el_GR",
14 "03": "de_DE",
15 "04": "fr_FR",
16 "05": "ru_RU",
17 "06": "en_GB",
18 "07": "Nordic",
19 "0a": "tr_TR",
20 "0c": "ja_JP",
21 "0f": "de_CH",
22 "10": "es_ES",
23 "11": "it_IT",
24 "12": "pt_PT",
25 "81": "en_US_mac"
26 }
27
28
29 @endpoint('razer.device.misc', 'getDriverVersion', out_sig='s')
30 def version(self):
31 """
32 Get the devices driver version
33
34 :return: Get driver version string like 1.0.7
35 :rtype: str
36 """
37 self.logger.debug("DBus call version")
38
39 # Caching
40 if 'driver_version' in self.method_args:
41 return self.method_args['driver_version']
42
43 driver_path = self.get_driver_path('version')
44
45 driver_version = '0.0.0'
46
47 if os.path.exists(driver_path):
48 # Check it exists, as people might not have reloaded driver
49 with open(driver_path, 'r') as driver_file:
50 driver_version = driver_file.read().strip()
51
52 self.method_args['driver_version'] = driver_version
53 return driver_version
54
55
56 @endpoint('razer.device.misc', 'getFirmware', out_sig='s')
57 def get_firmware(self):
58 """
59 Get the devices firmware version
60
61 :return: Get firmware string like v1.1
62 :rtype: str
63 """
64 self.logger.debug("DBus call get_firmware")
65
66 driver_path = self.get_driver_path('firmware_version')
67
68 with open(driver_path, 'r') as driver_file:
69 return driver_file.read().strip()
70
71
72 @endpoint('razer.device.misc', 'getDeviceName', out_sig='s')
73 def get_device_name(self):
74 """
75 Get the device's descriptive string
76
77 :return: Device string like 'BlackWidow Ultimate 2013'
78 :rtype: str
79 """
80 self.logger.debug("DBus call get_device_name")
81
82 driver_path = self.get_driver_path('device_type')
83
84 with open(driver_path, 'r') as driver_file:
85 return driver_file.read().strip()
86
87
88 @endpoint('razer.device.misc', 'getKeyboardLayout', out_sig='s')
89 def get_keyboard_layout(self):
90 """
91 Get the device's keyboard layout
92
93 :return: String like 'en_US', 'de_DE', 'en_GB' or 'unknown'
94 :rtype: str
95 """
96 self.logger.debug("DBus call get_keyboard_layout")
97
98 driver_path = self.get_driver_path('kbd_layout')
99
100 with open(driver_path, 'r') as driver_file:
101 try:
102 return layout_ids[driver_file.read().strip()]
103 except KeyError:
104 return "unknown"
105
106
107 # Functions to define a hardware class
108 @endpoint('razer.device.misc', 'getDeviceType', out_sig='s')
109 def get_device_type_keyboard(self):
110 """
111 Get the device's type
112
113 :return: 'keyboard'
114 :rtype: str
115 """
116 self.logger.debug("DBus call get_device_type")
117 return 'keyboard'
118
119
120 @endpoint('razer.device.misc', 'getDeviceType', out_sig='s')
121 def get_device_type_mouse(self):
122 """
123 Get the device's type
124
125 :return:'mouse'
126 :rtype: str
127 """
128 self.logger.debug("DBus call get_device_type")
129 return 'mouse'
130
131
132 @endpoint('razer.device.misc', 'getDeviceType', out_sig='s')
133 def get_device_type_mousemat(self):
134 """
135 Get the device's type
136
137 :return:'mousemat'
138 :rtype: str
139 """
140 self.logger.debug("DBus call get_device_type")
141 return 'mousemat'
142
143
144 @endpoint('razer.device.misc', 'getDeviceType', out_sig='s')
145 def get_device_type_core(self):
146 """
147 Get the device's type
148
149 :return:'core'
150 :rtype: str
151 """
152 self.logger.debug("DBus call get_device_type")
153 return 'core'
154
155
156 @endpoint('razer.device.misc', 'getDeviceType', out_sig='s')
157 def get_device_type_keypad(self):
158 """
159 Get the device's type
160
161 :return:'keypad'
162 :rtype: str
163 """
164 self.logger.debug("DBus call get_device_type")
165 return 'keypad'
166
167
168 @endpoint('razer.device.misc', 'getDeviceType', out_sig='s')
169 def get_device_type_headset(self):
170 """
171 Get the device's type
172
173 :return:'headset'
174 :rtype: str
175 """
176 self.logger.debug("DBus call get_device_type")
177 return 'headset'
178
179
180 @endpoint('razer.device.misc', 'getDeviceType', out_sig='s')
181 def get_device_type_accessory(self):
182 """
183 Get the device's type
184
185 :return:'accessory'
186 :rtype: str
187 """
188 self.logger.debug("DBus call get_device_type")
189 return 'accessory'
190
191
192 @endpoint('razer.device.misc', 'hasMatrix', out_sig='b')
193 def has_matrix(self):
194 """
195 If the device has an LED matrix
196 """
197 self.logger.debug("DBus call has_matrix")
198
199 return self.HAS_MATRIX
200
201
202 @endpoint('razer.device.misc', 'getMatrixDimensions', out_sig='ai')
203 def get_matrix_dims(self):
204 """
205 If the device has an LED matrix
206 """
207 self.logger.debug("DBus call has_matrix")
208
209 if not self.HAS_MATRIX:
210 raise RuntimeError("Device does not have matrix capabilities")
211 if self.HAS_MATRIX and self.MATRIX_DIMS is None:
212 raise RuntimeError("HAS_MATRIX is set but no MATRIX_DIMS set!")
213
214 return list(self.MATRIX_DIMS)