Esempio n. 1
0
    def rgb(self, red, green=None, blue=None, transitiontime=5):
        if isinstance(red, basestring):
            # assume a hex string is passed
            rstring = red
            red = int(rstring[1:3], 16)
            green = int(rstring[3:5], 16)
            blue = int(rstring[5:], 16)

        print red, green, blue

        # We need to convert the RGB value to Yxy.
        redScale = float(red) / 255.0
        greenScale = float(green) / 255.0
        blueScale = float(blue) / 255.0
        colormodels.init(
            phosphor_red=colormodels.xyz_color(0.64843, 0.33086),
            phosphor_green=colormodels.xyz_color(0.4091, 0.518),
            phosphor_blue=colormodels.xyz_color(0.167, 0.04))
        # logger.debug(redScale, greenScale, blueScale)
        xyz = colormodels.irgb_color(red, green, blue)
        # logger.debug(xyz)
        xyz = colormodels.xyz_from_rgb(xyz)
        # logger.debug(xyz)
        xyz = colormodels.xyz_normalize(xyz)
        # logger.debug(xyz)

        return self.set_state(
            {"xy": [xyz[0], xyz[1]], "transitiontime": transitiontime})
Esempio n. 2
0
    def rgb(self, red, green=None, blue=None, transitiontime=5):
        if isinstance(red, basestring):
            # assume a hex string is passed
            rstring = red
            red = int(rstring[1:3], 16)
            green = int(rstring[3:5], 16)
            blue = int(rstring[5:], 16)

        print red, green, blue

        # We need to convert the RGB value to Yxy.
        redScale = float(red) / 255.0
        greenScale = float(green) / 255.0
        blueScale = float(blue) / 255.0
        colormodels.init(phosphor_red=colormodels.xyz_color(0.64843, 0.33086),
                         phosphor_green=colormodels.xyz_color(0.4091, 0.518),
                         phosphor_blue=colormodels.xyz_color(0.167, 0.04))
        logger.debug(redScale, greenScale, blueScale)
        xyz = colormodels.irgb_color(red, green, blue)
        logger.debug(xyz)
        xyz = colormodels.xyz_from_rgb(xyz)
        logger.debug(xyz)
        xyz = colormodels.xyz_normalize(xyz)
        logger.debug(xyz)

        return self.set_state({
            "xy": [xyz[0], xyz[1]],
            "transitiontime": transitiontime
        })
Esempio n. 3
0
    def color_adj(self, light_id):
        if light_id == 1:    
            rgba = self.color_picker1.wheel.color
        elif light_id == 2:
            rgba = self.color_picker2.wheel.color
        elif light_id == 3:
            rgba = self.color_picker2.wheel.color
        red = rgba[0]
        green = rgba[1]
        blue = rgba[2]

        colormodels.init(
            phosphor_red=colormodels.xyz_color(0.64843, 0.33086),
            phosphor_green=colormodels.xyz_color(0.4091, 0.518),
            phosphor_blue=colormodels.xyz_color(0.167, 0.04))
        xyz = colormodels.irgb_color(red, green, blue)
        xyz = colormodels.xyz_from_rgb(xyz)
        xyz = colormodels.xyz_normalize(xyz)
        #print xyz, '\n'
        xy = [xyz[0], xyz[1]]
        huehub = 'http://' + ip + '/api/'+ myhash + "/lights/" + str(light_id)
        reply = requests.get(huehub)
        a=json.loads(reply.text)
        #print bri_val
        payload = json.dumps({"xy":xy})
        sethuehub = huehub + "/state"
        reply = requests.put(sethuehub, data=payload)

        #Update hue data printout
        reply= requests.get(huehub)
        a=json.loads(reply.text)

        if light_id == 1:    
            self.hue_label1.text = 'Hue :'+str(a['state']['hue'])
            self.bri_label1.text = 'Brightness :'+str(a['state']['bri'])
            self.sat_label1.text = 'Saturation :'+str(a['state']['sat'])
            self.ct_label1.text = 'Colour Temp :'+str(a['state']['ct'])
            self.xy_label1.text = '(x, y) :'+str(a['state']['xy'])
        elif light_id == 2:
            self.hue_label2.text = 'Hue :'+str(a['state']['hue'])
            self.bri_label2.text = 'Brightness :'+str(a['state']['bri'])
            self.sat_label2.text = 'Saturation :'+str(a['state']['sat'])
            self.ct_label2.text = 'Colour Temp :'+str(a['state']['ct'])
            self.xy_label2.text = '(x, y) :'+str(a['state']['xy'])
        elif light_id == 3:
            self.hue_label3.text = 'Hue :'+str(a['state']['hue'])
            self.bri_label3.text = 'Brightness :'+str(a['state']['bri'])
            self.sat_label3.text = 'Saturation :'+str(a['state']['sat'])
            self.ct_label3.text = 'Colour Temp :'+str(a['state']['ct'])
            self.xy_label3.text = '(x, y) :'+str(a['state']['xy'])
