How to use the wled.models.State function in wled

To help you get started, we’ve selected a few wled examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github frenck / python-wled / wled / models.py View on Github external
brightness = data.get("bri", 1)
        on = data.get("on", False)

        segments = [
            Segment.from_dict(
                segment_id=segment_id,
                data=segment,
                effects=effects,
                palettes=palettes,
                state_on=on,
                state_brightness=brightness,
            )
            for segment_id, segment in enumerate(data.get("seg", []))
        ]

        return State(
            brightness=brightness,
            nightlight=Nightlight.from_dict(data),
            on=on,
            playlist=data.get("pl", -1),
            preset=data.get("ps", -1),
            segments=segments,
            sync=Sync.from_dict(data),
            transition=data.get("transition", 0),
        )
github frenck / python-wled / wled / models.py View on Github external
on=on,
            playlist=data.get("pl", -1),
            preset=data.get("ps", -1),
            segments=segments,
            sync=Sync.from_dict(data),
            transition=data.get("transition", 0),
        )


class Device:
    """Object holding all information of WLED."""

    effects: List[Effect] = []
    info: Info
    palettes: List[Palette] = []
    state: State

    def __init__(self, data: dict):
        """Initialize an empty WLED device class."""
        # Check if all elements are in the passed dict, else raise an Error
        if any(
            k not in data and data[k] is not None
            for k in ["effects", "palettes", "info", "state"]
        ):
            raise WLEDError("WLED data is incomplete, cannot construct device object")
        self.update_from_dict(data)

    def update_from_dict(self, data: dict) -> "Device":
        """Return Device object from WLED API response."""
        if "effects" in data and data["effects"]:
            effects = [
                Effect(effect_id=effect_id, name=effect)