class V:
            serials = ["d073d5000001", "d073d5000002", "d073d5000003"]

            d1 = FakeDevice(serials[0], chp.default_responders(Products.LCM3_TILE))
            d2 = FakeDevice(serials[1], chp.default_responders(Products.LCM2_Z, zones=[]))
            d3 = FakeDevice(
                serials[2],
                chp.default_responders(
                    Products.LCM2_A19,
                    firmware=chp.Firmware(2, 80, 1337),
                    group_uuid="aa",
                    group_label="g1",
                    group_updated_at=42,
                    location_uuid="bb",
                    location_label="l1",
                    location_updated_at=56,
                ),
            )

            @hp.memoized_property
            def devices(s):
                return [s.d1, s.d2, s.d3]
 def fake_device(self):
     return FakeDevice(
         "d073d5000001",
         chp.default_responders(
             Products.LCM2_A19,
             label="kitchen",
             firmware=chp.Firmware(2, 80, 1337),
             group_uuid="aa",
             group_label="g1",
             group_updated_at=42,
             location_uuid="bb",
             location_label="l1",
             location_updated_at=56,
         ),
     )
示例#3
0
# coding: spec

from photons_control import test_helpers as chp

from photons_control.transform import Transformer, PowerToggle
from photons_messages import DeviceMessages, LightMessages
from photons_control.colour import ColourParser
from photons_transport.fake import FakeDevice

import itertools
import random
import pytest

light1 = FakeDevice("d073d5000001", chp.default_responders(color=chp.Color(0, 1, 0.3, 2500)))

light2 = FakeDevice(
    "d073d5000002", chp.default_responders(power=65535, color=chp.Color(100, 1, 0.5, 2500))
)

light3 = FakeDevice(
    "d073d5000003", chp.default_responders(power=65535, color=chp.Color(100, 0, 0.8, 2500))
)


@pytest.fixture(scope="module")
async def runner(memory_devices_runner):
    async with memory_devices_runner([light1, light2, light3]) as runner:
        yield runner


@pytest.fixture(autouse=True)
示例#4
0
 def device(self):
     device = FakeDevice("d073d5001337", [])
     assert device.attrs._attrs == {"online": False}
     return device
示例#5
0
# coding: spec

from photons_transport.targets import MemoryTarget, LanTarget
from photons_transport.fake import FakeDevice

from photons_messages import DiscoveryMessages, Services, DeviceMessages, protocol_register

from collections import defaultdict
import asyncio

describe "Fake device":

    async it "works with sockets":
        device = FakeDevice("d073d5000001", [], use_sockets=True)

        options = {"final_future": asyncio.Future(), "protocol_register": protocol_register}
        target = MemoryTarget.create(options, {"devices": device})

        await device.start()
        assert len(device.services) == 1
        device_port = device.services[0].state_service.port

        async with target.session() as sender:
            msg = DiscoveryMessages.GetService()

            got = defaultdict(list)
            async for pkt in sender(msg, device.serial):
                got[pkt.serial].append(pkt.payload.as_dict())

            assert dict(got) == {"d073d5000001": [{"service": Services.UDP, "port": device_port}]}
示例#6
0
async def _setup():
    device = FakeDevice("d073d5001337", chp.default_responders(Products.LCM2_A19), use_sockets=True)
    async with device:
        options = {"final_future": asyncio.Future(), "protocol_register": protocol_register}
        target = MemoryTarget.create(options, {"devices": device})
        yield target, device
示例#7
0
from photons_control import test_helpers as chp
from photons_control.script import Pipeline

from photons_app.errors import RunErrors, TimedOut
from photons_app.special import FoundSerials

from photons_messages import DeviceMessages, LightMessages
from photons_transport.fake import FakeDevice

from collections import defaultdict
from itertools import chain
import asyncio
import pytest

light1 = FakeDevice("d073d5000001", chp.default_responders())
light2 = FakeDevice("d073d5000002", chp.default_responders())
light3 = FakeDevice("d073d5000003", chp.default_responders())


