1717EC_CMD_THERMAL_SET_THRESHOLD : Final = 0x0050
1818EC_CMD_THERMAL_GET_THRESHOLD : Final = 0x0051
1919
20+
21+ class EcTempThresholds (Enum ):
22+ EC_TEMP_THRESH_WARN = 0
23+ EC_TEMP_THRESH_HIGH = auto ()
24+ EC_TEMP_THRESH_HALT = auto ()
25+
26+ EC_TEMP_THRESH_COUNT = auto ()
27+
28+
29+ def thermal_get_thresholds (
30+ ec : CrosEcClass , sensor_num : int , adjust : int | float = - 273
31+ ) -> dict [str , list [int | float ] | int | float ]:
32+ """
33+ Get the temperature thresholds for a given sensor.
34+ :param ec: The CrOS_EC object.
35+ :param sensor_num: The sensor number.
36+ :param adjust: The adjustment to apply to the temperature. Default is -273 to convert from Kelvin to Celsius.
37+ :return: A list of tuples containing the (warn, high, halt) thresholds.
38+ """
39+ data = struct .pack ("<B" , sensor_num )
40+ thresh_count : Final = EcTempThresholds .EC_TEMP_THRESH_COUNT .value
41+ resp = ec .command (1 , EC_CMD_THERMAL_GET_THRESHOLD , 1 , 4 * thresh_count + 4 * thresh_count + 4 + 4 , data )
42+ config = struct .unpack (f"<{ thresh_count } I{ thresh_count } III" , resp )
43+ return {
44+ "temp_host" : [(i + adjust ) for i in config [0 :thresh_count ]],
45+ "temp_host_release" : [
46+ (i + adjust ) for i in config [thresh_count : thresh_count * 2 ]
47+ ],
48+ "temp_fan_off" : config [thresh_count * 2 ] + adjust ,
49+ "temp_fan_max" : config [thresh_count * 2 + 1 ] + adjust ,
50+ }
51+
52+
2053EC_CMD_THERMAL_AUTO_FAN_CTRL : Final = 0x0052
2154
2255
@@ -75,4 +108,3 @@ def get_temp_sensors(ec: CrosEcClass) -> dict[str, tuple[int, EcTempSensorType]]
75108 info = temp_sensor_get_info (ec , i )
76109 ret [info ["name" ]] = (j , info ["type" ])
77110 return ret
78-
0 commit comments