Exemplo n.º 1
0
        def process(self, pkt):
            if self.zones is Zones.LINEAR:
                self.result = [(0, [c for _, c in self.deps["zones"]])]
                return True

            if self.zones is Zones.SINGLE and pkt | LightMessages.LightState:
                self.result = [(0, [Color(pkt.hue, pkt.saturation, pkt.brightness, pkt.kelvin)])]
                return True

            if pkt | TileMessages.State64:
                colors = self.deps["chain"]["reverse_orient"](pkt.tile_index, pkt.colors)
                self.result.append((pkt.tile_index, colors))

                if len(self.result) == len(self.deps["chain"]["chain"]):
                    return True
Exemplo n.º 2
0
            def assert_colors(cs, *hues):
                colors = []
                for h in hues:
                    if h is None:
                        colors.append((0, 0, 0, 0))
                    else:
                        colors.append((h, 1, 1, 3500))

                while len(colors) != 64:
                    colors.append((0, 0, 0, 0))

                colors = [Color(*c) for c in colors]
                for i, (got, want) in enumerate(zip(cs, colors)):
                    if got != want:
                        print(i, got, want)

                assert cs == colors
Exemplo n.º 3
0
    def make_new_messages(self):
        if not self.colors:
            return

        colors = []
        for c in self.colors:
            if isinstance(c, dict) or getattr(c, "is_dict", False):
                colors.append(c)
            else:
                colors.append(Color(*c))

        return (MultiZoneMessages.SetExtendedColorZones(
            duration=self.duration,
            colors_count=len(self.colors),
            colors=colors,
            target=self.serial,
            zone_index=self.zone_index,
            ack_required=True,
            res_required=False,
        ), )
