Пример #1
0
    async def get_W2(self, ctx):
        """Set Wiz Blue."""
        try:
            await ctx.send('Sending Wiz Command....')

            # turn on the light into "rhythm mode"
            await light.turn_on(PilotBuilder())
            # set bulb brightness
            await light.turn_on(PilotBuilder(brightness=255))
            await light.turn_on(PilotBuilder(rgb=(0, 0, 255)))

            await ctx.send('Wiz Command Finished....')
        except (RuntimeError, AttributeError):
            await ctx.send('Wiz Command Failed.')
Пример #2
0
 def set_colortemp(self, colortemp=None):
     if colortemp is None:
         state = self.get_state()
         colortemp = state.get_colortemp()
     colortemp = max(min(int(colortemp), 6500), 2200)
     self.loop.run_until_complete(
         self.light.turn_on(PilotBuilder(colortemp=colortemp)))
Пример #3
0
async def main():
    """Sample code to work with bulbs."""
    # Discover all bulbs in the network via broadcast datagram (UDP)
    # function takes the discovery object and returns a list with wizlight objects.
    #    bulbs = await discovery.find_wizlights(discovery)
    # Print the IP address of the bulb on index 0
    #    print(f"Bulb IP address: {bulbs[0].ip}")

    # Iterate over all returned bulbs
    #    for bulb in bulbs:
    #        print(bulb.__dict__)
    # Turn off all available bulbs
    # await bulb.turn_off()

    # Set up a standard light
    #light = wizlight("192.168.0.170")
    light = wizlight("192.168.86.36")
    # Set up the light with a custom port
    #light = wizlight("your bulb's IP address", 12345)

    # The following calls need to be done inside an asyncio coroutine
    # to run them fron normal synchronous code, you can wrap them with
    # asyncio.run(..).

    # Turn on the light into "rhythm mode"
    #    await light.turn_on(PilotBuilder())
    # Set bulb brightness
    #    await light.turn_on(PilotBuilder(brightness = 255))

    # Set bulb brightness (with async timeout)
    timeout = 10
    await asyncio.wait_for(light.turn_on(PilotBuilder(brightness=255)),
                           timeout)

    # Set bulb to warm white
    #    await light.turn_on(PilotBuilder(warm_white = 255))

    # Set RGB values
    # red to 0 = 0%, green to 128 = 50%, blue to 255 = 100%
    #    await light.turn_on(PilotBuilder(rgb = (0, 128, 255)))

    # Set bulb to red
    #    await light.turn_on(PilotBuilder(warm_white = 255))

    # Set RGB values
    # red to 0 = 0%, green to 128 = 50%, blue to 255 = 100%
    await light.turn_on(PilotBuilder(rgb=(255, 0, 0)))
Пример #4
0
 def set_brightness(self, brightness=None):
     if brightness is None:
         state = self.get_state()
         brightness = state.get_brightness()
     brightness = int(brightness)
     brightness = max(brightness, 0)  # lower bound
     brightness = min(brightness, 255)  # upper bound
     self.loop.run_until_complete(
         self.light.turn_on(PilotBuilder(brightness=brightness)))
Пример #5
0
async def lights_normal():
    loop = asyncio.get_event_loop()
    pb = PilotBuilder()
    await asyncio.gather(
        lights[0].turn_on(pb),
        lights[1].turn_on(pb),
        lights[2].turn_on(pb),
        loop = loop
    )
Пример #6
0
async def lights_red():
    # create/get the current thread's asyncio loop
    loop = asyncio.get_event_loop()
    rgb = [1, 0, 0]
    pb = PilotBuilder(rgb = rgb)
    await asyncio.gather(
        lights[0].turn_on(pb),
        lights[1].turn_on(pb),
        lights[2].turn_on(pb),
        loop = loop
    )
