(self)
| 22 | max_energy_reading: Energy = field(default_factory=lambda: Energy(0)) |
| 23 | |
| 24 | def __post_init__(self): |
| 25 | self.last_energy = self._get_value() |
| 26 | try: |
| 27 | with open(self.max_path, "r") as f: |
| 28 | max_micro_joules = float(f.read()) |
| 29 | self.max_energy_reading = Energy.from_ujoules(max_micro_joules) |
| 30 | except Exception as e: |
| 31 | # If we cannot read the max range, log and set to 0 so wrap detection |
| 32 | # will be effectively disabled for this file. |
| 33 | if isinstance(e, PermissionError): |
| 34 | logger.warning( |
| 35 | "Unable to read max_energy_range_uj from %s due to permission error: %s", |
| 36 | self.max_path, |
| 37 | e, |
| 38 | ) |
| 39 | else: |
| 40 | logger.debug( |
| 41 | "Unable to read max_energy_range_uj from %s: %s", |
| 42 | self.max_path, |
| 43 | e, |
| 44 | ) |
| 45 | self.max_energy_reading = Energy.from_ujoules(0) |
| 46 | |
| 47 | def _get_value(self) -> Energy: |
| 48 | """ |
nothing calls this directly
no test coverage detected