Exemplo n.º 4
0
            with_colors = await self.gather(sender, [device.serial], "parts_and_colors")
            info = with_colors[device.serial][1]["parts_and_colors"]

            assert len(info) == 1
            pc = info[0]

            colors = [(c.hue, c.saturation, c.brightness, c.kelvin) for c in colors]
            assert pc is part
            assert pc.original_colors == colors
            assert pc.real_part.original_colors == colors

        async it "works for a tile set", sender:
            device = light1

            colors1 = [Color(i, 1, 1, 3500) for i in range(64)]
            colors2 = [Color(i + 100, 0, 0.4, 8000) for i in range(64)]
            colors3 = [Color(i + 200, 0.1, 0.9, 7000) for i in range(64)]

            await device.change(
                (("chain", 0, "colors"), co.reorient(colors1, co.Orientation.RotatedLeft)),
                (("chain", 0, "accel_meas_x"), -10),
                (("chain", 0, "accel_meas_y"), 1),
                (("chain", 0, "accel_meas_z"), 5),
                (("chain", 0, "user_x"), 3),
                (("chain", 0, "user_y"), 5),
                #
                (("chain", 1, "colors"), colors2),
                #
                (("chain", 2, "accel_meas_x"), 1),
                (("chain", 2, "accel_meas_y"), 5),
Exemplo n.º 5
0
        simple.update({**dict(changes), "target": "d073d5998877"})
        assertSame(real, simple)
        assertSame(real, simple.clone())

    it "can be cloned":
        msg = Set64(width=6, tile_index=20)
        clone = msg.clone()
        assert clone.pack() == msg.pack()

        clone.width = 8
        assert clone.width == 8
        assert msg.width == 6

    it "can be given colors in multiple ways", seed:

        c1 = Color(100, 1, 1, 3500)
        c2 = Color(200, 0, 0, 3500)

        setting = [
            (c1.hue, c1.saturation, c1.brightness, c1.kelvin),
            (c2.hue, c2.saturation, c2.brightness, c2.kelvin),
        ]
        real = seed.clone()
        real.colors = [Color(h, s, b, k) for h, s, b, k in setting]

        simple = Set64(colors=setting)
        r = real.payload.pack()
        w = simple.pack()[36 * 8 :]

        assert len(r) == len(w)
        assert r == w
Exemplo n.º 6
0
            dct = {
                "x": 0,
                "y": 0,
                "length": 1,
                "tile_index": 3,
                "colors": rotated,
                "ack_required": False,
                "width": 8,
                "duration": 200,
                "res_required": False,
            }

            for k, v in dct.items():
                if k == "colors":
                    v = [Color(*c) for c in rotated]
                assert getattr(msgs[0], k) == v

            assert isinstance(msgs[0], Set64)

        describe "Caching":
            it "it sends same messages or NO_MESSAGES depending on time and difference", FakeTime, V:
                colors = [(i, 1, 1, 3500) for i in range(64)]
                device = cont.Device("d073d5001337", Products.LCM3_TILE.cap)

                with FakeTime() as t:
                    t.set(2)
                    part = V.make_part(
                        device, 3, orientation=Orientation.RotatedLeft, original_colors=colors
                    )
                    assert part.next_force_send == 1
Exemplo n.º 7
0
            real_part2 = V.make_part(V.device, 3)
            real_part3 = V.make_part(V.other_device, 5, original_colors=oc2)

            part1 = V.make_part(V.device, 1)
            part2 = V.make_part(V.device, 2, real_part=real_part1)
            part3 = V.make_part(V.device, 3, real_part=real_part2)
            part4 = V.make_part(V.other_device, 5, real_part=real_part3)

            canvas = Canvas()
            canvas.add_parts(part1, part2, part3, part4)

            msgs = list(canvas.restore_msgs(duration=3))
            assert len(msgs) == 2
            assert all(m | TileMessages.Set64 for m in msgs)

            assert msgs[0].colors == [Color(*c) for c in oc1]
            assert msgs[1].colors == [Color(*c) for c in oc2]

            assert msgs[0].serial == V.device.serial
            assert msgs[1].serial == V.other_device.serial

            assert msgs[0].tile_index == 2
            assert msgs[1].tile_index == 5

    describe "msgs":
        it "gets colours from the layer", V:
            info = {"canvas": None}

            def layer(point, canvas):
                assert info["canvas"] is not None
                assert canvas is info["canvas"]
Exemplo n.º 8
0
 def normalise_filled(self, meta, val):
     overrides = meta.everything.get("overrides", {})
     return [
         Color(**color) for i, color in enumerate(make_hsbks([[c, 1] for c in val], overrides))
     ]
Exemplo n.º 9
0
def effects_running_status():
    return {
        "results": {
            "d073d5000001": {
                "effect": {"type": "SKIP"},
                "product": {"cap": mock.ANY, "name": "LCM2_A19", "pid": 27, "vid": 1},
            },
            "d073d5000002": {
                "effect": {"type": "SKIP"},
                "product": {"cap": mock.ANY, "name": "LCM2_A19", "pid": 27, "vid": 1},
            },
            "d073d5000003": {
                "effect": {"type": "SKIP"},
                "product": {"cap": mock.ANY, "name": "LCMV4_A19_COLOR", "pid": 22, "vid": 1},
            },
            "d073d5000004": {
                "effect": {"type": "SKIP"},
                "product": {"cap": mock.ANY, "name": "LCMV4_A19_WHITE_LV", "pid": 10, "vid": 1},
            },
            "d073d5000005": {
                "effect": {
                    "options": {
                        "duration": 0.0,
                        "instanceid": mock.ANY,
                        "speed": 0.005,
                        "speed_direction": "RIGHT",
                    },
                    "type": "MOVE",
                },
                "product": {"cap": mock.ANY, "name": "LCM2_Z", "pid": 32, "vid": 1},
            },
            "d073d5000006": {
                "effect": {
                    "options": {
                        "duration": 0.0,
                        "instanceid": mock.ANY,
                        "speed": 0.005,
                        "speed_direction": "RIGHT",
                    },
                    "type": "MOVE",
                },
                "product": {"cap": mock.ANY, "name": "LCM1_Z", "pid": 31, "vid": 1},
            },
            "d073d5000007": {
                "effect": {
                    "options": {
                        "duration": 0.0,
                        "instanceid": mock.ANY,
                        "palette": [Color(**color).as_dict() for color in default_tile_palette],
                        "speed": 0.005,
                    },
                    "type": "MORPH",
                },
                "product": {"cap": mock.ANY, "name": "LCM3_CANDLE", "pid": 57, "vid": 1},
            },
            "d073d5000008": {
                "effect": {
                    "options": {
                        "duration": 0.0,
                        "instanceid": mock.ANY,
                        "palette": [],
                        "speed": 0.005,
                    },
                    "type": "OFF",
                },
                "product": {"cap": mock.ANY, "name": "LCM3_TILE", "pid": 55, "vid": 1},
            },
            "d073d5000009": {
                "effect": {"type": "SKIP"},
                "product": {"cap": mock.ANY, "name": "LCM3_A19_CLEAN", "pid": 90, "vid": 1},
            },
            "d073d500000a": {
                "effect": {"type": "SKIP"},
                "product": {"cap": mock.ANY, "name": "LCM3_32_SWITCH_I", "pid": 89, "vid": 1},
            },
        }
    }