@pytest.fixture(scope="module")
async def runner(memory_devices_runner):
    async with memory_devices_runner([light1, light2, light3]) as runner:
        yield runner


@pytest.fixture(autouse=True)
async def reset_runner(runner):
    await runner.per_test()

示例#8
0
# coding: spec

from photons_control import test_helpers as chp

from photons_messages import MultiZoneEffectType, TileEffectType
from photons_transport.fake import FakeDevice
from photons_products import Products

from delfick_project.errors_pytest import assertRaises

describe "default_responders":
    async it "has defaults":
        device = FakeDevice("d073d5000001", chp.default_responders())
        await device.start()

        assert device.attrs.vendor_id == 1
        assert device.attrs.product_id == 27

        assert device.attrs.firmware == chp.Firmware(0, 0, 0)
        assert device.attrs.color == chp.Color(0, 1, 1, 3500)
        assert device.attrs.power == 0

        assert device.attrs.group_uuid == ""
        assert device.attrs.group_label == ""
        assert device.attrs.group_updated_at == 0

        assert device.attrs.location_uuid == ""
        assert device.attrs.location_label == ""
        assert device.attrs.location_updated_at == 0

        assert not any(isinstance(r, chp.ZonesResponder) for r in device.responders)
示例#9
0

def convert(c):
    c2 = {}
    c2["hue"] = int(c["hue"] / 360 * 65535) / 65535 * 360
    c2["saturation"] = int(c["saturation"] * 65535) / 65535
    c2["brightness"] = int(c["brightness"] * 65535) / 65535
    c2["kelvin"] = c["kelvin"]
    return c2


default_tile_palette = [convert(c) for c in default_tile_palette]

tile1 = FakeDevice(
    "d073d5000001",
    chp.default_responders(
        Products.LCM3_TILE, firmware_build=1548977726000000000, firmware_major=3, firmware_minor=50
    ),
)

tile2 = FakeDevice(
    "d073d5000002",
    chp.default_responders(
        Products.LCM3_TILE, firmware_build=1548977726000000000, firmware_major=3, firmware_minor=50
    ),
)

