Skip to content

Commit cbbcaad

Browse files
authored
Add support for Filesystem information (#462)
1 parent 8217f14 commit cbbcaad

1 file changed

Lines changed: 42 additions & 1 deletion

File tree

src/wled/models.py

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,14 +256,54 @@ def from_dict(data: dict[str, Any]) -> Wifi | None:
256256

257257

258258
@dataclass
259-
class Info:
259+
class Filesystem:
260+
"""Object holding Filesystem information from WLED.
261+
262+
Args:
263+
data: The data from the WLED device API.
264+
265+
Returns:
266+
A Filesystem object.
267+
"""
268+
269+
total: int
270+
used: int
271+
free: int
272+
percentage: int
273+
274+
@staticmethod
275+
def from_dict(data: dict[str, Any]) -> Filesystem | None:
276+
"""Return Filesystem object form WLED API response.
277+
278+
Args:
279+
data: The response from the WLED API.
280+
281+
Returns:
282+
An Filesystem object.
283+
"""
284+
if "fs" not in data:
285+
return None
286+
filesystem = data.get("fs", {})
287+
total = filesystem.get("t", 1)
288+
used = filesystem.get("u", 1)
289+
return Filesystem(
290+
total=total,
291+
used=used,
292+
free=(total - used),
293+
percentage=round((used / total) * 100),
294+
)
295+
296+
297+
@dataclass
298+
class Info: # pylint: disable=too-many-instance-attributes
260299
"""Object holding information from WLED."""
261300

262301
architecture: str
263302
arduino_core_version: str
264303
brand: str
265304
build_type: str
266305
effect_count: int
306+
filesystem: Filesystem | None
267307
free_heap: int
268308
leds: Leds
269309
live_ip: str
@@ -299,6 +339,7 @@ def from_dict(data: dict[str, Any]) -> Info:
299339
brand=data.get("brand", "WLED"),
300340
build_type=data.get("btype", "Unknown"),
301341
effect_count=data.get("fxcount", 0),
342+
filesystem=Filesystem.from_dict(data),
302343
free_heap=data.get("freeheap", 0),
303344
leds=Leds.from_dict(data),
304345
live_ip=data.get("lip", "Unknown"),

0 commit comments

Comments
 (0)