コード例 #1
0
 async def gen(reference, sender, **kwargs):
     get_power = DeviceMessages.GetPower()
     async for pkt in sender(get_power, reference, **kwargs):
         if pkt | DeviceMessages.StatePower:
             if pkt.level == 0:
                 yield LightMessages.SetLightPower(level=65535,
                                                   res_required=False,
                                                   duration=duration,
                                                   target=pkt.serial)
             else:
                 yield LightMessages.SetLightPower(level=0,
                                                   res_required=False,
                                                   duration=duration,
                                                   target=pkt.serial)
コード例 #2
0
            def power_message(self, overrides):
                power = overrides.get("power", self.power)
                duration = overrides.get("duration", self.duration) or 0

                if power is not None:
                    level = 0 if power not in (True, "on") else 65535
                    return LightMessages.SetLightPower(level=level, duration=duration)
コード例 #3
0
async def apply_zone(applier, target, afr, serial, theme, overrides):
    length = None
    msg = MultiZoneMessages.GetColorZones(start_index=0, end_index=255)
    async for pkt, _, _ in target.script(msg).run_with(serial, afr):
        if pkt | MultiZoneMessages.StateMultiZone:
            length = pkt.zones_count

    if length is None:
        log.warning(
            hp.lc("Couldn't work out how many zones the light had",
                  serial=serial))
        return

    messages = []
    for (start_index, end_index), hsbk in applier(length).apply_theme(theme):
        messages.append(
            MultiZoneMessages.SetColorZones(start_index=start_index,
                                            end_index=end_index,
                                            hue=hsbk.hue,
                                            saturation=hsbk.saturation,
                                            brightness=hsbk.brightness,
                                            kelvin=hsbk.kelvin,
                                            duration=overrides.get(
                                                "duration", 1),
                                            res_required=False,
                                            ack_required=True))

    set_power = LightMessages.SetLightPower(level=65535,
                                            duration=overrides.get(
                                                "duration", 1))
    pipeline = Pipeline(*messages, spread=0.005)
    await target.script([set_power, pipeline]).run_with_all(serial, afr)
コード例 #4
0
async def apply_light(applier, target, afr, serial, theme, overrides):
    color = applier().apply_theme(theme)
    s = "kelvin:{} hue:{} saturation:{} brightness:{}".format(
        color.kelvin, color.hue, color.saturation, color.brightness)
    set_power = LightMessages.SetLightPower(level=65535,
                                            duration=overrides.get(
                                                "duration", 1))
    await target.script([
        set_power, Parser.color_to_msg(s, overrides=overrides)
    ]).run_with_all(serial, afr)
コード例 #5
0
ファイル: transform.py プロジェクト: mic159/photons-core
    def power_message(self, state):
        power_level = 65535 if state["power"] == "on" else 0

        if state.get("duration") in (sb.NotSpecified, "", 0, None):
            return DeviceMessages.SetPower(level=power_level,
                                           res_required=False)
        else:
            return LightMessages.SetLightPower(level=power_level,
                                               duration=state["duration"],
                                               res_required=False)
コード例 #6
0
        async def gen(reference, sender, **kwargs):
            instance = kls(reference, sender, kwargs, aps, theme, options)

            # Turn on the device
            yield LightMessages.SetLightPower(level=65535, duration=options.duration)

            # Yield messages to turn on the theme for this device
            plans = sender.make_plans("capability")
            async for serial, _, info in sender.gatherer.gather(plans, reference):
                async for m in instance.apply(info["cap"]):
                    yield m