nottile = FakeDevice(
    "d073d5000003",
    chp.default_responders(
        Products.LMB_MESH_A21,
        firmware_build=1448861477000000000,
示例#10
0
        self.received = [
            m for m in self.received if m.__class__.__name__.startswith("Set")
        ]
        super().compare_received(expected, keep_duplicates=keep_duplicates)

    def expect_no_set_messages(self):
        assert not any([
            m for m in self.received if m.__class__.__name__.startswith("Set")
        ])


a19_1 = FakeDevice(
    "d073d5000001",
    chp.default_responders(
        Products.LCM2_A19,
        label="kitchen",
        power=0,
        color=chp.Color(0, 1, 1, 2500),
        firmware=chp.Firmware(2, 75, 1521690429),
    ) + [CollectionResponder(group=group_one, location=location_one)],
)

a19_2 = FakeDevice(
    "d073d5000002",
    chp.default_responders(
        Products.LCM2_A19,
        label="bathroom",
        power=65535,
        color=chp.Color(100, 1, 1, 2500),
        firmware=chp.Firmware(2, 75, 1521690429),
    ) + [CollectionResponder(group=group_two, location=location_one)],
)
示例#11
0
from photons_app.errors import BadRun, TimedOut, BadRunWithResults
from photons_app import helpers as hp

from photons_transport.errors import FailedToFindDevice
from photons_transport.fake import FakeDevice
from photons_messages import DeviceMessages

from delfick_project.errors_pytest import assertRaises
from collections import defaultdict
from functools import partial
import asyncio
import pytest

light1 = FakeDevice(
    "d073d5000001", chp.default_responders(power=0, color=chp.Color(0, 1, 0.3, 2500))
)

light2 = FakeDevice(
    "d073d5000002", chp.default_responders(power=65535, color=chp.Color(100, 1, 0.5, 2500))
)

light3 = FakeDevice("d073d5000003", chp.default_responders(color=chp.Color(100, 1, 0.5, 2500)))


@pytest.fixture(scope="module")
async def runner(memory_devices_runner):
    async with memory_devices_runner([light1, light2, light3]) as runner:
        yield runner

示例#12
0
# coding: spec

from photons_control import test_helpers as chp
from photons_control.script import find_serials

from photons_app.special import FoundSerials

from photons_transport.fake import FakeDevice

from delfick_project.norms import sb
import pytest

light1 = FakeDevice("d073d5000001", chp.default_responders())
light2 = FakeDevice("d073d5000002", chp.default_responders())
light3 = FakeDevice("d073d5000003", chp.default_responders())


@pytest.fixture(scope="module")
async def runner(memory_devices_runner):
    async with memory_devices_runner([light1, light2, light3]) as runner:
        yield runner


@pytest.fixture(autouse=True)
async def reset_runner(runner):
    await runner.per_test()


describe "Repeater":

    async it "can find all serials", runner:
示例#13
0
import pytest

describe "Searcher":
    it "takes in a sender":
        sender = mock.Mock(name="sender")
        searcher = Searcher(sender)

        assert isinstance(searcher.search_fut, hp.ResettableFuture)
        assert searcher.search_fut.done()

        assert searcher.sender is sender

    describe "getting serials":
        async it "can get serials", memory_devices_runner:
            serials = ["d073d5000001", "d073d5000002", "d073d5000003"]
            devices = [FakeDevice(serial, []) for serial in serials]

            async with memory_devices_runner(devices) as runner:
                searcher = Searcher(runner.sender)
                assert (await searcher._serials()) == serials

    describe "discover":

        @pytest.fixture()
        def searcher(self):
            return Searcher(mock.NonCallableMock(name="sender", spec=[]))

        async it "does a search if the search_fut is resolved as None", searcher:
            serials = mock.Mock(name="serials")

            async def _serials():
示例#14
0
from delfick_project.errors_pytest import assertRaises
import pytest


zeroColor = chp.Color(0, 0, 0, 3500)
zones1 = [chp.Color(i, 1, 1, 3500) for i in range(30)]
zones2 = [chp.Color(90 - i, 1, 1, 3500) for i in range(6)]
zones3 = [chp.Color(300 - i, 1, 1, 3500) for i in range(16)]

light1 = FakeDevice(
    "d073d5000001",
    chp.default_responders(
        Products.LCM3_TILE,
        power=0,
        label="bob",
        infrared=100,
        color=chp.Color(100, 0.5, 0.5, 4500),
        firmware=chp.Firmware(3, 50, 1548977726000000000),
    ),
)

light2 = FakeDevice(
    "d073d5000002",
    chp.default_responders(
        Products.LMB_MESH_A21,
        power=65535,
        label="sam",
        infrared=0,
        color=chp.Color(200, 0.3, 1, 9000),
        firmware=chp.Firmware(2, 2, 1448861477000000000),
示例#15
0
        if s.equal:
            return repr(s.equal)
        else:
            return f"<DIFFERENT: {repr(s.item)}>"


zones1 = [chp.Color(i, 1, 1, 3500) for i in range(30)]
zones2 = [chp.Color(60 - i, 1, 1, 6500) for i in range(20)]
zones3 = [chp.Color(90 - i, 1, 1, 9000) for i in range(40)]

light1 = FakeDevice(
    "d073d5000001",
    chp.default_responders(
        Products.LCM3_TILE,
        power=0,
        label="bob",
        infrared=100,
        color=chp.Color(100, 0.5, 0.5, 4500),
        firmware=chp.Firmware(3, 50, 1548977726000000000),
    ),
)

light2 = FakeDevice(
    "d073d5000002",
    chp.default_responders(
        Products.LMB_MESH_A21,
        power=65535,
        label="sam",
        infrared=0,
        color=chp.Color(200, 0.3, 1, 9000),
        firmware=chp.Firmware(2, 2, 1448861477000000000),
示例#16
0
 def __init__(self, *responders):
     self.device = FakeDevice("d073d5000001", responders)