Python LimitlessLED via RF

Check-in [6c4b5c6de5]
Login

Check-in [6c4b5c6de5]

Overview
Comment:Support transitioning for brightness
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 6c4b5c6de55a895e2efc8bbf4368ee90c64e688c111f0fbf96f1b5dbffa11fd8
User & Date: rkeene on 2020-08-27 21:56:48
Other Links: manifest | tags
Context
2020-08-27
21:57
Remove some debugging check-in: 8de9b26091 user: rkeene tags: trunk
21:56
Support transitioning for brightness check-in: 6c4b5c6de5 user: rkeene tags: trunk
17:07
Calculate a few things better check-in: 8b48210ca6 user: rkeene tags: trunk
Changes

Modified limitlessled_rf/__init__.py from [79e827bccc] to [567595d90c].

506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
		return False

	def _get_next_message_id(self):
		# Determine next message ID
		self._message_id = (self._message_id + 1) & 0xff
		return self._message_id

	def _send_button(self, button_info):
		# Include the remote ID unless one was supplied
		button_info = button_info.copy()
		if 'remote_id' not in button_info:
			button_info['remote_id'] = self._id

			# Get the next message ID for this remote
			if 'message_id' not in button_info:







|







506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
		return False

	def _get_next_message_id(self):
		# Determine next message ID
		self._message_id = (self._message_id + 1) & 0xff
		return self._message_id

	def _send_button(self, button_info, post_delay = None):
		# Include the remote ID unless one was supplied
		button_info = button_info.copy()
		if 'remote_id' not in button_info:
			button_info['remote_id'] = self._id

			# Get the next message ID for this remote
			if 'message_id' not in button_info:
533
534
535
536
537
538
539



540
541
542
543
544
545
546



547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
			delay = self._config['delay']
		if 'retries' in button_info:
			retries = button_info['retries']
		else:
			retries = self._config['retries']

		format_config = self._config.get('format_config', None)




		self._debug("Sending {}={} n={} times with a {}s delay to queue {}, format = {}".format(button_info, message, retries, delay, self._config['radio_queue'], format_config))
		self._radio.multi_transmit(message, self._config['channels'], retries, delay, syncword = self._config['syncword'], submit_queue = self._config['radio_queue'], format_config = format_config)

		return True

	def _set_brightness(self, brightness, zone = None):



		if zone is None:
			message = {'button': 'set_brightness'}
		else:
			message = {
				'button': 'zone_set_brightness',
				'zone': zone
			}

		message['brightness'] = brightness

		return self._send_button(message)

	def _step_value(self, target_value, target_range_min, target_range_max, button_prefix, zone, midpoint = None):
		# Step all the way to the nearest extreme before moving it to
		# where it should be
		target_range = target_range_max - target_range_min + 1
		if midpoint is None:
			midpoint = (target_range / 2) + target_range_min

		# Move to the "initial" value where we force the value







>
>
>






|
>
>
>












|







533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
			delay = self._config['delay']
		if 'retries' in button_info:
			retries = button_info['retries']
		else:
			retries = self._config['retries']

		format_config = self._config.get('format_config', None)

		if post_delay is not None:
			delay = post_delay

		self._debug("Sending {}={} n={} times with a {}s delay to queue {}, format = {}".format(button_info, message, retries, delay, self._config['radio_queue'], format_config))
		self._radio.multi_transmit(message, self._config['channels'], retries, delay, syncword = self._config['syncword'], submit_queue = self._config['radio_queue'], format_config = format_config)

		return True

	def _set_brightness(self, brightness, zone = None, transition = None):
		if transition is not None:
			self._debug('Tranisition not supported for SET-type bulbs (yet)')

		if zone is None:
			message = {'button': 'set_brightness'}
		else:
			message = {
				'button': 'zone_set_brightness',
				'zone': zone
			}

		message['brightness'] = brightness

		return self._send_button(message)

	def _step_value(self, target_value, target_range_min, target_range_max, button_prefix, zone, midpoint = None, transition = None):
		# Step all the way to the nearest extreme before moving it to
		# where it should be
		target_range = target_range_max - target_range_min + 1
		if midpoint is None:
			midpoint = (target_range / 2) + target_range_min

		# Move to the "initial" value where we force the value
599
600
601
602
603
604
605







606




607
608
609
610
611
612
613
614
615
616
617

618



619
620
621
622
623
624
625
626
			final_steps = target_value - initial_value
		else:
			final_steps = initial_value - target_value

		step_command = {'button': "{}_{}".format(button_prefix, final_direction)}
		if zone is not None:
			step_command['zone'] = zone







		for step in range(final_steps):




			self._debug("[FINAL] Stepping {} {}".format(button_prefix, final_direction))
			self._send_button(step_command)

		return True

	def _step_brightness(self, brightness, brightness_min, brightness_max, zone = None):
		# For setting the brightness, set a change-overpoint at around
		# 75%, where below this value we will go to the dimmest and
		# step up and above this point it will go to the brightest
		# and step down.  This is to avoid getting bright then dimming
		# which is much more jarring than getting dim and brightening.

		brightness_changeover = ((brightness_max - brightness_min) * 0.75) + brightness_min;



		return self._step_value(brightness, brightness_min, brightness_max, 'brightness', zone, midpoint = brightness_changeover)

	def _step_temperature(self, temperature, temperature_min, temperature_max, zone = None):
		return self._step_value(temperature, temperature_min, temperature_max, 'temperature', zone)

	def _max_brightness(self, zone = None):
		if zone is None:
			message = {'button': 'max'}







