flickerstrip-py/flickerstrip_py/models/pattern.py

53 lines
985 B
Python

from dataclasses import dataclass
from typing import Any
@dataclass
class Pattern:
"""
Represents a pattern.
"""
id: int
name: str
frames: int
pixels: int
flags: int
fps: int
def to_json(self) -> Any:
"""
Converts the pattern to a JSON object.
"""
return {
"id": self.id,
"name": self.name,
"frames": self.frames,
"pixels": self.pixels,
"flags": self.flags,
"fps": self.fps,
}
@classmethod
def from_json(cls, json: Any) -> "Pattern":
"""
Creates a pattern from a json object.
"""
return cls(
id=json["id"],
name=json["name"],
frames=json["frames"],
pixels=json["pixels"],
flags=json["flags"],
fps=json["fps"],
)
@dataclass
class PatternData:
"""
Represents a pattern data.
"""
data: bytes