コード例 #7
0
async def apply_tile(applier, target, afr, serial, theme, overrides):
    from photons_tile_paint.orientation import Orientation as O, reorient
    from photons_tile_paint.animation import orientations_from

    chain = []
    orientations = {}
    async for pkt, _, _ in target.script(
            TileMessages.GetDeviceChain()).run_with(serial, afr):
        if pkt | TileMessages.StateDeviceChain:
            for tile in tiles_from(pkt):
                chain.append(tile)
            orientations = orientations_from(pkt)

    if chain is None:
        log.warning(
            hp.lc("Couldn't work out how many tiles the light had",
                  serial=serial))
        return

    coords_and_sizes = [((t.user_x, t.user_y), (t.width, t.height))
                        for t in chain]

    messages = []
    for i, (hsbks, coords_and_size) in enumerate(
            zip(
                applier.from_user_coords(coords_and_sizes).apply_theme(theme),
                coords_and_sizes)):
        colors = [{
            "hue": overrides.get("hue", hsbk.hue),
            "saturation": overrides.get("saturation", hsbk.saturation),
            "brightness": overrides.get("brightness", hsbk.brightness),
            "kelvin": overrides.get("kelvin", hsbk.kelvin)
        } for hsbk in hsbks]

        colors = reorient(colors, orientations.get(i, O.RightSideUp))

        messages.append(
            TileMessages.SetState64(tile_index=i,
                                    length=1,
                                    x=0,
                                    y=0,
                                    width=coords_and_size[1][0],
                                    duration=overrides.get("duration", 1),
                                    colors=colors,
                                    res_required=False,
                                    ack_required=True))

    set_power = LightMessages.SetLightPower(level=65535,
                                            duration=overrides.get(
                                                "duration", 1))
    pipeline = Pipeline(*messages, spread=0.005)
    await target.script([set_power, pipeline]).run_with_all(serial, afr)
コード例 #8
0
    async def gen(ref, sender, **kwargs):
        r = ref if reference is None else reference

        plans = {"set_zones": SetZonesPlan(colors, **options)}
        async for serial, _, messages in sender.gatherer.gather(
                plans, r, **kwargs):
            if messages is not Skip:
                if power_on:
                    yield LightMessages.SetLightPower(
                        level=65535,
                        target=serial,
                        duration=options.get("duration", 1),
                        ack_required=True,
                        res_required=False,
                    )

                yield messages
コード例 #9
0
    async def gen(ref, sender, **kwargs):
        r = ref if reference is None else reference

        ps = sender.make_plans("capability")
        async for serial, _, info in sender.gatherer.gather(ps, r, **kwargs):
            if info["cap"].has_matrix:
                if power_on:
                    yield LightMessages.SetLightPower(
                        level=65535,
                        target=serial,
                        duration=power_on_duration,
                        ack_required=True,
                        res_required=False,
                    )

                msg = set_effect.clone()
                msg.target = serial
                yield msg
コード例 #10
0
ファイル: theme.py プロジェクト: delfick/photons
        async def gen(reference, sender, **kwargs):
            serials = []
            canvases = []
            combined_canvas = Canvas()

            plans = sender.make_plans("parts")
            async for serial, _, info in sender.gatherer.gather(plans, reference, **kwargs):
                serials.append(serial)
                for part in info:
                    if part.device.cap.has_chain:
                        combined_canvas.add_parts(part)
                    else:
                        nxt = Canvas()
                        nxt.add_parts(part)
                        canvases.append(nxt)

            if combined_canvas:
                canvases.append(combined_canvas)

            msgs = []

            if options.power_on:
                for serial in serials:
                    msgs.append(
                        LightMessages.SetLightPower(
                            level=65535,
                            duration=options.duration,
                            target=serial,
                            res_required=False,
                        )
                    )

            for canvas in canvases:
                Applier(canvas, options.colors).apply()

                for msg in canvas.msgs(
                    options.override_layer, duration=options.duration, acks=True
                ):
                    msgs.append(msg)

            yield msgs
