# 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)
location=device.attrs.location.uuid, label=device.attrs.location.label, updated_at=device.attrs.location.updated_at, ) identifier = lambda: str(uuid.uuid4()).replace("-", "") group_one = Collection(identifier(), "Living Room", 0) group_two = Collection(identifier(), "Bathroom", 0) location_one = Collection(identifier(), "Home", 0) location_two = Collection(identifier(), "Work", 0) group_three = Collection(identifier(), "desk", 0) zones = [] for i in range(16): zones.append(chp.Color(i * 10, 1, 1, 2500)) class FakeDevice(FakeDevice): def compare_received_set(self, expected, keep_duplicates=False): 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") ])
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) assert not any(isinstance(r, chp.MatrixResponder) for r in device.responders) assert not any(isinstance(r, chp.InfraredResponder) for r in device.responders) for expect in (chp.ProductResponder, chp.LightStateResponder, chp.GroupingResponder):
def hsbk(*args, **kwargs): h, s, b, k = ColourParser.hsbk(*args, **kwargs) return chp.Color(h, s, b, k)
from photons_control.planner import Skip, NoMessages from photons_control import test_helpers as chp from photons_control.colour import ColourParser from photons_app.errors import PhotonsAppError from photons_messages import DeviceMessages, LightMessages, MultiZoneMessages, MultiZoneEffectType from photons_products.registry import Capability from photons_transport.fake import FakeDevice from photons_products import Products 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), ), )
s.equal = None def __eq__(s, other): print(f"Item {s.index}") assert_payloads_equals(other, s.item) s.equal = other return True def __repr__(s): 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), ), )
async def device(self): device = Device(chp.LightStateResponder()) async with device: device.assertAttrs(label="", power=0, color=chp.Color(0, 0, 1, 3500)) yield device
async with device: device.assertAttrs(matrix_effect=TileEffectType.OFF) yield device async it "responds to tile effect messages", device: await device.assertResponse( TileMessages.GetTileEffect(), [ TileMessages.StateTileEffect.empty_normalise( type=TileEffectType.OFF, palette_count=0, parameters={} ) ], ) await device.assertResponse( TileMessages.SetTileEffect( type=TileEffectType.FLAME, palette_count=1, palette=[chp.Color(1, 0, 1, 3500)] ), [ TileMessages.StateTileEffect.empty_normalise( type=TileEffectType.OFF, palette_count=0, parameters={}, palette=[] ) ], matrix_effect=TileEffectType.FLAME, ) await device.assertResponse( TileMessages.GetTileEffect(), [ TileMessages.StateTileEffect.empty_normalise( type=TileEffectType.FLAME, palette_count=1, parameters={},