︙ | | |
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
|
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
|
+
+
+
+
+
+
+
+
+
-
-
+
+
|
else:
self._message_id = button_info['message_id']
# Compute message
message = self._compute_button_message(button_info)
# Transmit
if 'delay' in button_info:
delay = button_info['delay']
else:
delay = self._config['delay']
if 'retries' in button_info:
retries = button_info['retries']
else:
retries = self._config['retries']
self._debug("Sending {}={} n={} times with a {}s delay".format(button_info, message, self._config['retries'], self._config['delay']))
self._radio.multi_transmit(message, self._config['channels'], self._config['retries'], self._config['delay'])
self._debug("Sending {}={} n={} times with a {}s delay".format(button_info, message, retries, delay))
self._radio.multi_transmit(message, self._config['channels'], retries, delay)
return True
def _set_brightness(self, brightness, zone = None):
if zone is None:
message = {'button': 'set_brightness'}
else:
|
︙ | | |
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
|
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
|
-
-
|
return True
def _step_brightness(self, brightness, brightness_min, brightness_max, zone = None):
# Select the appropriate zone before sending the steps
# to ensure they reach the correct bulbs
self.on(zone)
time.sleep(0.1)
return self._step_value(brightness, brightness_min, brightness_max, 'brightness', zone)
def _step_temperature(self, temperature, temperature_min, temperature_max, zone = None):
# Select the appropriate zone before sending the steps
# to ensure they reach the correct bulbs
self.on(zone)
time.sleep(0.1)
return self._step_value(temperature, temperature_min, temperature_max, 'temperature', zone)
def _rgb_to_hue(self, r, g, b):
r = r / 255.0
g = g / 255.0
b = b / 255.0
|
︙ | | |
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
|
464
465
466
467
468
469
470
471
472
473
474
475
476
477
|
-
-
-
|
color = int(color + 0.5)
self._debug("RGB = \x1b[38;2;%i;%i;%im%06x\x1b[0m; Hue = %s; Color = %i" % (r, g, b, rgb, str(h * 360), color))
return color
def rgb_to_color(self, rgb):
return self._rgb_to_color(rgb)
def raw_send_button(self, button_info):
return self._send_button(button_info)
def raw_read_button(self):
channel = self._config['channels'][0]
self._radio.set_syncword(self._config['syncword'])
data = self._radio.receive(channel = channel, wait = True, wait_time = 1)
|
︙ | | |
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
|
520
521
522
523
524
525
526
527
528
529
530
531
532
533
|
-
|
# If the bulbs do not support color, nothing needs to be done
if 'has_color' not in self._config['features']:
return False
# Turn on the appropriate zone to select it
self.on(zone)
time.sleep(0.1)
# Press the button
return self._send_button({'button': 'set_color', 'color': value})
def set_temperature(self, kelvins, zone = None):
if 'has_temperature' not in self._config['features']:
return False
|
︙ | | |
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
|
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
|
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
|
if zone is None:
message = {'button': 'on'}
else:
message = {
'button': 'zone_on',
'zone': zone
}
# Increase retries and delay for on/off to ensure
# that these important messages are delivered
message['retries'] = 15
message['delay'] = 0.2
return self._send_button(message)
def off(self, zone = None):
if zone is None:
message = {'button': 'off'}
message = {
'button': 'off',
}
else:
message = {
'button': 'zone_off',
'zone': zone
}
# Increase retries and delay for on/off to ensure
# that these important messages are delivered
message['retries'] = 15
message['delay'] = 0.2
return self._send_button(message)
def max_brightness(self, zone = None):
if 'has_max_brightness' not in self._config['features']:
return self.set_brightness(255, zone)
if zone is None:
|
︙ | | |