Пример #7
0
    async def send_to_device(self, colors: Colors) -> None:
        if len(colors) != len(config.LED_IPS): return
        try:
            ops = [
				wizlight(config.LED_IPS[i]).turn_on(PilotBuilder(rgb=colors[i]))
				for i in range(len(config.LED_IPS))
			]
            loop = asyncio.get_event_loop()
            await asyncio.gather(*ops, loop=loop)
        except Exception:
            logging.exception("Something went wrong with LightController")
            await asyncio.sleep(config.CONTROLLER_ERROR_DELAY)
Пример #8
0
    async def async_turn_on(self, **kwargs):
        """
            Instruct the light to turn on.
        """
        # TODO: change this to set state using a single UDP call
        #

        rgb = None
        if ATTR_RGB_COLOR in kwargs:
            rgb = kwargs[ATTR_RGB_COLOR]
        if ATTR_HS_COLOR in kwargs:
            rgb = color_utils.color_hs_to_RGB(kwargs[ATTR_HS_COLOR][0],
                                              kwargs[ATTR_HS_COLOR][1])

        brightness = None
        if ATTR_BRIGHTNESS in kwargs:
            brightness = kwargs[ATTR_BRIGHTNESS]

        colortemp = None
        if ATTR_COLOR_TEMP in kwargs:
            kelvin = color_utils.color_temperature_mired_to_kelvin(
                kwargs[ATTR_COLOR_TEMP])
            colortemp = kelvin

        sceneid = None
        if ATTR_EFFECT in kwargs:
            sceneid = self._light.get_id_from_scene_name(kwargs[ATTR_EFFECT])

        if sceneid == 1000:  #rhythm
            pilot = PilotBuilder()
        else:
            pilot = PilotBuilder(rgb=rgb,
                                 brightness=brightness,
                                 colortemp=colortemp,
                                 scene=sceneid)

        await self._light.turn_on(pilot)
Пример #9
0
async def light_random(light):
    # uniform random ints
    # pb = PilotBuilder(rgb = tuple(map(lambda i: int(i), rng.integers(0, 256, size=3))))
    # Dirichlet distribution
    #rgbs = np.round(255*np.random.dirichlet([1, 1, 1], 2))
    # HSV with maximum saturation and value
    state = await lights[light].updateState()
    oldrgb = tuple(map(lambda i: i/255, state.get_rgb()))
    oldhue = int(255 * colorsys.rgb_to_hsv(oldrgb[0], oldrgb[1], oldrgb[2])[0])
    while True:
        hue = rng.uniform(0, 360, 1)
        print(oldhue)
        print(hue)
        if abs(hue - oldhue) > 100 or (360 - oldhue + hue > 100) or (360 - hue + oldhue > 100):
            break
    rgb = colorsys.hsv_to_rgb(hue, 1.0, 1.0)
    await lights[light].turn_on(PilotBuilder(rgb = tuple(map(lambda i: int(255*i), rgb))))
Пример #10
0
 async def turn_bulb_on_scene_brightness(self, scene_id, brightness_val):
     await self.light.turn_on(PilotBuilder(scene = scene_id, brightness = brightness_val))
Пример #11
0
 async def turn_bulb_on_brightness(self, brightness_val):
     await self.light.turn_on(PilotBuilder(brightness = brightness_val))
Пример #12
0
 async def turn_bulb_on_scene_id(self, scene_id):
     await self.light.turn_on(PilotBuilder(scene = scene_id))
Пример #13
0
 async def turn_bulb_on(self):
     await self.light.turn_on(PilotBuilder())
Пример #14
0
async def turnOnLights(light, light2, brightness_input):
    #brightness
    await light.turn_on(PilotBuilder(brightness = brightness_input))
    await light2.turn_on(PilotBuilder(brightness = brightness_input))
Пример #15
0
 def set_color(self, rgb=(0, 0, 0)):
     rgb = tuple([max(min(int(c), 255), 0) for c in rgb])
     self.loop.run_until_complete(self.light.turn_on(PilotBuilder(rgb=rgb)))
