Пример #1
0
        class V:
            serials = ["d073d5000001", "d073d5000002", "d073d5000003", "d073d5000004"]
            devices = pytest.helpers.mimic()

            d1 = devices.add("d1")(serials[0], Products.LCM3_TILE, hp.Firmware(3, 50))
            d2 = devices.add("d2")(
                serials[1], Products.LCM2_Z, hp.Firmware(2, 80), value_store=dict(zones=[])
            )
            d3 = devices.add("d3")(
                serials[2],
                Products.LCM2_A19,
                hp.Firmware(2, 80),
                value_store=dict(
                    label="deethree",
                    group={"identity": "aa", "label": "g1", "updated_at": 42},
                    location={"identity": "bb", "label": "l1", "updated_at": 56},
                ),
            )
            d4 = devices.add("d4")(
                serials[3],
                Products.LCM3_32_SWITCH_I,
                hp.Firmware(3, 90),
                value_store=dict(
                    label="switchstacle",
                    group={"identity": "aa", "label": "g1", "updated_at": 42},
                    location={"identity": "bb", "label": "l1", "updated_at": 56},
                ),
            )
Пример #2
0
def device():
    return Device(
        "d073d5001337",
        Products.LCM2_A19,
        hp.Firmware(2, 80),
        value_store={"only_io_and_viewer_operators": True},
    )
Пример #3
0
        class V:
            serials = ["d073d5000001", "d073d5000002", "d073d5000003"]
            devices = pytest.helpers.mimic()

            d1 = devices.add("d1")(serials[0], Products.LCM3_TILE, hp.Firmware(3, 50))
            d2 = devices.add("d2")(
                serials[1], Products.LCM2_Z, hp.Firmware(2, 80), value_store=dict(zones=[])
            )
            d3 = devices.add("d3")(
                serials[2],
                Products.LCM2_A19,
                hp.Firmware(2, 80),
                value_store=dict(
                    label="kitchen",
                    firmware=hp.Firmware(2, 80),
                    group={"identity": "aa", "label": "g1", "updated_at": 42},
                    location={"identity": "bb", "label": "l1", "updated_at": 56},
                ),
            )
Пример #4
0
 def make_device(has_memory=True, has_udp=False, value_store=None):
     return Device(
         "d073d5001337",
         Products.LCM2_A19,
         hp.Firmware(2, 80),
         lambda d: Responder(d),
         value_store={
             "no_memory_io": not has_memory,
             "no_udp_io": not has_udp,
             "only_io_and_viewer_operators": True,
             **(value_store or {}),
         },
     )
Пример #5
0
 async def device(self, record, Responder, final_future, iokls, got_event):
     device = Device(
         "d073d5001337",
         Products.LCM2_A19,
         hp.Firmware(2, 80),
         lambda d: iokls(d),
         lambda d: Listener(d),
         lambda d: Responder(d),
         lambda d: RecordEvents(
             d, {"record_events_store": record, "got_event_fut": got_event}
         ),
         search_for_operators=False,
     )
     async with device.session(final_future):
         record.clear()
         yield device
Пример #6
0
 async def switch(self, record, Responder, final_future, iokls, got_event):
     device = Device(
         "d073d5001338",
         Products.LCM3_16_SWITCH,
         hp.Firmware(3, 70),
         lambda d: iokls(d),
         lambda d: Listener(d),
         lambda d: Responder(d),
         lambda d: RecordEvents(
             d, {"record_events_store": record, "got_event_fut": got_event}
         ),
         search_for_operators=False,
     )
     async with device.session(final_future):
         if record and record[-1] | Events.RESET:
             record.pop()
         yield device
