예제 #1
0
 async def execute(self):
     fltr = chp.filter_from_matcher(self.matcher, self.refresh)
     msg = Transformer.using(self.transform, **self.transform_options)
     script = self.target.script(msg)
     return await chp.run(
         script, fltr, self.finder, add_replies=False, message_timeout=self.timeout
     )
예제 #2
0
    def apply_scene(scene):
        transformer = Transformer()

        async def gen(reference, sender, **kwargs):
            for state in scene.values():
                if "power" in state:
                    yield transformer.power_message(state)
                if "color" in state:
                    yield transformer.color_message(state,
                                                    keep_brightness=False)

        return FromGenerator(gen)
예제 #3
0
    async def transform(
        self, runner, state, *, expected, keep_brightness=False, transition_color=False
    ):
        msg = Transformer.using(
            state, keep_brightness=keep_brightness, transition_color=transition_color
        )
        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])
예제 #4
0
    async def transform(self, fltr, scene, result):
        options = scene.transform_options
        options.update(self.overrides)

        msg = Transformer.using(options)
        script = self.target.script(msg)
        try:
            await chp.run(
                script,
                fltr,
                self.finder,
                add_replies=False,
                message_timeout=self.timeout,
                result=result,
            )
        except FoundNoDevices:
            pass
예제 #5
0
    async def transform(
        self, sender, state, *, expected, keep_brightness=False, transition_color=False
    ):
        msg = Transformer.using(
            state, keep_brightness=keep_brightness, transition_color=transition_color
        )
        await sender(msg, devices.serials)

        assert len(devices) > 0

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

        for device, msgs in expected.items():
            assert device in devices
            devices.store(device).assertIncoming(*msgs, ignore=[DiscoveryMessages.GetService])
            devices.store(device).clear()
예제 #6
0
    ):
        msg = Transformer.using(
            state, keep_brightness=keep_brightness, transition_color=transition_color
        )
        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 "returns an empty list if no power or color options":
        assert Transformer.using({}) == []

    async it "Uses SetPower if no duration", runner:
        msg = DeviceMessages.SetPower(level=0, res_required=False)
        expected = {device: [msg] for device in runner.devices}
        await self.transform(runner, {"power": "off"}, expected=expected)

        await runner.reset_devices()
        msg = DeviceMessages.SetPower(level=65535, res_required=False)
        expected = {device: [msg] for device in runner.devices}
        await self.transform(runner, {"power": "on"}, expected=expected)

    async it "uses SetLightPower if we have duration", runner:
        msg = LightMessages.SetLightPower(level=0, duration=100, res_required=False)
        expected = {device: [msg] for device in runner.devices}
        await self.transform(runner, {"power": "off", "duration": 100}, expected=expected)
예제 #7
0
파일: control.py 프로젝트: delfick/photons
 async def execute(self):
     msg = Transformer.using(self.transform, **self.transform_options)
     return await self.send(msg, add_replies=False)