>
>
>
>
>
>
>

>
>
>
>
|
|



|





>
|
>
>
>
|







605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
			final_steps = target_value - initial_value
		else:
			final_steps = initial_value - target_value

		step_command = {'button': "{}_{}".format(button_prefix, final_direction)}
		if zone is not None:
			step_command['zone'] = zone

		transition_delay = None
		self._debug("[FINAL] t = {}, fs = {}".format(transition, final_steps))
		if transition is not None and final_steps > 1:
			transition_delay = transition / (final_steps - 1)
		self._debug("[FINAL] td = {}".format(transition_delay))

		for step in range(final_steps):
			if step == (final_steps - 1):
				transition_delay = None
				self._debug("[FINAL] ftd = {}".format(transition_delay))

			self._debug("[FINAL] Stepping {} {} with a delay of {} (ms) afterwards".format(button_prefix, final_direction, transition_delay))
			self._send_button(step_command, post_delay = transition_delay)

		return True

	def _step_brightness(self, brightness, brightness_min, brightness_max, zone = None, transition = None):
		# For setting the brightness, set a change-overpoint at around
		# 75%, where below this value we will go to the dimmest and
		# step up and above this point it will go to the brightest
		# and step down.  This is to avoid getting bright then dimming
		# which is much more jarring than getting dim and brightening.
		if transition is None:
			brightness_changeover = ((brightness_max - brightness_min) * 0.75) + brightness_min
		else:
			brightness_changeover = brightness_max * 2

		return self._step_value(brightness, brightness_min, brightness_max, 'brightness', zone, midpoint = brightness_changeover, transition = transition)

	def _step_temperature(self, temperature, temperature_min, temperature_max, zone = None):
		return self._step_value(temperature, temperature_min, temperature_max, 'temperature', zone)

	def _max_brightness(self, zone = None):
		if zone is None:
			message = {'button': 'max'}
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
		length = self._config.get('message_length', None)
		format_config = self._config.get('format_config', None)

		data = self._radio.receive(channel = channel, wait = True, wait_time = 0.1, length = length, format_config = format_config)
		message = self._parse_button_message(data)
		return message

	def set_brightness(self, brightness, zone = None):
		if 'has_brightness' not in self._config['features']:
			return False

		if brightness < 0 or brightness > 255:
			return False

		self._debug("Setting brightness to {}".format(brightness))
		if brightness == 0:
			self._debug("Really setting to off")
			return self.off(zone)

		if brightness == 255:
			if 'has_max_brightness' in self._config['features']:
				return self._max_brightness(zone)

		brightness_min = self._config['brightness_range'][0]
		brightness_max = self._config['brightness_range'][1]

		brightness = self._scale_int(brightness, 1, 255, self._config['brightness_range'][0], self._config['brightness_range'][1])

		if 'can_set_brightness' in self._config['features']:
			return self._set_brightness(brightness, zone)
		else:
			return self._step_brightness(brightness, brightness_min, brightness_max, zone)

	def set_color(self, rgb, zone = None):
		# Compute the color value from the RGB value
		value = self._rgb_to_color(rgb)

		# If the color selected is really a shade of grey, turn the
		# bulbs white at that brightness







|






|




|









|

|







711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
		length = self._config.get('message_length', None)
		format_config = self._config.get('format_config', None)

		data = self._radio.receive(channel = channel, wait = True, wait_time = 0.1, length = length, format_config = format_config)
		message = self._parse_button_message(data)
		return message

	def set_brightness(self, brightness, zone = None, transition = None):
		if 'has_brightness' not in self._config['features']:
			return False

		if brightness < 0 or brightness > 255:
			return False

		self._debug("Setting brightness to {} with transition {} s".format(brightness, transition))
		if brightness == 0:
			self._debug("Really setting to off")
			return self.off(zone)

		if brightness == 255 and transition is None:
			if 'has_max_brightness' in self._config['features']:
				return self._max_brightness(zone)

		brightness_min = self._config['brightness_range'][0]
		brightness_max = self._config['brightness_range'][1]

		brightness = self._scale_int(brightness, 1, 255, self._config['brightness_range'][0], self._config['brightness_range'][1])

		if 'can_set_brightness' in self._config['features']:
			return self._set_brightness(brightness, zone, transition)
		else:
			return self._step_brightness(brightness, brightness_min, brightness_max, zone, transition)

	def set_color(self, rgb, zone = None):
		# Compute the color value from the RGB value
		value = self._rgb_to_color(rgb)

		# If the color selected is really a shade of grey, turn the
		# bulbs white at that brightness