Esempio n. 4
0
    def _rgb_transfer(self, red, green=None, blue=None):
        if isinstance(red, basestring):
            rstring = red
            red = int(rstring[1:3], 16)
            green = int(rstring[3:5], 16)
            blue = int(rstring[5:], 16)

        colormodels.init(
            phosphor_red=colormodels.xyz_color(0.64843, 0.33086),
            phosphor_green=colormodels.xyz_color(0.4091, 0.518),
            phosphor_blue=colormodels.xyz_color(0.167, 0.04))
        xyz = colormodels.irgb_color(red, green, blue)
        xyz = colormodels.xyz_from_rgb(xyz)
        xyz = colormodels.xyz_normalize(xyz)
        d = dict(xy=[xyz[0], xyz[1]],
                transitiontime=self._conf.default_transitiontime)
        return self.set_state(d)
    def colour_select(self, light_id):

        try:
            (rgb, hx) = tkColorChooser.askcolor()
            if (rgb, hx) == (None, None):
                warnings.warn('ColorChooser Error: No RGB colour selected.')
    
            else:
                print '(rgb, hx):', rgb, hx
                red = rgb[0]
                green = rgb[1]
                blue = rgb[2]

                redScale = float(red) / 255.0 #rgb goes from 0-255, this changes it into the 0-1.0 that xy uses
                greenScale = float(green) / 255.0
                blueScale = float(blue) / 255.0
                # Initialization function for conversion between CIE XYZ and linear RGB spaces
                colormodels.init(
                    phosphor_red=colormodels.xyz_color(0.64843, 0.33086),
                    phosphor_green=colormodels.xyz_color(0.4091, 0.518),
                    phosphor_blue=colormodels.xyz_color(0.167, 0.04))
                xyz = colormodels.irgb_color(red, green, blue)
                xyz = colormodels.xyz_from_rgb(xyz)
                xyz = colormodels.xyz_normalize(xyz)
                print xyz, '\n'
                xy = [xyz[0], xyz[1]]
                

                #print 'rgb: ', red, green, blue
                #global huehub
                huehub = "http://192.168.0.100/api/"+ myhash + "/lights/" + str(light_id)
                reply = requests.get(huehub)
                a=json.loads(reply.text)
                #print bri_val
                payload = json.dumps({"xy":xy})
                sethuehub = huehub + "/state"
                reply = requests.put(sethuehub, data=payload)
        except TypeError, e:
            print 'Error closing ColorChooser: variable referenced before assignment\n', e, '\n'
            pass
Esempio n. 6
0
    def rgb(self, red, green, blue, transitiontime=5):
        red = int(red)
        blue = int(blue)
        green = int(green)
        transitiontime = int(transitiontime)

        # We need to convert the RGB value to Yxy.
        redScale = float(red) / 255.0
        greenScale = float(green) / 255.0
        blueScale = float(blue) / 255.0
        colormodels.init(
            phosphor_red=colormodels.xyz_color(0.64843, 0.33086),
            phosphor_green=colormodels.xyz_color(0.4091, 0.518),
            phosphor_blue=colormodels.xyz_color(0.167, 0.04))
        logger.debug(redScale, greenScale, blueScale)
        xyz = colormodels.irgb_color(red, green, blue)
        logger.debug(xyz)
        xyz = colormodels.xyz_from_rgb(xyz)
        logger.debug(xyz)
        xyz = colormodels.xyz_normalize(xyz)
        logger.debug(xyz)

        return self.set_state(
            **{"xy": [xyz[0], xyz[1]], "transitiontime": transitiontime})
Esempio n. 7
0
        self.state = state
        self.config = state['config']
        self.schedules = state['schedules']
        self.groups = state['groups']

        for l in state['lights']:
            light = self._lights.get("l%s" % l, None)
            if not light:
                light = ExtendedColorLight(self, l)
                self._lights["l%s" % l] = light
            light.update_state_cache(state['lights'][l])

        self.last_update_state = datetime.datetime.now()

colormodels.init(
    phosphor_red=colormodels.xyz_color(0.64843, 0.33086),
    phosphor_green=colormodels.xyz_color(0.4091, 0.518),
    phosphor_blue=colormodels.xyz_color(0.167, 0.04))

class LightGroup(object):
    __slots__ = ['_lights']
    def __init__(self, lights):
        super(LightGroup, self).__setattr__('_lights', lights)

    def __getattr__(self, name):
        def apply_to_all(*args, **kwargs):
            for l in self._lights.values():
                getattr(l, name)(*args, **kwargs)
            return self
        origfunc = getattr(self._lights.itervalues().next(), name)
        functools.update_wrapper(apply_to_all, origfunc)
        return apply_to_all