Skip to content

Commit 8a918cf

Browse files
authored
Merge pull request #61 from GoogleChromeLabs/byron/thermal
Introduce getThermalInfo
2 parents bee5dc2 + 4564f16 commit 8a918cf

File tree

4 files changed

+119
-0
lines changed

4 files changed

+119
-0
lines changed

src/README.md

+13
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,18 @@ Source:
461461
| length_seconds | number | Length of time to run the routine for. |
462462
| file_size_mb | number | Test file size, in mega bytes, to test with DiskRead routine. Maximum file size is 10 GB. |
463463

464+
### ThermalSensorInfo
465+
| Property Name | Type | Description |
466+
| ------------------ | ------ | ----------------------------------------------------------------------- |
467+
| name | string | Name of the thermal sensor. |
468+
| temperatureCelsius | number | Temperature detected by the thermal sensor in celsius. |
469+
| source | string | Where the thermal sensor is detected from. ("ec", "sysFs" or "unknown") |
470+
471+
### ThermalInfo
472+
| Property Name | Type | Description |
473+
| -------------- | -------------------------- | ---------------------------------------------------------------------- |
474+
| thermalSensors | Array\<ThermalSensorInfo\> | An array containing all the information retrieved for thermal sensors. |
475+
464476
## Functions
465477
### dpsl.telemetry.*
466478
| Function Name | Definition | Permission needed to access | Released in `dpsl` version |
@@ -479,6 +491,7 @@ Source:
479491
| getMarketingInfo | () => Promise\<MarketingInfo\> | `os.telemetry` | 1.3.4 |
480492
| getUsbBusInfo | () => Promise\<UsbDevicesInfo\> | `os.telemetry`, `os.attached_device_info` | 1.3.5 |
481493
| getDisplayInfo | () => Promise\<DisplayInfo\> | `os.telemetry` | 1.3.6 |
494+
| getThermalInfo | () => Promise\<ThermalInfo\> | `os.telemetry` | 1.4.1 |
482495

483496
### dpsl.diagnostics.*
484497
| Function Name | Definition | Permission needed to access | Released in `dpsl` version |

src/__tests__/dpsl.test.js

+79
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,85 @@ describe('dpsl.telemetry tests', () => {
476476
done();
477477
});
478478
});
479+
480+
test('dpsl.telemetry.getThermalInfo() returns correct data',
481+
(done) => {
482+
// Mock the global chrome object.
483+
const expectedThermalInfo = {
484+
'thermalSensors': [
485+
{
486+
'name': 'TSR0',
487+
'source': 'sysFs',
488+
'temperatureCelsius': 39.8,
489+
},
490+
{
491+
'name': 'x86_pkg_temp',
492+
'source': 'sysFs',
493+
'temperatureCelsius': 51,
494+
},
495+
{
496+
'name': 'TSR3',
497+
'source': 'sysFs',
498+
'temperatureCelsius': 35.8,
499+
},
500+
{
501+
'name': 'TSR1',
502+
'source': 'sysFs',
503+
'temperatureCelsius': 36.8,
504+
},
505+
{
506+
'name': 'INT3400 Thermal',
507+
'source': 'sysFs',
508+
'temperatureCelsius': 20,
509+
},
510+
{
511+
'name': 'TCPU',
512+
'source': 'sysFs',
513+
'temperatureCelsius': 52,
514+
},
515+
{
516+
'name': 'TSR2',
517+
'source': 'sysFs',
518+
'temperatureCelsius': 39.8,
519+
},
520+
{
521+
'name': 'Charger',
522+
'source': 'ec',
523+
'temperatureCelsius': 39.85000000000002,
524+
},
525+
{
526+
'name': 'PP3300 Regulator',
527+
'source': 'ec',
528+
'temperatureCelsius': 36.85000000000002,
529+
},
530+
{
531+
'name': 'DDR and SOC',
532+
'source': 'ec',
533+
'temperatureCelsius': 39.85000000000002,
534+
},
535+
{
536+
'name': 'Fan',
537+
'source': 'ec',
538+
'temperatureCelsius': 35.85000000000002,
539+
},
540+
],
541+
};
542+
const chrome = {
543+
os: {
544+
telemetry: {
545+
getThermalInfo: () => expectedThermalInfo,
546+
},
547+
},
548+
};
549+
global.chrome = chrome;
550+
551+
dpsl.telemetry.getThermalInfo()
552+
.then((thermalInfo) => {
553+
expect(thermalInfo)
554+
.toEqual(expectedThermalInfo);
555+
done();
556+
});
557+
});
479558
});
480559

481560

src/telemetry_requester.js

+15
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,21 @@ class DPSLTelemetryRequester {
240240

241241
return chrome.os.telemetry.getDisplayInfo();
242242
}
243+
244+
/**
245+
* Requests Thermal information.
246+
* @return { !Promise<!dpsl.ThermalInfo> }
247+
* @public
248+
*/
249+
async getThermalInfo() {
250+
const functionName = 'getThermalInfo';
251+
if (!isSupported(functionName)) {
252+
throw new MethodNotFoundError(API_NAME, functionName,
253+
/* chromeVersion */ 127);
254+
}
255+
256+
return chrome.os.telemetry.getThermalInfo();
257+
}
243258
}
244259

245260
module.exports = {

src/types.js

+12
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,18 @@ dpsl.UsbBusInfo;
316316
*/
317317
dpsl.DisplayInfo;
318318

319+
/**
320+
* Response message containing Thermal Info
321+
* @typedef {{
322+
* thermalSensors: Array<{
323+
* name: string,
324+
* temperatureCelsius: number,
325+
* source: string,
326+
* }>,
327+
* }}
328+
*/
329+
dpsl.ThermalInfo;
330+
319331
///////////////////// dpsl.diagnostics.* type definitions //////////////////////
320332

321333
/**

0 commit comments

Comments
 (0)