fix(sensors/darwin): parse sp78 temperatures instead of returning 0.0#2084
Open
drutsan wants to merge 1 commit into
Open
fix(sensors/darwin): parse sp78 temperatures instead of returning 0.0#2084drutsan wants to merge 1 commit into
drutsan wants to merge 1 commit into
Conversation
f1ebcc5 to
13e4809
Compare
The Intel macOS SMC returns temperature readings in sp78 format (signed
7.8 fixed-point: high byte = signed integer degrees, low byte = fractional
part in 1/256 increments). The previous code detected this format
correctly but then unconditionally returned 0.0 for it.
This caused all `TemperaturesWithContext` results on Intel Macs to report
0.0°C for every sensor — even though `NewSMC()` succeeded, the IOKit
connection was open, and the keys were being read successfully.
This patch parses the two-byte response according to the sp78 spec.
Verified on Mac mini 2018 (Intel Core i5-8500B, T2 chip) running macOS
15.7.5 (Sequoia):
Before:
TC0P: 0.0°C
TM0P: 0.0°C
TW0P: 0.0°C
(all 21 keys returned 0.0)
After:
TC0P: 60.3°C (CPU 0 Proximity)
TM0P: 57.6°C (Memory Slots Proximity)
TW0P: 49.6°C (Wireless Module)
(other keys correctly return 0 on this hardware — they are not present
on the T2 platform; values match `osx-cpu-temp` output of 59.7°C)
Affected platforms: all `darwin && !arm64` builds (Intel Macs).
Note that Apple Silicon Macs use a different sensor backend
(sensors_darwin_arm64.go) and are not affected by this bug.
13e4809 to
28add59
Compare
shirou
approved these changes
May 10, 2026
Owner
shirou
left a comment
There was a problem hiding this comment.
LGTM. The sp78 decoding is correct — equivalent to interpreting the two bytes as a signed 16-bit big-endian value and dividing by 256, which matches the canonical reading used by the Linux applesmc driver and other established SMC implementations. I have not checked on a real macOS, but verified the formula handles both positive and negative readings (e.g. 0xFE 0x80 → -1.5°C).
Two minor (non-blocking) suggestions:
- The 5-line comment is heavier than the surrounding style; the historical "Previously this branch incorrectly returned 0.0" sentence will rot — git blame already records that. Trimming to a one-liner referencing the format would be enough.
- Extracting the parser into a tiny pure helper (parseSp78(hi, lo uint8) float64) would make it unit-testable on any platform
Would be great to see both addressed in this PR before merge.
Reference implementations consulted:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
sensors.TemperaturesWithContext()returns 0.0°C for every sensor on Intel Macs becausegetTemperature()insensors_darwin.goexplicitly returns0.0when it detects the sp78 data type — but sp78 is exactly the format Apple's SMC uses for temperature readings.Bug
sensors/sensors_darwin.go:108-110:This branch is supposed to parse the sp78 reading, not discard it. Looks like an unfinished placeholder.
Fix
Parse the two-byte sp78 response according to spec — high byte = signed integer degrees, low byte = fractional part in 1/256 increments:
Verification
Tested on Mac mini 2018 (Intel Core i5-8500B, T2 chip) running macOS 15.7.5 (Sequoia):
Before:
After:
Cross-checked against
osx-cpu-tempwhich reports 59.7°C for the same hardware/load — values match.Other keys (TC0D, TC0H, TG0D, etc.) still legitimately return 0.0 — those sensors aren't physically present on T2-chip Mac mini hardware. The IOKit + SMC stack is fine; only the parsing was broken.
Affected platforms
darwin && !arm64(Intel Macs). Apple Silicon Macs use a different code path (sensors_darwin_arm64.go) and are not affected.Test plan
osx-cpu-tempoutput