Skip to content

Commit 55ff463

Browse files
committed
Add thermal_get_thresholds
1 parent d323332 commit 55ff463

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

cros_ec_python/commands/thermal.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,39 @@
1717
EC_CMD_THERMAL_SET_THRESHOLD: Final = 0x0050
1818
EC_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+
2053
EC_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-

tests/thermal.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33

44
ec = get_cros_ec()
55

6+
class TestGetThresholds(unittest.TestCase):
7+
def test(self):
8+
resp = ec_thermal.thermal_get_thresholds(ec, 0)
9+
print(type(self).__name__, "-", "Resp:", resp)
10+
self.assertIsInstance(resp, dict)
611

712
class TestAutoFanControl(unittest.TestCase):
813
def test_version0(self):

0 commit comments

Comments
 (0)