From 6ccddc099f2d3c5599c27ff3e979ff7f9e59f8b5 Mon Sep 17 00:00:00 2001 From: Byron Lee Date: Wed, 8 Jan 2025 10:53:41 +0000 Subject: [PATCH] Introduce getThermalInfo --- src/README.md | 12 ++++++ src/__tests__/dpsl.test.js | 79 ++++++++++++++++++++++++++++++++++++++ src/telemetry_requester.js | 15 ++++++++ src/types.js | 12 ++++++ 4 files changed, 118 insertions(+) diff --git a/src/README.md b/src/README.md index 1f7410c..5cb49ca 100644 --- a/src/README.md +++ b/src/README.md @@ -454,6 +454,18 @@ Source: | embeddedDisplay | EmbeddedDisplayInfo | Information about embedded display | | externalDisplays | Array\ | Information about external displays | +### ThermalSensorInfo +| Property Name | Type | Description | +| ------------------ | ------ | ----------------------------------------------------------------------- | +| name | string | Name of the thermal sensor. | +| temperatureCelsius | number | Temperature detected by the thermal sensor in celsius. | +| source | string | Where the thermal sensor is detected from. ("ec", "sysFs" or "unknown") | + +### ThermalInfo +| Property Name | Type | Description | +| -------------- | -------------------------- | ---------------------------------------------------------------------- | +| thermalSensors | Array\ | An array containing all the information retrieved for thermal sensors. | + ## Functions ### dpsl.telemetry.* | Function Name | Definition | Permission needed to access | Released in `dpsl` version | diff --git a/src/__tests__/dpsl.test.js b/src/__tests__/dpsl.test.js index 0a03735..43a6756 100644 --- a/src/__tests__/dpsl.test.js +++ b/src/__tests__/dpsl.test.js @@ -476,6 +476,85 @@ describe('dpsl.telemetry tests', () => { done(); }); }); + + test('dpsl.telemetry.getThermalInfo() returns correct data', + (done) => { + // Mock the global chrome object. + const expectedThermalInfo = { + 'thermalSensors': [ + { + 'name': 'TSR0', + 'source': 'sysFs', + 'temperatureCelsius': 39.8, + }, + { + 'name': 'x86_pkg_temp', + 'source': 'sysFs', + 'temperatureCelsius': 51, + }, + { + 'name': 'TSR3', + 'source': 'sysFs', + 'temperatureCelsius': 35.8, + }, + { + 'name': 'TSR1', + 'source': 'sysFs', + 'temperatureCelsius': 36.8, + }, + { + 'name': 'INT3400 Thermal', + 'source': 'sysFs', + 'temperatureCelsius': 20, + }, + { + 'name': 'TCPU', + 'source': 'sysFs', + 'temperatureCelsius': 52, + }, + { + 'name': 'TSR2', + 'source': 'sysFs', + 'temperatureCelsius': 39.8, + }, + { + 'name': 'Charger', + 'source': 'ec', + 'temperatureCelsius': 39.85000000000002, + }, + { + 'name': 'PP3300 Regulator', + 'source': 'ec', + 'temperatureCelsius': 36.85000000000002, + }, + { + 'name': 'DDR and SOC', + 'source': 'ec', + 'temperatureCelsius': 39.85000000000002, + }, + { + 'name': 'Fan', + 'source': 'ec', + 'temperatureCelsius': 35.85000000000002, + }, + ], + }; + const chrome = { + os: { + telemetry: { + getThermalInfo: () => expectedThermalInfo, + }, + }, + }; + global.chrome = chrome; + + dpsl.telemetry.getThermalInfo() + .then((thermalInfo) => { + expect(thermalInfo) + .toEqual(expectedThermalInfo); + done(); + }); + }); }); diff --git a/src/telemetry_requester.js b/src/telemetry_requester.js index b6c6902..b7c1036 100644 --- a/src/telemetry_requester.js +++ b/src/telemetry_requester.js @@ -240,6 +240,21 @@ class DPSLTelemetryRequester { return chrome.os.telemetry.getDisplayInfo(); } + + /** + * Requests Thermal information. + * @return { !Promise } + * @public + */ + async getThermalInfo() { + const functionName = 'getThermalInfo'; + if (!isSupported(functionName)) { + throw new MethodNotFoundError(API_NAME, functionName, + /* chromeVersion */ 127); + } + + return chrome.os.telemetry.getThermalInfo(); + } } module.exports = { diff --git a/src/types.js b/src/types.js index 58dd816..497fd54 100644 --- a/src/types.js +++ b/src/types.js @@ -316,6 +316,18 @@ dpsl.UsbBusInfo; */ dpsl.DisplayInfo; +/** + * Response message containing Thermal Info + * @typedef {{ + * thermalSensors: Array<{ + * name: string, + * temperatureCelsius: number, + * source: string, + * }>, + * }} + */ +dpsl.ThermalInfo; + ///////////////////// dpsl.diagnostics.* type definitions ////////////////////// /**