Пример #7
0
    def set_from_pkt(self, pkt, collections):
        """
        Set information from the provided pkt.

        collections is used for determining the group/location based on the pkt.

        We return a InfoPoints enum representing what type of information was set.
        """
        if pkt | LightMessages.LightState:
            self.label = pkt.label
            self.power = "off" if pkt.power == 0 else "on"
            self.hue = pkt.hue
            self.saturation = pkt.saturation
            self.brightness = pkt.brightness
            self.kelvin = pkt.kelvin
            return InfoPoints.LIGHT_STATE

        elif pkt | DeviceMessages.StateLabel:
            self.label = pkt.label
            return InfoPoints.LABEL

        elif pkt | DeviceMessages.StateGroup:
            uuid = binascii.hexlify(pkt.group).decode()
            self.group = collections.add_group(uuid, pkt.updated_at, pkt.label)
            return InfoPoints.GROUP

        elif pkt | DeviceMessages.StateLocation:
            uuid = binascii.hexlify(pkt.location).decode()
            self.location = collections.add_location(uuid, pkt.updated_at, pkt.label)
            return InfoPoints.LOCATION

        elif pkt | DeviceMessages.StateHostFirmware:
            self.firmware = hp.Firmware(pkt.version_major, pkt.version_minor, pkt.build)
            return InfoPoints.FIRMWARE

        elif pkt | DeviceMessages.StateVersion:
            self.product_id = pkt.product
            return InfoPoints.VERSION
Пример #8
0
def device2():
    return Device("d073d5001338", Products.LCM3_TILE, hp.Firmware(3, 50))
Пример #9
0
def device():
    return Device("d073d5001337", Products.LCM2_A19, hp.Firmware(2, 80))
Пример #10
0
# coding: spec

from photons_control.script import find_serials

from photons_app.special import FoundSerials
from photons_app import helpers as hp

from photons_products import Products

from delfick_project.norms import sb
import pytest

devices = pytest.helpers.mimic()

light1 = devices.add("light1")("d073d5000001", Products.LCM2_A19, hp.Firmware(2, 80))
light2 = devices.add("light2")("d073d5000002", Products.LCM2_A19, hp.Firmware(2, 80))
light3 = devices.add("light3")("d073d5000003", Products.LCM2_A19, hp.Firmware(2, 80))


@pytest.fixture(scope="module")
def final_future():
    fut = hp.create_future()
    try:
        yield fut
    finally:
        fut.cancel()


@pytest.fixture(scope="module")
async def sender(final_future):
    async with devices.for_test(final_future) as sender:
Пример #11
0
group_three_uuid = identifier()

location_one_label = "Home"
location_one_uuid = identifier()

location_two_label = "Work"
location_two_uuid = identifier()

zones = []
for i in range(16):
    zones.append(hp.Color(i * 10, 1, 1, 2500))

ds.add("a19_1")(
    next(ds.serial_seq),
    Products.LCM2_A19,
    hp.Firmware(2, 75),
    value_store=dict(
        label="kitchen",
        power=0,
        group={
            "label": group_one_label,
            "identity": group_one_uuid
        },
        location={
            "label": location_one_label,
            "identity": location_one_uuid
        },
        color=hp.Color(0, 1, 1, 2500),
    ),
)
Пример #12
0
    TileMessages,
    MultiZoneMessages,
    Waveform,
    TileEffectType,
    MultiZoneEffectType,
    LightLastHevCycleResult,
)

import pytest

devices = pytest.helpers.mimic()

devices.add("a19")(
    next(devices.serial_seq),
    Products.LCM2_A19,
    hp.Firmware(2, 80),
    value_store=dict(
        group={"label": "gl", "identity": "abcd", "updated_at": 1},
        location={"label": "ll", "identity": "efef", "updated_at": 2},
    ),
)

devices.add("color1000")(next(devices.serial_seq), Products.LCMV4_A19_COLOR, hp.Firmware(1, 23))

devices.add("lcm3a19")(next(devices.serial_seq), Products.LCM3_A19, hp.Firmware(3, 60))

devices.add("ir")(next(devices.serial_seq), Products.LCM2_A19_PLUS, hp.Firmware(2, 80))

devices.add("tile")(next(devices.serial_seq), Products.LCM3_TILE, hp.Firmware(3, 50))

devices.add("clean")(next(devices.serial_seq), Products.LCM3_A19_CLEAN, hp.Firmware(3, 50))
Пример #13
0
from delfick_project.errors_pytest import assertRaises
import pytest


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

devices = pytest.helpers.mimic()

light1 = devices.add("light1")(
    "d073d5000001",
    Products.LCM3_TILE,
    hp.Firmware(3, 50),
    value_store=dict(
        power=0,
        label="bob",
        infrared=100,
        color=hp.Color(100, 0.5, 0.5, 4500),
    ),
)