Пример #16
0
def trapezoid (hueVec, saturation, brightness):
    # if saturation is essentially 0, just go to the full on
    if (saturation <= epsilon):
        rgb = (0, 0, 0)
    else:
        # we want to compute the actual RGB color of the saturated point as a linear
        # combination of no more than two of the basis vectors. first we have to figure
        # out which of the basis vectors we will use
        maxAngle = math.cos ((math.pi * 2 / 3) - epsilon)
        mask = tuple([(1 if (vecDot (hueVec, vector) > maxAngle) else 0) for vector in basis])
        count = sum(mask)
        debug ("    Max Angle: {:0.3f}, Mask: ({}, {}, {}), Count: {}".format (maxAngle, mask[0], mask[1], mask[2], count))
        if (count == 1):
            # easy case, it's just one color component
            rgb = mask
        else:
            # recast as a ray-line intersection using the two found basis vectors, note
            # the basis vectors are normalized by definition
            subBasis = [basis[i] for i, maskVal in enumerate(mask) if (maskVal == 1)]
            printBasis (subBasis, "    ")

            # define the line from the origin along the second vector, computing its
            # equation in the form Ax + C = 0, but C is always 0 for this line
            AB = (subBasis[1][1], subBasis[1][0] * -1)

            # intersect the ray from the saturation point along the first basis vector
            # with the line we just computed, these are definitely not co-linear, so there
            # should always be an intersection point, and the result should always be in
            # the range [-1 .. 1], this is the first basis coefficient
            coeff = [0, 0]
            coeff[0] = vecDot (hueVec, AB) / vecDot (subBasis[0], AB)

            # compute the intersection point, and the second basis coefficient, note that
            # we compute the coefficients to always be positive, but the intersection calculation
            # needs to be in the opposite direction from the basis vector (hence the negative on
            # coeff[0]).
            intersection = vecAdd (vecMul (subBasis[0], -coeff[0]), hueVec)
            coeff[1] = vecDot (intersection, subBasis[1])

            debug ("    Intersection Point: {}, Coefficients: {}".format (vecFormat (intersection), vecFormat (coeff)))

            # there's a bit of a gamut problem here, as the area outside the hexagon defined by
            # the three unit basis vectors is not actually reachable. this manifests as
            # coefficients greater than 1, which will always happen unless the target color is
            # either one of the basis vectors or a bisector of two basis vectors. we scale both
            # coefficients by 1/maxCoefficient to make valid colors
            maxCoeff = max (coeff[0], coeff[1])
            coeff = [c / maxCoeff for c in coeff]
            debug ("    Scaled Coefficients: {}".format (vecFormat (coeff)))

            # now rebuild the rgb vector by putting the coefficients into the correct place
            j = 0
            rgbList = []
            for i in range (3):
                if (mask[i] == 1):
                    rgbList.append (min (coeff[j], 1))
                    j += 1
                else:
                    rgbList.append (0)
            rgb = tuple (rgbList)

    # we want a discontinuous behavior. if saturation >= 0.5, we want the color to remain saturated
    # and we scale the cw value down to 0 as saturation goes from 0.5 to 1. if saturation < 0.5, we
    # want to saturate cw, and scale the rgb down to (0, 0, 0) as saturation goes from 0.5 - 0
    if (saturation >= 0.5):
        # rgb remains saturated
        # scale the cw value down to 0 as saturation goes from 0.5 to 1
        cw = 1 - ((saturation - 0.5) * 2)
    else:
        cw = 1
        rgb = vecMul (rgb, saturation * 2)

    # scale back to the pilot color space
    rgb = vecInt (vecMul (rgb, 255))
    cw = int (max (0, cw * cwMax))
    if (cw == 0): cw = None;

    # scale cw back to 1-255 and return the Pilot Builder that includes the white light
    debug ("    RGB OUT: {}, CW: {}".format (rgb, cw))

    # the wiz light appears to have 5 different LEDs, r, g, b, warm_white, and cold_white
    # there appears to be a max power supplied across the 5 LEDs, which explains why all-
    # on full isn't the brightest configuration
    # warm_white appears to be 2800k, and cold_white appears to be 6200k, somewhat neutral
    # brightness is achieved by turning both of them on
    return PilotBuilder(rgb = rgb, warm_white = cw, cold_white = cw, brightness = brightness)