Coverage for src / zooc / data / offset_temp.py: 90%

29 statements  

« prev     ^ index     » next       coverage.py v7.13.0, created at 2025-12-11 21:45 +0000

1"""Z-offset temperature data.""" 

2from __future__ import annotations 

3 

4from dataclasses import dataclass, field 

5from typing import override 

6 

7from klipper_utils.klipper_utils import KlipperConfigDict 

8 

9from .temps import Temps 

10 

11 

12@dataclass(kw_only=True, frozen=True) 

13class OffsetTemp(KlipperConfigDict): 

14 """Single Z-offset measure at bed and extruder temperatures with optional auxiliary data. 

15 

16 :param bed_temp: Bed temperature [°C]. 

17 :param extruder_temp: Extruder temperature [°C]. 

18 :param z_offset: Z-offset value at given temperatures [mm]. 

19 :param aux_data: Optional auxiliary data for the measurement. This is not saved in the config file. 

20 """ 

21 

22 @staticmethod 

23 def build(temps: Temps, z_offset: float, aux_data: dict[str, object] | None = None) -> OffsetTemp: 

24 """Create OffsetTemp from temperatures and z-offset. 

25 

26 :param temps: Bed and extruder temperatures. 

27 :param z_offset: Z-offset value [mm]. 

28 :param aux_data: Optional auxiliary data for the measurement. This is not saved in the config file. 

29 :return: OffsetTemp created with temperatures and z-offset. 

30 """ 

31 if aux_data is None: 31 ↛ 32line 31 didn't jump to line 32 because the condition on line 31 was never true

32 aux_data = {} 

33 return OffsetTemp(bed_temp=temps.bed_temp, extruder_temp=temps.extruder_temp, z_offset=z_offset, aux_data=aux_data) 

34 

35 bed_temp: float 

36 extruder_temp: float 

37 z_offset: float 

38 aux_data: dict[str, object] = field(default_factory=dict) 

39 

40 def __post_init__(self) -> None: 

41 """Consolidate the variable data.""" 

42 object.__setattr__(self, 'bed_temp', float(self.bed_temp)) 

43 object.__setattr__(self, 'extruder_temp', float(self.extruder_temp)) 

44 object.__setattr__(self, 'z_offset', float(self.z_offset)) 

45 

46 @property 

47 def temps(self) -> Temps: 

48 """Get the temperatures as a Temps object. 

49 

50 :return: Bed and extruder temperatures. 

51 """ 

52 return Temps.klipper(bed=self.bed_temp, extruder=self.extruder_temp) 

53 

54 @staticmethod 

55 @override 

56 def get_title() -> list[str]: 

57 return ["bed_temp", "extruder_temp", "z_offset"] 

58 

59 def __str__(self) -> str: 

60 """Get a string representation of the temperatures and offset. 

61 

62 :return: String of bed and extruder temperatures and z-offset. 

63 """ 

64 return f"bed={self.bed_temp}C extruder={self.extruder_temp}C Z-offset={self.z_offset:.3f}"