From 58cef5c04678a82f3b5f56b7b8733aacd756e6c6 Mon Sep 17 00:00:00 2001
From: Sebastian Hildebrandt
Date: Thu, 14 Jul 2022 08:33:08 +0200
Subject: [PATCH] cpuTemperature() apple silicon support
---
CHANGELOG.md | 2 +-
README.md | 2 +-
docs/changes.html | 2 +-
docs/cpu.html | 2 +-
docs/issues.html | 2 +-
lib/cpu.js | 12 ++++++++++++
6 files changed, 17 insertions(+), 5 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 43e2e50..5a80a47 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -66,7 +66,7 @@ We had to make **several interface changes** to keep systeminformation as consis
- `uuid()`: better value support
- `uuid()`: added MACs
- `uuid()`: better Raspberry Pi hardware ID
-- `Apple M1 Silicon extended support (now everything supported except of cpu temperature)
+- `Apple M1 Silicon extended support
- `updated TypeScript definitions
#### Test Full Version 5 Functionality
diff --git a/README.md b/README.md
index 57082aa..241f4f2 100644
--- a/README.md
+++ b/README.md
@@ -904,7 +904,7 @@ To be able to measure temperature on macOS I created a little additional package
in NPM with `optionalDependencies` I unfortunately was getting unexpected warnings on other platforms.
So I decided to drop this optional dependency for macOS - so by default, you will not get correct values.
-This additional package will unfortunately NOT work on Apple Silicon M1 machines.
+This additional package is now also supporting Apple Silicon M1 machines.
But if you need to detect macOS temperature just run the following additional
installation command:
diff --git a/docs/changes.html b/docs/changes.html
index 52e2aa0..c7a31e8 100644
--- a/docs/changes.html
+++ b/docs/changes.html
@@ -192,7 +192,7 @@
uuid(): added MACs
uuid(): better Raspberry Pi hardware ID
versions(): added bash, zsh, fish, powershell, dotnet
- Apple M1 Silicon extended support (now everything supported except of cpu temperature)
+ Apple M1 Silicon extended support
updated TypeScript definitions
Test Full Version 5 Functionality
diff --git a/docs/cpu.html b/docs/cpu.html
index c029a1d..6d81cdd 100644
--- a/docs/cpu.html
+++ b/docs/cpu.html
@@ -594,7 +594,7 @@ si.cpuTemperature().then(data => console.log(data));
- This additional package will unfortunately not work on Apple Silicon M1 machines.
+ This additional package is now also suppprting Apple Silicon M1 machines.
But if you need to detect macOS temperature just run the following additional installation command:
diff --git a/docs/issues.html b/docs/issues.html
index 4fe1e62..4ce36c0 100644
--- a/docs/issues.html
+++ b/docs/issues.html
@@ -50,7 +50,7 @@
I unfortunately was getting unexpected warnings on other platforms. So I decided to drop this optional dependency for macOS - so by default,
you will not get correct values.
- This additional package will unfortunately not work on Apple Silicon M1 machines.
+ This additional package is now also supporting Apple Silicon M1 machines.
But if you need to detect macOS temperature just run the following additional installation command:
diff --git a/lib/cpu.js b/lib/cpu.js
index ee02b29..a87ee3e 100644
--- a/lib/cpu.js
+++ b/lib/cpu.js
@@ -1204,6 +1204,18 @@ function cpuTemperature(callback) {
}
if (osxTemp) {
result = osxTemp.cpuTemperature();
+ // round to 2 digits
+ if (result.main) {
+ result.main = Math.round(result.main * 100) / 100;
+ }
+ if (result.max) {
+ result.max = Math.round(result.max * 100) / 100;
+ }
+ if (result.cores && result.cores.length) {
+ for (let i = 0; i < result.cores.length; i++) {
+ result.cores[i] = Math.round(result.cores[i] * 100) / 100;
+ }
+ }
}
if (callback) { callback(result); }