"""Sensor readings shared by the LCD, lighting, cooling and the web UI.""" from __future__ import annotations from dataclasses import dataclass, field @dataclass class Readings: temp: float | None = None # deg C load: float | None = None # percent clock: float | None = None # MHz power: float | None = None # W @dataclass class PowerReadings: cpu: float | None = None # W, CPU package (measured) gpu: float | None = None # W, graphics card board power (measured) other: float | None = None # W, rest of the PC (partly measured, partly estimated) parts: dict[str, float] = field(default_factory=dict) # what makes up `other` @property def total(self) -> float | None: """The known parts summed; None only when nothing is known. While a part is missing the total under-counts -- `complete` says so.""" known = [v for v in (self.cpu, self.gpu, self.other) if v is not None] return sum(known) if known else None @property def complete(self) -> bool: return self.cpu is not None and self.gpu is not None and self.other is not None