def test_hue(self): sc = Command(b'\x45\x00', 1) self.assertEqual( self.commands.hue(0.0), Command(b'\x40\xaa', 1, select=True, select_command=sc)) self.assertEqual( self.commands.hue(0.5), Command(b'\x40\x2a', 1, select=True, select_command=sc))
def test_brightness(self): sc = Command(b'\x45\x00', 1) self.assertEqual( self.commands.brightness(0.0), Command(b'\x4e\02', 1, select=True, select_command=sc)) self.assertEqual( self.commands.brightness(0.5), Command(b'\x4e\x0f', 1, select=True, select_command=sc)) self.assertEqual( self.commands.brightness(1.0), Command(b'\x4e\x1b', 1, select=True, select_command=sc))
def _build_command(self, cmd_1, cmd_2=None, select=False, select_command=None): """ Constructs the complete command. :param cmd_1: Light command 1. :param cmd_2: Light command 2. :param select: If command requires selection. :param select_command: Selection command bytes. :return: The complete command. """ if cmd_2 is None: cmd_2 = self.SUFFIX_BYTE cmd = [cmd_1, cmd_2] if self._bridge.version < self.BRIDGE_SHORT_VERSION_MIN: cmd.append(self.BRIDGE_LONG_BYTE) return Command(cmd, self._group_number, select, select_command)
def _build_command(self, cmd_1, cmd_2): """ Constructs the complete command. :param cmd_1: Light command 1. :param cmd_2: Light command 2. :return: The complete command. """ wb1 = self._bridge.wb1 wb2 = self._bridge.wb2 sn = self._bridge.sn preamble = [0x80, 0x00, 0x00, 0x00, 0x11, wb1, wb2, 0x00, sn, 0x00] cmd = [ 0x31, self.PASSWORD_BYTE1, self.PASSWORD_BYTE2, self._remote_style, cmd_1, cmd_2, cmd_2, cmd_2, cmd_2 ] zone_selector = [self._group_number, 0x00] checksum = sum(cmd + zone_selector) & 0xFF return Command(preamble + cmd + zone_selector + [checksum], self._group_number)
def test_white(self): sc = Command(b'\x45\x00', 1) self.assertEqual( self.commands.white(), Command(b'\xc5\x00', 1, select=True, select_command=sc))
def test_off(self): self.assertEqual(self.commands.off(), Command(b'\x46\x00', 1))
def test_on(self): self.assertEqual(self.commands.on(), Command(b'\x45\x00', 1))
def test_warmer(self): sc = Command(b'\x38\x00', 1) self.assertEqual( self.commands.warmer(), Command(b'\x3e\x00', 1, select=True, select_command=sc))
def test_brighter(self): sc = Command(b'\x38\x00', 1) self.assertEqual( self.commands.brighter(), Command(b'\x3c\x00', 1, select=True, select_command=sc))
def setUp(self): self.command = Command(b'\x00', b'\x01', 1, select=True, select_command=None)