Skip to content

Commit

Permalink
Introduce getThermalInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron Lee committed Jan 8, 2025
1 parent ccbf68a commit 6ccddc0
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,18 @@ Source:
| embeddedDisplay | EmbeddedDisplayInfo | Information about embedded display |
| externalDisplays | Array\<ExternalDisplayInfo\> | 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\<ThermalSensorInfo\> | An array containing all the information retrieved for thermal sensors. |

## Functions
### dpsl.telemetry.*
| Function Name | Definition | Permission needed to access | Released in `dpsl` version |
Expand Down
79 changes: 79 additions & 0 deletions src/__tests__/dpsl.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
});


Expand Down
15 changes: 15 additions & 0 deletions src/telemetry_requester.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,21 @@ class DPSLTelemetryRequester {

return chrome.os.telemetry.getDisplayInfo();
}

/**
* Requests Thermal information.
* @return { !Promise<!dpsl.ThermalInfo> }
* @public
*/
async getThermalInfo() {
const functionName = 'getThermalInfo';
if (!isSupported(functionName)) {
throw new MethodNotFoundError(API_NAME, functionName,
/* chromeVersion */ 127);
}

return chrome.os.telemetry.getThermalInfo();
}
}

module.exports = {
Expand Down
12 changes: 12 additions & 0 deletions src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 //////////////////////

/**
Expand Down

0 comments on commit 6ccddc0

Please sign in to comment.