def make_hsbks(self, colors, overrides): results = list(make_hsbks(colors, overrides)) if len(results) > 82: raise PhotonsAppError("colors can only go up to 82 colors", got=len(results)) if not results: raise PhotonsAppError("No colors were specified") return results
colorRed = hsbk("red", overrides={"brightness": 1.0, "kelvin": 3500}) colorBlue = hsbk("blue", overrides={"brightness": 1.0, "kelvin": 3500}) colorHSBK = hsbk("hue:78 brightness:0.5", overrides={"saturation": 0, "kelvin": 3500}) colorHEX = hsbk("#234455", overrides={"kelvin": 3500}) expected = [colorRed] * 10 + [colorBlue] * 3 + [colorHSBK] * 5 + [colorHEX] * 2 for _ in range(2): expected.append({"hue": 100, "saturation": 0, "brightness": 1, "kelvin": 3500}) expected.append({"hue": 100, "saturation": 0.5, "brightness": 1, "kelvin": 3500}) expected.append({"hue": 100, "saturation": 0.5, "brightness": 0.5, "kelvin": 3500}) expected.append({"hue": 100, "saturation": 0.5, "brightness": 0.5, "kelvin": 9000}) expected.append({"hue": 0, "saturation": 0, "brightness": 0, "kelvin": 0}) expected.append({"hue": 120, "saturation": 1, "brightness": 1, "kelvin": 9000}) assert list(make_hsbks(colors)) == expected it "can overrides hue", colors: colors = list(make_hsbks(colors, overrides={"hue": 1})) for c in colors: assert c["hue"] == 1 it "can overrides saturation", colors: colors = list(make_hsbks(colors, overrides={"saturation": 0.3})) for c in colors: assert c["saturation"] == 0.3 it "can overrides brightness", colors: colors = list(make_hsbks(colors, overrides={"brightness": 0.6})) for c in colors:
def SetTileEffect(effect, power_on=True, power_on_duration=1, reference=None, **options): """ Set an effect on your tiles Where effect is one of the available effect types: OFF Turn the animation off FLAME A flame effect MORPH A Morph effect Options include: * speed * duration * palette Usage looks like: .. code-block:: python msg = SetTileEffect("MORPH", palette=["red", "blue", "green"]) await target.send(msg, reference) By default the devices will be powered on. If you don't want this to happen then pass in ``power_on=False``. If you want to target a particular device or devices, pass in reference. """ typ = effect if type(effect) is str: for e in TileEffectType: if e.name.lower() == effect.lower(): typ = e break if typ is None: available = [e.name for e in TileEffectType] raise PhotonsAppError("Please specify a valid type", wanted=effect, available=available) options["type"] = typ options["res_required"] = False if "palette" not in options: options["palette"] = default_tile_palette if len(options["palette"]) > 16: raise PhotonsAppError("Palette can only be up to 16 colors", got=len(options["palette"])) options["palette"] = list(make_hsbks([c, 1] for c in options["palette"])) options["palette_count"] = len(options["palette"]) set_effect = TileMessages.SetTileEffect.create(**options) async def gen(ref, sender, **kwargs): r = ref if reference is None else reference ps = sender.make_plans("capability") async for serial, _, info in sender.gatherer.gather(ps, r, **kwargs): if info["cap"].has_matrix: if power_on: yield LightMessages.SetLightPower( level=65535, target=serial, duration=power_on_duration, ack_required=True, res_required=False, ) msg = set_effect.clone() msg.target = serial yield msg return FromGenerator(gen)
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)) ]