Debian Codegraph @

daemon/openrazer_daemon/dbus_services/dbus_methods/charging_pad_chroma.py

raw
1 # SPDX-License-Identifier: GPL-2.0-or-later
2
3 from openrazer_daemon.dbus_services import endpoint
4
5
6 @endpoint('razer.device.lighting.charging', 'getChargingBrightness', out_sig='d')
7 def get_charging_brightness(self):
8 """
9 Get the device's brightness
10 :return: Brightness
11 :rtype: float
12 """
13 self.logger.debug("DBus call get_charging_brightness")
14
15 return self.zone["charging"]["brightness"]
16
17
18 @endpoint('razer.device.lighting.charging', 'setChargingBrightness', in_sig='d')
19 def set_charging_brightness(self, brightness):
20 """
21 Set the device's brightness
22 :param brightness: Brightness
23 :type brightness: int
24 """
25 self.logger.debug("DBus call set_charging_brightness")
26
27 driver_path = self.get_driver_path('charging_led_brightness')
28
29 self.method_args['brightness'] = brightness
30
31 if brightness > 100:
32 brightness = 100
33 elif brightness < 0:
34 brightness = 0
35
36 self.set_persistence("charging", "brightness", int(brightness))
37
38 brightness = int(round(brightness * (255.0 / 100.0)))
39
40 with open(driver_path, 'w') as driver_file:
41 driver_file.write(str(brightness))
42
43 # Notify others
44 self.send_effect_event('setBrightness', brightness)
45
46
47 @endpoint('razer.device.lighting.charging', 'setChargingWave', in_sig='i')
48 def set_charging_wave(self, direction):
49 """
50 Set the wave effect on the device
51 :param direction: (0|1) - down to up, (1|2) up to down
52 :type direction: int
53 """
54 self.logger.debug("DBus call set_charging_wave")
55
56 # Notify others
57 self.send_effect_event('setWave', direction)
58
59 # remember effect
60 self.set_persistence("charging", "effect", 'wave')
61 self.set_persistence("charging", "wave_dir", int(direction))
62
63 driver_path = self.get_driver_path('charging_matrix_effect_wave')
64
65 if direction not in self.WAVE_DIRS:
66 direction = self.WAVE_DIRS[0]
67
68 with open(driver_path, 'w') as driver_file:
69 driver_file.write(str(direction))
70
71
72 @endpoint('razer.device.lighting.charging', 'setChargingStatic', in_sig='yyy')
73 def set_charging_static(self, red, green, blue):
74 """
75 Set the device to static colour
76
77 :param red: Red component
78 :type red: int
79
80 :param green: Green component
81 :type green: int
82
83 :param blue: Blue component
84 :type blue: int
85 """
86 self.logger.debug("DBus call set_charging_static")
87
88 # Notify others
89 self.send_effect_event('setStatic', red, green, blue)
90
91 # remember effect
92 self.set_persistence("charging", "effect", 'static')
93 self.zone["charging"]["colors"][0:3] = int(red), int(green), int(blue)
94
95 rgb_driver_path = self.get_driver_path('charging_matrix_effect_static')
96
97 payload = bytes([red, green, blue])
98
99 with open(rgb_driver_path, 'wb') as rgb_driver_file:
100 rgb_driver_file.write(payload)
101
102
103 @endpoint('razer.device.lighting.charging', 'setChargingSpectrum')
104 def set_charging_spectrum(self):
105 """
106 Set the device to spectrum mode
107 """
108 self.logger.debug("DBus call set_charging_spectrum")
109
110 # Notify others
111 self.send_effect_event('setSpectrum')
112
113 # remember effect
114 self.set_persistence("charging", "effect", 'spectrum')
115
116 effect_driver_path = self.get_driver_path('charging_matrix_effect_spectrum')
117
118 with open(effect_driver_path, 'w') as effect_driver_file:
119 effect_driver_file.write('1')
120
121
122 @endpoint('razer.device.lighting.charging', 'setChargingNone')
123 def set_charging_none(self):
124 """
125 Set the device to effect none
126 """
127 self.logger.debug("DBus call set_charging_none")
128
129 # Notify others
130 self.send_effect_event('setNone')
131
132 # remember effect
133 self.set_persistence("charging", "effect", 'none')
134
135 driver_path = self.get_driver_path('charging_matrix_effect_none')
136
137 with open(driver_path, 'w') as driver_file:
138 driver_file.write('1')
139
140
141 @endpoint('razer.device.lighting.charging', 'setChargingBreathRandom')
142 def set_charging_breath_random(self):
143 """
144 Set the device to random colour breathing effect
145 """
146 self.logger.debug("DBus call set_charging_breath_random")
147
148 # Notify others
149 self.send_effect_event('setBreathRandom')
150
151 # remember effect
152 self.set_persistence("charging", "effect", 'breathRandom')
153
154 driver_path = self.get_driver_path('charging_matrix_effect_breath')
155
156 payload = b'1'
157
158 with open(driver_path, 'wb') as driver_file:
159 driver_file.write(payload)
160
161
162 @endpoint('razer.device.lighting.charging', 'setChargingBreathSingle', in_sig='yyy')
163 def set_charging_breath_single(self, red, green, blue):
164 """
165 Set the device to single colour breathing effect
166
167 :param red: Red component
168 :type red: int
169
170 :param green: Green component
171 :type green: int
172
173 :param blue: Blue component
174 :type blue: int
175 """
176 self.logger.debug("DBus call set_charging_breath_single")
177
178 # Notify others
179 self.send_effect_event('setBreathSingle', red, green, blue)
180
181 # remember effect
182 self.set_persistence("charging", "effect", 'breathSingle')
183 self.zone["charging"]["colors"][0:3] = int(red), int(green), int(blue)
184
185 driver_path = self.get_driver_path('charging_matrix_effect_breath')
186
187 payload = bytes([red, green, blue])
188
189 with open(driver_path, 'wb') as driver_file:
190 driver_file.write(payload)
191
192
193 @endpoint('razer.device.lighting.charging', 'setChargingBreathDual', in_sig='yyyyyy')
194 def set_charging_breath_dual(self, red1, green1, blue1, red2, green2, blue2):
195 """
196 Set the device to dual colour breathing effect
197
198 :param red1: Red component
199 :type red1: int
200
201 :param green1: Green component
202 :type green1: int
203
204 :param blue1: Blue component
205 :type blue1: int
206
207 :param red2: Red component
208 :type red2: int
209
210 :param green2: Green component
211 :type green2: int
212
213 :param blue2: Blue component
214 :type blue2: int
215 """
216 self.logger.debug("DBus call set_charging_breath_dual")
217
218 # Notify others
219 self.send_effect_event('setBreathDual', red1, green1, blue1, red2, green2, blue2)
220
221 # remember effect
222 self.set_persistence("charging", "effect", 'breathDual')
223 self.zone["charging"]["colors"][0:6] = int(red1), int(green1), int(blue1), int(red2), int(green2), int(blue2)
224
225 driver_path = self.get_driver_path('charging_matrix_effect_breath')
226
227 payload = bytes([red1, green1, blue1, red2, green2, blue2])
228
229 with open(driver_path, 'wb') as driver_file:
230 driver_file.write(payload)
231
232
233 @endpoint('razer.device.lighting.fast_charging', 'getFastChargingBrightness', out_sig='d')
234 def get_fast_charging_brightness(self):
235 """
236 Get the device's brightness
237 :return: Brightness
238 :rtype: float
239 """
240 self.logger.debug("DBus call get_fast_charging_brightness")
241
242 return self.zone["fast_charging"]["brightness"]
243
244
245 @endpoint('razer.device.lighting.fast_charging', 'setFastChargingBrightness', in_sig='d')
246 def set_fast_charging_brightness(self, brightness):
247 """
248 Set the device's brightness
249 :param brightness: Brightness
250 :type brightness: int
251 """
252 self.logger.debug("DBus call set_fast_charging_brightness")
253
254 driver_path = self.get_driver_path('fast_charging_led_brightness')
255
256 self.method_args['brightness'] = brightness
257
258 if brightness > 100:
259 brightness = 100
260 elif brightness < 0:
261 brightness = 0
262
263 self.set_persistence("fast_charging", "brightness", int(brightness))
264
265 brightness = int(round(brightness * (255.0 / 100.0)))
266
267 with open(driver_path, 'w') as driver_file:
268 driver_file.write(str(brightness))
269
270 # Notify others
271 self.send_effect_event('setBrightness', brightness)
272
273
274 @endpoint('razer.device.lighting.fast_charging', 'setFastChargingWave', in_sig='i')
275 def set_fast_charging_wave(self, direction):
276 """
277 Set the wave effect on the device
278 :param direction: (0|1) - down to up, (1|2) up to down
279 :type direction: int
280 """
281 self.logger.debug("DBus call set_fast_charging_wave")
282
283 # Notify others
284 self.send_effect_event('setWave', direction)
285
286 # remember effect
287 self.set_persistence("fast_charging", "effect", 'wave')
288 self.set_persistence("fast_charging", "wave_dir", int(direction))
289
290 driver_path = self.get_driver_path('fast_charging_matrix_effect_wave')
291
292 if direction not in self.WAVE_DIRS:
293 direction = self.WAVE_DIRS[0]
294
295 with open(driver_path, 'w') as driver_file:
296 driver_file.write(str(direction))
297
298
299 @endpoint('razer.device.lighting.fast_charging', 'setFastChargingStatic', in_sig='yyy')
300 def set_fast_charging_static(self, red, green, blue):
301 """
302 Set the device to static colour
303
304 :param red: Red component
305 :type red: int
306
307 :param green: Green component
308 :type green: int
309
310 :param blue: Blue component
311 :type blue: int
312 """
313 self.logger.debug("DBus call set_fast_charging_static")
314
315 # Notify others
316 self.send_effect_event('setStatic', red, green, blue)
317
318 # remember effect
319 self.set_persistence("fast_charging", "effect", 'static')
320 self.zone["fast_charging"]["colors"][0:3] = int(red), int(green), int(blue)
321
322 rgb_driver_path = self.get_driver_path('fast_charging_matrix_effect_static')
323
324 payload = bytes([red, green, blue])
325
326 with open(rgb_driver_path, 'wb') as rgb_driver_file:
327 rgb_driver_file.write(payload)
328
329
330 @endpoint('razer.device.lighting.fast_charging', 'setFastChargingSpectrum')
331 def set_fast_charging_spectrum(self):
332 """
333 Set the device to spectrum mode
334 """
335 self.logger.debug("DBus call set_fast_charging_spectrum")
336
337 # Notify others
338 self.send_effect_event('setSpectrum')
339
340 # remember effect
341 self.set_persistence("fast_charging", "effect", 'spectrum')
342
343 effect_driver_path = self.get_driver_path('fast_charging_matrix_effect_spectrum')
344
345 with open(effect_driver_path, 'w') as effect_driver_file:
346 effect_driver_file.write('1')
347
348
349 @endpoint('razer.device.lighting.fast_charging', 'setFastChargingNone')
350 def set_fast_charging_none(self):
351 """
352 Set the device to effect none
353 """
354 self.logger.debug("DBus call set_fast_charging_none")
355
356 # Notify others
357 self.send_effect_event('setNone')
358
359 # remember effect
360 self.set_persistence("fast_charging", "effect", 'none')
361
362 driver_path = self.get_driver_path('fast_charging_matrix_effect_none')
363
364 with open(driver_path, 'w') as driver_file:
365 driver_file.write('1')
366
367
368 @endpoint('razer.device.lighting.fast_charging', 'setFastChargingBreathRandom')
369 def set_fast_charging_breath_random(self):
370 """
371 Set the device to random colour breathing effect
372 """
373 self.logger.debug("DBus call set_fast_charging_breath_random")
374
375 # Notify others
376 self.send_effect_event('setBreathRandom')
377
378 # remember effect
379 self.set_persistence("fast_charging", "effect", 'breathRandom')
380
381 driver_path = self.get_driver_path('fast_charging_matrix_effect_breath')
382
383 payload = b'1'
384
385 with open(driver_path, 'wb') as driver_file:
386 driver_file.write(payload)
387
388
389 @endpoint('razer.device.lighting.fast_charging', 'setFastChargingBreathSingle', in_sig='yyy')
390 def set_fast_charging_breath_single(self, red, green, blue):
391 """
392 Set the device to single colour breathing effect
393
394 :param red: Red component
395 :type red: int
396
397 :param green: Green component
398 :type green: int
399
400 :param blue: Blue component
401 :type blue: int
402 """
403 self.logger.debug("DBus call set_fast_charging_breath_single")
404
405 # Notify others
406 self.send_effect_event('setBreathSingle', red, green, blue)
407
408 # remember effect
409 self.set_persistence("fast_charging", "effect", 'breathSingle')
410 self.zone["fast_charging"]["colors"][0:3] = int(red), int(green), int(blue)
411
412 driver_path = self.get_driver_path('fast_charging_matrix_effect_breath')
413
414 payload = bytes([red, green, blue])
415
416 with open(driver_path, 'wb') as driver_file:
417 driver_file.write(payload)
418
419
420 @endpoint('razer.device.lighting.fast_charging', 'setFastChargingBreathDual', in_sig='yyyyyy')
421 def set_fast_charging_breath_dual(self, red1, green1, blue1, red2, green2, blue2):
422 """
423 Set the device to dual colour breathing effect
424
425 :param red1: Red component
426 :type red1: int
427
428 :param green1: Green component
429 :type green1: int
430
431 :param blue1: Blue component
432 :type blue1: int
433
434 :param red2: Red component
435 :type red2: int
436
437 :param green2: Green component
438 :type green2: int
439
440 :param blue2: Blue component
441 :type blue2: int
442 """
443 self.logger.debug("DBus call set_fast_charging_breath_dual")
444
445 # Notify others
446 self.send_effect_event('setBreathDual', red1, green1, blue1, red2, green2, blue2)
447
448 # remember effect
449 self.set_persistence("fast_charging", "effect", 'breathDual')
450 self.zone["fast_charging"]["colors"][0:6] = int(red1), int(green1), int(blue1), int(red2), int(green2), int(blue2)
451
452 driver_path = self.get_driver_path('fast_charging_matrix_effect_breath')
453
454 payload = bytes([red1, green1, blue1, red2, green2, blue2])
455
456 with open(driver_path, 'wb') as driver_file:
457 driver_file.write(payload)
458
459
460 @endpoint('razer.device.lighting.fully_charged', 'getFullyChargedBrightness', out_sig='d')
461 def get_fully_charged_brightness(self):
462 """
463 Get the device's brightness
464 :return: Brightness
465 :rtype: float
466 """
467 self.logger.debug("DBus call get_fully_charged_brightness")
468
469 return self.zone["fully_charged"]["brightness"]
470
471
472 @endpoint('razer.device.lighting.fully_charged', 'setFullyChargedBrightness', in_sig='d')
473 def set_fully_charged_brightness(self, brightness):
474 """
475 Set the device's brightness
476 :param brightness: Brightness
477 :type brightness: int
478 """
479 self.logger.debug("DBus call set_fully_charged_brightness")
480
481 driver_path = self.get_driver_path('fully_charged_led_brightness')
482
483 self.method_args['brightness'] = brightness
484
485 if brightness > 100:
486 brightness = 100
487 elif brightness < 0:
488 brightness = 0
489
490 self.set_persistence("fully_charged", "brightness", int(brightness))
491
492 brightness = int(round(brightness * (255.0 / 100.0)))
493
494 with open(driver_path, 'w') as driver_file:
495 driver_file.write(str(brightness))
496
497 # Notify others
498 self.send_effect_event('setBrightness', brightness)
499
500
501 @endpoint('razer.device.lighting.fully_charged', 'setFullyChargedWave', in_sig='i')
502 def set_fully_charged_wave(self, direction):
503 """
504 Set the wave effect on the device
505 :param direction: (0|1) - down to up, (1|2) up to down
506 :type direction: int
507 """
508 self.logger.debug("DBus call set_fully_charged_wave")
509
510 # Notify others
511 self.send_effect_event('setWave', direction)
512
513 # remember effect
514 self.set_persistence("fully_charged", "effect", 'wave')
515 self.set_persistence("fully_charged", "wave_dir", int(direction))
516
517 driver_path = self.get_driver_path('fully_charged_matrix_effect_wave')
518
519 if direction not in self.WAVE_DIRS:
520 direction = self.WAVE_DIRS[0]
521
522 with open(driver_path, 'w') as driver_file:
523 driver_file.write(str(direction))
524
525
526 @endpoint('razer.device.lighting.fully_charged', 'setFullyChargedStatic', in_sig='yyy')
527 def set_fully_charged_static(self, red, green, blue):
528 """
529 Set the device to static colour
530
531 :param red: Red component
532 :type red: int
533
534 :param green: Green component
535 :type green: int
536
537 :param blue: Blue component
538 :type blue: int
539 """
540 self.logger.debug("DBus call set_fully_charged_static")
541
542 # Notify others
543 self.send_effect_event('setStatic', red, green, blue)
544
545 # remember effect
546 self.set_persistence("fully_charged", "effect", 'static')
547 self.zone["fully_charged"]["colors"][0:3] = int(red), int(green), int(blue)
548
549 rgb_driver_path = self.get_driver_path('fully_charged_matrix_effect_static')
550
551 payload = bytes([red, green, blue])
552
553 with open(rgb_driver_path, 'wb') as rgb_driver_file:
554 rgb_driver_file.write(payload)
555
556
557 @endpoint('razer.device.lighting.fully_charged', 'setFullyChargedSpectrum')
558 def set_fully_charged_spectrum(self):
559 """
560 Set the device to spectrum mode
561 """
562 self.logger.debug("DBus call set_fully_charged_spectrum")
563
564 # Notify others
565 self.send_effect_event('setSpectrum')
566
567 # remember effect
568 self.set_persistence("fully_charged", "effect", 'spectrum')
569
570 effect_driver_path = self.get_driver_path('fully_charged_matrix_effect_spectrum')
571
572 with open(effect_driver_path, 'w') as effect_driver_file:
573 effect_driver_file.write('1')
574
575
576 @endpoint('razer.device.lighting.fully_charged', 'setFullyChargedNone')
577 def set_fully_charged_none(self):
578 """
579 Set the device to effect none
580 """
581 self.logger.debug("DBus call set_fully_charged_none")
582
583 # Notify others
584 self.send_effect_event('setNone')
585
586 # remember effect
587 self.set_persistence("fully_charged", "effect", 'none')
588
589 driver_path = self.get_driver_path('fully_charged_matrix_effect_none')
590
591 with open(driver_path, 'w') as driver_file:
592 driver_file.write('1')
593
594
595 @endpoint('razer.device.lighting.fully_charged', 'setFullyChargedBreathRandom')
596 def set_fully_charged_breath_random(self):
597 """
598 Set the device to random colour breathing effect
599 """
600 self.logger.debug("DBus call set_fully_charged_breath_random")
601
602 # Notify others
603 self.send_effect_event('setBreathRandom')
604
605 # remember effect
606 self.set_persistence("fully_charged", "effect", 'breathRandom')
607
608 driver_path = self.get_driver_path('fully_charged_matrix_effect_breath')
609
610 payload = b'1'
611
612 with open(driver_path, 'wb') as driver_file:
613 driver_file.write(payload)
614
615
616 @endpoint('razer.device.lighting.fully_charged', 'setFullyChargedBreathSingle', in_sig='yyy')
617 def set_fully_charged_breath_single(self, red, green, blue):
618 """
619 Set the device to single colour breathing effect
620
621 :param red: Red component
622 :type red: int
623
624 :param green: Green component
625 :type green: int
626
627 :param blue: Blue component
628 :type blue: int
629 """
630 self.logger.debug("DBus call set_fully_charged_breath_single")
631
632 # Notify others
633 self.send_effect_event('setBreathSingle', red, green, blue)
634
635 # remember effect
636 self.set_persistence("fully_charged", "effect", 'breathSingle')
637 self.zone["fully_charged"]["colors"][0:3] = int(red), int(green), int(blue)
638
639 driver_path = self.get_driver_path('fully_charged_matrix_effect_breath')
640
641 payload = bytes([red, green, blue])
642
643 with open(driver_path, 'wb') as driver_file:
644 driver_file.write(payload)
645
646
647 @endpoint('razer.device.lighting.fully_charged', 'setFullyChargedBreathDual', in_sig='yyyyyy')
648 def set_fully_charged_breath_dual(self, red1, green1, blue1, red2, green2, blue2):
649 """
650 Set the device to dual colour breathing effect
651
652 :param red1: Red component
653 :type red1: int
654
655 :param green1: Green component
656 :type green1: int
657
658 :param blue1: Blue component
659 :type blue1: int
660
661 :param red2: Red component
662 :type red2: int
663
664 :param green2: Green component
665 :type green2: int
666
667 :param blue2: Blue component
668 :type blue2: int
669 """
670 self.logger.debug("DBus call set_fully_charged_breath_dual")
671
672 # Notify others
673 self.send_effect_event('setBreathDual', red1, green1, blue1, red2, green2, blue2)
674
675 # remember effect
676 self.set_persistence("fully_charged", "effect", 'breathDual')
677 self.zone["fully_charged"]["colors"][0:6] = int(red1), int(green1), int(blue1), int(red2), int(green2), int(blue2)
678
679 driver_path = self.get_driver_path('fully_charged_matrix_effect_breath')
680
681 payload = bytes([red1, green1, blue1, red2, green2, blue2])
682
683 with open(driver_path, 'wb') as driver_file:
684 driver_file.write(payload)