Example #1
0
 def test_set_color(self):
     self.led.send(self.bulb.color(0))
     self.led.send(self.bulb.color(127, 1))
     red = milight.color_from_hex('#FF0000')
     self.assertEqual(red, 170)
     self.led.send(self.bulb.color(red))
     blue = milight.color_from_hls(0.66, 0.5, 0.5)
     self.assertEqual(blue, 1)
     self.led.send(self.bulb.color(blue))
Example #2
0
 def test_set_color(self):
     self.led.send(self.bulb.color(0))
     self.led.send(self.bulb.color(127, 1))
     red = milight.color_from_hex('#FF0000')
     self.assertEqual(red, 170)
     self.led.send(self.bulb.color(red))
     blue = milight.color_from_hls(0.66,0.5,0.5)
     self.assertEqual(blue, 1)
     self.led.send(self.bulb.color(blue))
Example #3
0
 def _read_json(self, jsonable_string):
     """
     Reads the config json file out from jsonable_string and creates a Milight sequence to later run on
     :param jsonable_string: a string that can be turn into a json element. Must be in the form: 
     [
         {"group":"1", "command":"command", "payload": "value"},
         ...,
         {"group":"1", "command":"command", "payload": "value"}
     ]
     """
     logger.debug("Reading JSON config file")
     try:
         sequence = json.loads(jsonable_string)
     except (AttributeError, ValueError) as e:
         raise SFXError("Unable to parse {} due to {}".format(
             jsonable_string, e))
     logger.debug("Sequence created, adding elements")
     for a_command in sequence:
         try:
             # Essentially: for each str command attribute, get the command from the light element
             # and piles it up into the list using the payload and group element
             the_command = getattr(self.light, a_command['command'])
             value = a_command.get('payload', None)
             group = a_command.get('group', None)
             if value:
                 # If the command got a parameter...
                 if a_command['command'] == 'color':
                     #  The color processing is different for all the rest of them as
                     # it uses a 0.255 value calculated from  a helper
                     # For simplicity sake, let's use only hex values.
                     value = milight.color_from_hex(value)
                 the_command_result = the_command(
                     value, group) if group else the_command(
                         value
                     )  # the wait command does not take a group parameter
             elif not group:
                 # This is a generic wait command, so:
                 the_command_result = the_command(a_command.get('value', 1))
             else:
                 # Nope, just the bulb group as a parameter
                 the_command_result = the_command(group)
             if not self.commands:
                 self.commands = the_command_result
             else:
                 self.commands += the_command_result
         except (ValueError, AttributeError) as e:
             logger.error("Unable to decode {} due to {}".format(
                 a_command, e))
     logger.debug("JSON processed sucessfully")
Example #4
0
    def change_lamp_color(self):
        try:
            query = LightModel.Light.query.filter_by(id=self.id).first()

            controller = milight.MiLight(
                {
                    'host': query.identifier,
                    'port': query.protocol
                },
                wait_duration=0)
            light = milight.LightBulb(['rgbw', 'white', 'rgb'])

            controller.send(light.color(milight.color_from_hex(query.color),
                                        1))

            logger.info('Device ' + query.name + ' color changed')
            return json.encode({"status": "success"})
        except Exception as e:
            logger.error('Device color error : ' + str(e))
            raise DevicesException(str(e))
            return json.encode({"status": "error"})
Example #5
0
        for group in [0, 1, 2, 3]:
            ar_status = status.split(',')
            ar_color = color.split(',')
            ar_last_status = last_status.split(',')
            ar_last_color = last_color.split(',')
            if not (ar_last_status[group] == ar_status[group]
                    and ar_last_color[group] == ar_color[group]):
                #                print "group "+str(group) + " - status "+ ar_status[group] +" - color " +ar_color[group]
                migroup = int(group) + 1
                if ar_status[group] == '1':
                    #                    print "on"
                    controller.send(light.brightness(0, migroup))
                    time.sleep(0.2)
                    controller.send(
                        light.color(
                            milight.color_from_hex('#' + ar_color[group]),
                            migroup))
                    time.sleep(0.5)
                    controller.send(light.fade_up(migroup))
                    controller.send(light.brightness(100, migroup))
                else:
                    if not (ar_last_status[group] == ar_status[group]):
                        #                      print "off"
                        controller.send(light.fade_down(migroup))
                        time.sleep(0.5)
                        controller.send(light.fade_down(migroup))
                        time.sleep(4)
                        for force_off in [0, 1, 2, 3]:
                            time.sleep(1.5)
                            controller.send(light.off(migroup))
#                print "sleep"
Example #6
0
 def change_color(self, light_id, color_code):
     self._milight.send(
         self._bulbs.color(color_from_hex(color_code), light_id))
def setHexColor(color, led):
    controller.send(light.color(milight.color_from_hex(color), led))