flickerstrip-py/flickerstrip_py/models/memory.py

26 lines
533 B
Python

from dataclasses import dataclass
@dataclass
class Usage:
"""
Represents the memory usage of a flickerstrip.
"""
used: int
free: int
total: int
def to_json(self):
"""
Converts the usage to a JSON object.
"""
return {"used": self.used, "free": self.free, "total": self.total}
@classmethod
def from_json(cls, json):
"""
Creates a usage from a JSON object.
"""
return cls(used=json["used"], free=json["free"], total=json["total"])