light2 = devices.add("light2")(
    "d073d5000002",
    Products.LMB_MESH_A21,
    hp.Firmware(2, 2),
    value_store=dict(
        power=65535,
        label="sam",
Пример #14
0
from photons_app.mimic.event import Events
from photons_app import helpers as hp

from photons_messages import LightMessages, DeviceMessages
from photons_products import Products

from delfick_project.errors_pytest import assertRaises
from unittest import mock
import asyncio
import pytest

devices = pytest.helpers.mimic()
devices.add("light")(
    next(devices.serial_seq),
    Products.LCM2_A19,
    hp.Firmware(2, 80),
    value_store=dict(
        label="kitchen",
        firmware=hp.Firmware(2, 80),
        group={"identity": "aa", "label": "g1", "updated_at": 42},
        location={"identity": "bb", "label": "l1", "updated_at": 56},
    ),
)
devices.add("switch")(
    next(devices.serial_seq),
    Products.LCM3_32_SWITCH_I,
    hp.Firmware(3, 90),
    value_store=dict(
        label="switcharoo",
        group={"identity": "aa", "label": "g1", "updated_at": 42},
        location={"identity": "bb", "label": "l1", "updated_at": 56},
Пример #15
0
)
from photons_products import Products

from delfick_project.errors_pytest import assertRaises
import pytest


def convert(c):
    return hp.Color(c["hue"], c["saturation"], c["brightness"], c["kelvin"]).as_dict()


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

devices = pytest.helpers.mimic()

tile1 = devices.add("tile1")("d073d5000001", Products.LCM3_TILE, hp.Firmware(3, 50))
tile2 = devices.add("tile2")("d073d5000002", Products.LCM3_TILE, hp.Firmware(3, 50))

nottile = devices.add("nottile")("d073d5000003", Products.LMB_MESH_A21, hp.Firmware(2, 2))

tiles = [tile1, tile2]


@pytest.fixture(scope="module")
def final_future():
    fut = hp.create_future()
    try:
        yield fut
    finally:
        fut.cancel()
Пример #16
0
def device():
    return Device("d073d5001337", Products.LCM2_A19, hp.Firmware(2, 80), search_for_operators=False)
from photons_canvas.points.simple_messages import MultizoneMessagesMaker

from photons_app import helpers as hp

from photons_products import Products

import pytest

devices = pytest.helpers.mimic()


devices.add("striplcm1")(
    "d073d5000003",
    Products.LCM1_Z,
    hp.Firmware(1, 22),
    value_store=dict(
        power=0,
        label="lcm1-no-extended",
        zones=[hp.Color(0, 0, 0, 0)] * 16,
    ),
)

devices.add("striplcm2noextended")(
    "d073d5000004",
    Products.LCM2_Z,
    hp.Firmware(2, 70),
    value_store=dict(
        power=0,
        label="lcm2-no-extended",
        zones=[hp.Color(0, 0, 0, 0)] * 16,
Пример #18
0
from photons_control.clean import SetCleanConfig, ChangeCleanCycle

from photons_app import helpers as hp

from photons_messages import DeviceMessages, LightMessages, DiscoveryMessages

from photons_products import Products

import pytest

devices = pytest.helpers.mimic()

light1 = devices.add("light1")(
    "d073d5000001",
    Products.LCM3_A19_CLEAN,
    hp.Firmware(3, 70),
    value_store=dict(
        power=0,
        color=hp.Color(0, 1, 0.3, 2500),
    ),
)

light2 = devices.add("light2")(
    "d073d5000002",
    Products.LCM3_A19_CLEAN,
    hp.Firmware(3, 70),
    value_store=dict(
        power=65535,
        indication=True,
        color=hp.Color(100, 1, 0.5, 2500),
    ),
Пример #19
0
from photons_app.mimic.operators.relays import Relay, RelayPowerGetter
from photons_app.mimic.event import Events
from photons_app import helpers as hp

from photons_products import Products
from photons_messages import DeviceMessages, RelayMessages

import pytest

devices = pytest.helpers.mimic()

devices.add("switch")(
    next(devices.serial_seq),
    Products.LCM3_32_SWITCH_I,
    hp.Firmware(3, 80),
    value_store=dict(
        group={"label": "gl", "identity": "abcd", "updated_at": 1},
        location={"label": "ll", "identity": "efef", "updated_at": 2},
    ),
)


@pytest.fixture(scope="module")
def final_future():
    fut = hp.create_future()
    try:
        yield fut
    finally:
        fut.cancel()
Пример #20
0
        assertChange("hue", 20)
        assertChange("saturation", 0.5)
        assertChange("brightness", 0.6)
        assertChange("kelvin", 2500)

        device.product_id = 32
        info["product_name"] = values["product_name"] = "LIFX Z"
        info["product_type"] = "light"
        info["product_id"] = values["product_id"] = 32
        info["cap"] = values["cap"] = pytest.helpers.has_caps_list(
            "color", "multizone", "variable_color_temp"
        )
        assert device.info == info
        assert device.as_dict() == values

        device.firmware = hp.Firmware(2, 80)
        values["firmware_version"] = "2.80"
        values["cap"] = pytest.helpers.has_caps_list(
            "color", "extended_multizone", "multizone", "variable_color_temp"
        )
        assert device.info == values
        assert device.as_dict() == values

    describe "matches_fltr":
        it "says yes if the filter matches all", device:
            device.label = "kitchen"
            device.power = "on"
            filtr = Filter.empty()
            assert filtr.matches_all
            assert device.matches_fltr(filtr)
Пример #21
0
from delfick_project.errors_pytest import assertRaises, assertSameError
from contextlib import contextmanager
from collections import defaultdict
from functools import partial
import asyncio
import pytest
import time
import sys

devices = pytest.helpers.mimic()


light1 = devices.add("light1")(
    "d073d5000001",
    Products.LCM2_A19,
    hp.Firmware(2, 80),
    value_store=dict(power=0, color=hp.Color(0, 1, 0.3, 2500)),
)

light2 = devices.add("light2")(
    "d073d5000002",
    Products.LCM2_A19,
    hp.Firmware(2, 80),
    value_store=dict(power=65535, color=hp.Color(100, 1, 0.5, 2500)),
)

light3 = devices.add("light3")(
    "d073d5000003",
    Products.LCM2_A19,
    hp.Firmware(2, 80),
    value_store=dict(color=hp.Color(100, 1, 0.5, 2500)),
Пример #22
0
        if s.equal:
            return repr(s.equal)
        else:
            return f"<DIFFERENT: {repr(s.item)}>"


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

devices = pytest.helpers.mimic()

light1 = devices.add("light1")(
    next(devices.serial_seq),
    Products.LCM3_TILE,
    hp.Firmware(3, 50),
    value_store=dict(
        power=0,
        label="bob",
        infrared=100,
        color=hp.Color(100, 0.5, 0.5, 4500),
    ),
)

light2 = devices.add("light2")(
    next(devices.serial_seq),
    Products.LMB_MESH_A21,
    hp.Firmware(2, 2),
    value_store=dict(
        power=65535,
        label="sam",
Пример #23
0
from photons_messages import (
    DeviceMessages,
    CoreMessages,
    MultiZoneMessages,
    DiscoveryMessages,
    Services,
)
from photons_products import Products

from delfick_project.errors_pytest import assertRaises
import pytest
import time

devices = pytest.helpers.mimic()
devices.add("strip")(
    "d073d5001337", Products.LCM2_Z, hp.Firmware(2, 80), value_store={"zones_count": 22}
)


@pytest.fixture()
async def sender(final_future):
    async with devices.for_test(final_future) as sender:
        await FoundSerials().find(sender, timeout=1)
        sender.received.clear()
        for store in devices.stores.values():
            store.clear()
        yield sender


@pytest.fixture(autouse=True)
async def reset_devices(sender):
Пример #24
0
from photons_app import helpers as hp

from photons_messages import DeviceMessages, CoreMessages
from photons_control.script import FromGenerator
from photons_products import Products

from delfick_project.errors_pytest import assertSameError
from collections import defaultdict
from unittest import mock
import asyncio
import pytest
import sys

devices = pytest.helpers.mimic(has_udp=True, has_memory=False)

devices.add("one")("d073d5001337", Products.LCM2_A19, hp.Firmware(2, 77))
devices.add("two")("d073d5001338", Products.LCM2_A19, hp.Firmware(2, 77))


@pytest.fixture()
async def sender(final_future):
    async with devices.for_test(final_future, udp=True) as sender:
        yield sender


describe "Sending messages":

    @pytest.fixture
    def V(self, sender):
        class V:
            target = sender.transport_target