Index: __init__.py ================================================================== --- __init__.py +++ __init__.py @@ -7,10 +7,12 @@ _remote_type_alias_map = { 'fut089': 'rgb+cct' } _remote_type_parameters_map = { 'rgbw': { + 'retries': 5, + 'delay': 0.02, 'channels': [9, 40, 71], 'syncword': [0x258B, 0x147A], 'features': [ 'can_set_brightness', 'has_brightness', @@ -46,10 +48,12 @@ 'zone_set_brightness': 0x0E, 'set_color': 0x0F } }, 'cct': { + 'retries': 10, + 'delay': 0.5, 'channels': [4, 39, 74], 'syncword': [0x55AA, 0x050A], 'brightness_range': [0, 9], 'temperature_output_range': [0, 9], 'temperature_input_range': [3000, 9000], @@ -99,13 +103,10 @@ 'syncword': [0xAA55, 0x50A0] } } def __init__(self, radio, remote_type, remote_id, message_id = None, config = None): - if not radio.initialize(): - raise ValueError('Radio initialization failed') - # Pull in the config for this remote type self._config = self._get_type_parameters(remote_type) # Allow the user to specify some more parameters if config is not None: @@ -150,10 +151,12 @@ if 'delay' not in config: config['delay'] = 0.1 setattr(self, '_compute_button_message', getattr(self, '_compute_button_message_' + remote_type)) setattr(self, '_parse_button_message', getattr(self, '_parse_button_message_' + remote_type)) + setattr(self, 'pair', getattr(self, '_pair_' + remote_type)) + setattr(self, 'unpair', getattr(self, '_unpair_' + remote_type)) return config def _compute_button_and_zone_from_button_id(self, button_id): button_info = {} @@ -223,10 +226,29 @@ # Map the button ID to a button name button_id = button_message[4] button_info.update(self._compute_button_and_zone_from_button_id(button_id)) return button_info + + def _pair_cct(self, zone): + self._send_button({ + 'button': 'zone_on', + 'zone': zone + }) + + # Ensure that the "on" button cannot be hit soon after + # because it might trigger the unpair flow + time.sleep(5) + return True + + def _unpair_cct(self, zone): + for retry in range(7): + self._send_button({ + 'button': 'zone_on', + 'zone': zone + }) + return True def _compute_button_message_rgbw(self, button_info): remote_id = button_info['remote_id'] message_id = button_info['message_id'] @@ -309,10 +331,24 @@ brightness = brightness >> 3 brightness = 31 - ((brightness + 15) % 32) button_info['brightness'] = brightness return button_info + + def _pair_rgbw(self, zone): + self._send_button({ + 'button': 'zone_on', + 'zone': zone + }) + return False + + def _unpair_rgbw(self, zone): + self._send_button({ + 'button': 'zone_white', + 'zone': zone + }) + return False def _get_next_message_id(self): # Determine next message ID self._message_id = (self._message_id + 1) & 0xff return self._message_id @@ -559,16 +595,20 @@ 'zone': zone } # Increase retries and delay for on/off to ensure # that these important messages are delivered - message['retries'] = 15 - message['delay'] = 0.2 + message['retries'] = self._config['retries'] * 2 + message['delay'] = self._config['delay'] * 2 return self._send_button(message) - def off(self, zone = None): + def off(self, zone = None, dim = True): + # Dim the bulbs so that when turned on they are not bright + if dim: + self.set_brightness(1, zone) + if zone is None: message = { 'button': 'off', } else: @@ -577,12 +617,12 @@ 'zone': zone } # Increase retries and delay for on/off to ensure # that these important messages are delivered - message['retries'] = 15 - message['delay'] = 0.2 + message['retries'] = self._config['retries'] * 2 + message['delay'] = self._config['delay'] * 2 return self._send_button(message) def max_brightness(self, zone = None): if 'has_max_brightness' not in self._config['features']: @@ -612,13 +652,5 @@ message = { 'button': 'zone_white', 'zone': zone } return self._send_button(message) - - def pair(self, zone): - # XXX - return False - - def unpair(self, zone): - # XXX - return False