Ejemplo n.º 1
0
class Schedule(dictobj.Spec):
    days = dictobj.NullableField(
        sb.listof(enum_spec(None, Days, unpacking=True)))
    hour = dictobj.Field(range_spec(sb.integer_spec(), 0, 23),
                         wrapper=sb.required)
    minute = dictobj.Field(range_spec(sb.integer_spec(), 0, 59),
                           wrapper=sb.required)

    task = dictobj.Field(task_spec)

    hue = dictobj.Field(range_spec(sb.float_spec(), 0, 360), default=0)
    saturation = dictobj.Field(range_spec(sb.float_spec(), 0, 1), default=0)
    brightness = dictobj.Field(range_spec(sb.float_spec(), 0, 1), default=1)
    kelvin = dictobj.Field(range_spec(sb.integer_spec(), 1500, 9000),
                           default=3500)
    transform_options = dictobj.NullableField(
        sb.dictof(sb.string_spec(), sb.boolean()))

    duration = dictobj.NullableField(sb.float_spec)
    power = dictobj.NullableField(power_spec)

    colors = dictobj.NullableField(colors_spec)
    override = dictobj.NullableField(
        sb.dictof(sb.string_spec(), range_spec(sb.float_spec(), 0, 1)))

    reference = dictobj.Field(reference_spec)

    @property
    def hsbk(self):
        if self.task == 'lan:transform':
            keys = ["hue", "saturation", "brightness", "kelvin"]
            options = {k: v for k, v in self.as_dict().items() if k in keys}
            return {k: v for k, v in options.items() if v is not None}
        else:
            return {}

    @property
    def extra(self):
        keys_except = [
            "days", "hour", "minute", "reference", "task", "hue", "saturation",
            "brightness", "kelvin"
        ]
        options = {
            k: v
            for k, v in self.as_dict().items() if k not in keys_except
        }
        return {k: v for k, v in options.items() if v is not None}

    @property
    def dow(self):
        days = self.days
        if not self.days:
            days = list(Days)

        return [day.value for day in days]
Ejemplo n.º 2
0
    def setup_addon_register(self, photons_app, __main__):
        """Setup our addon register"""
        # Create the addon getter and register the crosshair namespace
        self.addon_getter = AddonGetter()
        self.addon_getter.add_namespace("lifx.photons", Result.FieldSpec(), Addon.FieldSpec())

        # Initiate the addons from our configuration
        register = Register(self.addon_getter, self)

        if "addons" in photons_app:
            addons = photons_app["addons"]
            if type(addons) in (MergedOptions, dict) or getattr(addons, "is_dict", False):
                spec = sb.dictof(sb.string_spec(), sb.listof(sb.string_spec()))
                meta = Meta(photons_app, []).at("addons")
                for namespace, adns in spec.normalise(meta, addons).items():
                    register.add_pairs(*[(namespace, adn) for adn in adns])
        elif photons_app.get("default_activate"):
            for comp in photons_app["default_activate"]:
                register.add_pairs(("lifx.photons", comp))

        if __main__ is not None:
            register.add_pairs(("lifx.photons", "__main__"))

        # Import our addons
        register.recursive_import_known()

        # Resolve our addons
        register.recursive_resolve_imported()

        return register
Ejemplo n.º 3
0
 def targets_spec(self):
     """
     Get us a dictionary of target name to Target object
     """
     return sb.dictof(
         self.target_name_spec, Target.FieldSpec(formatter=MergedOptionStringFormatter)
     )
Ejemplo n.º 4
0
class DayDusk(dictobj.Spec):
    schedules = dictobj.Field(
        sb.dictof(sb.string_spec(),
                  Schedule.FieldSpec(formatter=MergedOptionStringFormatter)))
Ejemplo n.º 5
0
    ("Uint32", 32, "<I", int),
    ("Int64", 64, "<q", int),
    ("Uint64", 64, "<Q", int),
    ("Float", 32, "<f", float),
    ("Double", 64, "<d", float),
    ("Bytes", None, None, bytes),
    ("String", None, None, str),
    ("Reserved", None, None, bytes),
    ("CSV", None, None, (list, str, ",")),
    ("JSON", None, None, json),
)

json_spec = sb.match_spec(
    (bool, sb.any_spec()),
    (int, sb.any_spec()),
    (float, sb.any_spec()),
    (str, sb.any_spec()),
    (list, lambda: sb.listof(json_spec)),
    (type(None), sb.any_spec()),
    fallback=lambda: sb.dictof(sb.string_spec(), json_spec),
)

# Here so we don't have to instantiate these every time we get a value from a packet
static_conversion_from_spec = {
    any: sb.any_spec(),
    bool: boolean(),
    float: float_spec(),
    (bool, int): boolean_as_int_spec(),
    json: json_spec,
}
Ejemplo n.º 6
0
        self.assertSignature(sb.optional_spec(sb.any_spec()), "(optional)")

    it "knows about defaulted":
        self.assertSignature(sb.defaulted(sb.integer_spec(), 20), "integer (default 20)")
        self.assertSignature(sb.defaulted(sb.any_spec(), True), "(default True)")

    it "knows about required":
        self.assertSignature(sb.required(sb.integer_spec()), "integer (required)")
        self.assertSignature(sb.required(sb.any_spec()), "(required)")

    it "knows about listof":
        self.assertSignature(sb.listof(sb.integer_spec()), "[ integer , ... ]")
        self.assertSignature(sb.listof(sb.any_spec()), "[ <item> , ... ]")

    it "knows about dictof":
        self.assertSignature(sb.dictof(sb.string_spec(), sb.integer_spec()), "{ string : integer }")
        self.assertSignature(sb.dictof(sb.string_spec(), sb.any_spec()), "{ string : <item> }")

    it "knows about container_spec":

        class Container:
            def __init__(self, value):
                pass

        self.assertSignature(sb.container_spec(Container, sb.string_spec()), "string")

    it "knows about formatted":
        self.assertSignature(sb.formatted(sb.string_spec(), formatter=None), "string")

    it "knows about or_spec":
        self.assertSignature(
Ejemplo n.º 7
0
    def setup(self, spec):
        self.spec = spec

    def normalise_empty(self, meta):
        raise BadSpecValue("Preset must have a non empty list of animations",
                           meta=meta)

    def normalise_filled(self, meta, val):
        val = sb.listof(self.spec).normalise(meta, val)
        if not val:
            raise BadSpecValue(
                "Preset must have a non empty list of animations", meta=meta)
        return val


presets_spec = lambda: sb.dictof(
    sb.string_spec(), non_empty_list_spec(PresetAnimation.FieldSpec()))


class TileTransitionAnimation(Animation):
    def setup(self):
        self.color = Color(random.randrange(0, 360), 1, 1, 3500)

    def next_state(self, prev_state, coords):
        if prev_state is None:
            filled = {}
            remaining = {}

            for (left, top), (width, height) in coords:
                for i in range(left, left + width):
                    for j in range(top, top - height, -1):
                        remaining[(i, j)] = True
Ejemplo n.º 8
0
 def setup(self):
     self.spec = sb.dictof(
         service_type_spec(),
         sb.set_options(host=sb.required(sb.string_spec()),
                        port=sb.required(sb.integer_spec())),
     )
Ejemplo n.º 9
0
 def setup(self, see_env=True):
     self.spec = sb.dictof(serial_spec(), service_info_spec())
     self.see_env = see_env