コード例 #11
0
        async it "can power on devices and set zones effect", sender:
            msg = SetZonesEffect("move")
            got = await sender(msg, devices.serials)
            assert got == []

            for strip in strips:
                assert strip.attrs.zones_effect is MultiZoneEffectType.MOVE

            self.compare_received(
                {
                    light1: [DeviceMessages.GetHostFirmware(), DeviceMessages.GetVersion()],
                    light2: [DeviceMessages.GetHostFirmware(), DeviceMessages.GetVersion()],
                    striplcm1: [
                        DeviceMessages.GetHostFirmware(),
                        DeviceMessages.GetVersion(),
                        LightMessages.SetLightPower(level=65535, duration=1),
                        MultiZoneMessages.SetMultiZoneEffect.create(type=MultiZoneEffectType.MOVE),
                    ],
                    striplcm2noextended: [
                        DeviceMessages.GetHostFirmware(),
                        DeviceMessages.GetVersion(),
                        LightMessages.SetLightPower(level=65535, duration=1),
                        MultiZoneMessages.SetMultiZoneEffect.create(type=MultiZoneEffectType.MOVE),
                    ],
                    striplcm2extended: [
                        DeviceMessages.GetHostFirmware(),
                        DeviceMessages.GetVersion(),
                        LightMessages.SetLightPower(level=65535, duration=1),
                        MultiZoneMessages.SetMultiZoneEffect.create(type=MultiZoneEffectType.MOVE),
                    ],
                }
コード例 #12
0
            else:
                await device.change_one("power", 0xFFFF, event=None)

        await server.assertCommand(
            "/v1/lifx/command",
            {"command": "power_toggle"},
            json_output=expected,
        )

        for device in devices:
            io = device.io["MEMORY"]
            if device.serial == "d073d5000001":
                assert (
                    devices.store(device).count(
                        Events.INCOMING(
                            device, io, pkt=LightMessages.SetLightPower(level=65535, duration=1)
                        )
                    )
                    == 1
                )
            else:
                assert (
                    devices.store(device).count(
                        Events.INCOMING(
                            device, io, pkt=LightMessages.SetLightPower(level=0, duration=1)
                        )
                    )
                    == 1
                )
            devices.store(device).clear()
コード例 #13
0
 async def turn_on(self, serial):
     msg = LightMessages.SetLightPower(level=65535, duration=1)
     await self.sender(msg, serial, **self.kwargs)
コード例 #14
0
            await device.assertResponse(
                DeviceMessages.GetPower(), [DeviceMessages.StatePower(level=0)]
            )
            await device.assertResponse(
                DeviceMessages.SetPower(level=200), [DeviceMessages.StatePower(level=0)], power=200
            )
            await device.assertResponse(
                DeviceMessages.GetPower(), [DeviceMessages.StatePower(level=200)], power=200
            )

        async it "responds to light power messages", device:
            await device.assertResponse(
                DeviceMessages.GetPower(), [DeviceMessages.StatePower(level=0)]
            )
            await device.assertResponse(
                LightMessages.SetLightPower(level=200),
                [LightMessages.StateLightPower(level=0)],
                power=200,
            )
            await device.assertResponse(
                DeviceMessages.GetPower(), [DeviceMessages.StatePower(level=200)], power=200
            )

        async it "responds to Color messages", device:

            def light_state(label, power, hue, saturation, brightness, kelvin):
                return LightMessages.LightState.empty_normalise(
                    label=label,
                    power=power,
                    hue=hue,
                    saturation=saturation,
コード例 #15
0
    async def generate_messages(self, reference, final_future, pauser=None):
        if pauser is None:
            pauser = asyncio.Condition()

        serials = await tile_serials_from_reference(reference, self.sender)
        state = TileStateGetter(self.target,
                                self.sender,
                                serials,
                                self.options.background,
                                coords=self.coords)
        await state.fill(random_orientations=self.random_orientations)

        by_serial = {}
        for serial in serials:
            by_serial[serial] = {
                "state": None,
                "coords": tuple(state.info_by_serial[serial].coords),
            }

        log.info("Starting!")

        await self.sender(LightMessages.SetLightPower(level=65535, duration=1),
                          serials)

        combined_coords = []
        for info in by_serial.values():
            combined_coords.extend(info["coords"])
        combined_info = {"state": None}

        start = None
        while True:
            combined_canvas = None
            if getattr(self.options, "combine_tiles", False):
                combined_state = combined_info["state"] = self.next_state(
                    combined_info["state"], combined_coords)
                combined_canvas = self.make_canvas(combined_state,
                                                   combined_coords)

            msgs = []
            for serial, info in by_serial.items():
                coords = info["coords"]

                canvas = combined_canvas
                if canvas is None:
                    info["state"] = self.next_state(info["state"], coords)
                    canvas = self.make_canvas(info["state"], coords)

                self.set_canvas_default_color_func(
                    canvas, state.info_by_serial[serial].default_color_func)

                reorient = state.info_by_serial[serial].reorient
                for msg in canvas_to_msgs(
                        canvas,
                        coords,
                        duration=self.duration,
                        reorient=reorient,
                        acks=self.retries,
                ):
                    msg.target = serial
                    msgs.append(msg)

            if start is not None:
                diff = time.time() - start
                if diff < self.every:
                    await asyncio.sleep(self.every - diff)
            start = time.time()

            async with pauser:
                if final_future.done():
                    break
                yield msgs

            if final_future.done():
                break
コード例 #16
0
ファイル: test_scene_spec.py プロジェクト: delfick/photons
                        result.append(want)

                    assert V.obj.colors_from_hsbks(hsbks, overrides) == result

        describe "power_message":
            it "does not provide SetLightPower if we have no power", V:
                V.obj.power = None
                msg = V.obj.power_message({})
                assert msg is None

            it "provides power if in overrides", V:
                V.obj.power = None
                V.obj.duration = None

                msg = V.obj.power_message({"power": "on"})
                assert msg == LightMessages.SetLightPower(level=65535, duration=0)

                msg = V.obj.power_message({"power": True})
                assert msg == LightMessages.SetLightPower(level=65535, duration=0)

                msg = V.obj.power_message({"power": False})
                assert msg == LightMessages.SetLightPower(level=0, duration=0)

                msg = V.obj.power_message({"power": "off"})
                assert msg == LightMessages.SetLightPower(level=0, duration=0)

                V.obj.duration = 2
                msg = V.obj.power_message({"power": "off"})
                assert msg == LightMessages.SetLightPower(level=0, duration=2)

            it "provides power if on the object", V:
コード例 #17
0
ファイル: animation.py プロジェクト: mic159/photons-core
    async def animate(self, reference, final_future, pauser=None):
        if pauser is None:
            pauser = asyncio.Condition()

        def errors(e):
            log.error(e)

        serials = await tile_serials_from_reference(self.target, reference,
                                                    self.afr)
        state = TileStateGetter(self.target,
                                self.afr,
                                serials,
                                self.options.background,
                                coords=self.coords)
        await state.fill(random_orientations=self.random_orientations)

        by_serial = {}
        for serial in serials:
            by_serial[serial] = {
                "state": None,
                "coords": tuple(state.info_by_serial[serial].coords)
            }

        log.info("Starting!")

        await self.target.script(
            LightMessages.SetLightPower(level=65535, duration=1)
        ).run_with_all(serials, self.afr)

        combined_coords = []
        for info in by_serial.values():
            combined_coords.extend(info["coords"])
        combined_info = {"state": None}

        while True:
            start = time.time()

            combined_canvas = None
            if getattr(self.options, "combine_tiles", False):
                combined_state = combined_info["state"] = self.next_state(
                    combined_info["state"], combined_coords)
                combined_canvas = self.make_canvas(combined_state,
                                                   combined_coords)

            msgs = []
            for serial, info in by_serial.items():
                coords = info["coords"]

                canvas = combined_canvas
                if canvas is None:
                    info["state"] = self.next_state(info["state"], coords)
                    canvas = self.make_canvas(info["state"], coords)

                canvas.set_default_color_func(
                    state.info_by_serial[serial].default_color_func)
                orientations = state.info_by_serial[serial].orientations
                for msg in canvas_to_msgs(canvas,
                                          coords,
                                          duration=self.duration,
                                          acks=self.acks,
                                          orientations=orientations):
                    msg.target = serial
                    msgs.append(msg)

            async with pauser:
                if final_future.done():
                    break
                await self.target.script(msgs).run_with_all(
                    None, self.afr, error_catcher=errors)

            if final_future.done():
                break

            diff = time.time() - start
            if diff < self.every:
                await asyncio.sleep(self.every - diff)
コード例 #18
0
    async def run_and_compare(self, runner, msg, *, expected):
        await runner.sender(msg, runner.serials)

        assert len(runner.devices) > 0

        for device in runner.devices:
            if device not in expected:
                assert False, f"No expectation for {device.serial}"

            device.compare_received(expected[device])

    async it "toggles the power", runner:
        expected = {
            light1: [
                DeviceMessages.GetPower(),
                LightMessages.SetLightPower(level=65535, duration=1),
            ],
            light2: [DeviceMessages.GetPower(), LightMessages.SetLightPower(level=0, duration=1)],
            light3: [DeviceMessages.GetPower(), LightMessages.SetLightPower(level=0, duration=1)],
        }
        await self.run_and_compare(runner, PowerToggle(), expected=expected)

        for device in runner.devices:
            device.received = []

        expected = {
            light1: [DeviceMessages.GetPower(), LightMessages.SetLightPower(level=0, duration=2)],
            light2: [
                DeviceMessages.GetPower(),
                LightMessages.SetLightPower(level=65535, duration=2),
            ],