Scan /sys/class/thermal for CPU/SoC zones (Android). Falls back to any zone if no CPU-named zone is found.
(self)
| 226 | return 0, 0 |
| 227 | |
| 228 | def _read_temp(self) -> Optional[float]: |
| 229 | """ |
| 230 | Scan /sys/class/thermal for CPU/SoC zones (Android). |
| 231 | Falls back to any zone if no CPU-named zone is found. |
| 232 | """ |
| 233 | best: Optional[float] = None |
| 234 | try: |
| 235 | for zone in sorted(Path("/sys/class/thermal").glob("thermal_zone*")): |
| 236 | try: |
| 237 | ztype = (zone / "type").read_text().strip().lower() |
| 238 | raw = int((zone / "temp").read_text().strip()) |
| 239 | temp_c = raw / 1000.0 |
| 240 | # Ignore absurd readings (sensor glitches) |
| 241 | if not (0 < temp_c < 120): |
| 242 | continue |
| 243 | if any(k in ztype for k in ("cpu", "soc", "package", "skin")): |
| 244 | return temp_c |
| 245 | if best is None: |
| 246 | best = temp_c |
| 247 | except Exception: |
| 248 | continue |
| 249 | except Exception: |
| 250 | pass |
| 251 | return best |
| 252 | |
| 253 | def _read_battery(self) -> Tuple[Optional[int], bool]: |
| 254 | """ |