Fix battery scaling and fan step, add airflow-percentage register - #6
Open
madsvonqualen wants to merge 1 commit into
Open
Fix battery scaling and fan step, add airflow-percentage register#6madsvonqualen wants to merge 1 commit into
madsvonqualen wants to merge 1 commit into
Conversation
Battery (0x01 04 03 0f) is a plain 0-100 byte, not a 0-255 value: it was rescaled by 100/255, so a full pack read ~39% instead of 100%. Read it directly instead. fan_step (0x01 04 15 61) is the stored manual step (1-10). The 0.3.0 "fan step in percent" change multiplied it by 10 to approximate airflow, but the real airflow percentage is a separate register (0x00 04 17 81). Expose that as fan_speed_percent and return the raw manual step for fan_step, so both values are available and correct. Verified against a live Danfoss Air CCM: battery 100 (raw) vs 39.22 (rescaled); fan_step 5 while airflow reads 54% (5*10=50 != 54, confirming the *10 was an approximation). Adds unit tests for the decoding. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Owner
|
Thanks for the PR. I will however not sit in front of a computer for the next couple of weeks. I will look at it when I am at a computer again. |
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.
Fix battery scaling and fan step, add airflow-percentage register
Three related read-decoding fixes, all verified against a live Danfoss Air CCM
(Danfoss Air A2, HW rev. 18.15, SW rev. 2.48).
1. Battery is a raw 0–100 byte, not a 0–255 value
battery_percent(0x01 04 03 0f) was decoded via_read_percent, i.e.raw * 100 / 255. The register already reports a percentage directly, so a fullbattery pack (raw
100) was reported as ≈39 %. Fixed by reading it as aplain byte.
Confirmed by measuring the Air Dial's 4×AAA pack:
×100/255)2.
fan_stepis the stored manual step (1–10), not step×10The 0.3.0 "fan step in percent" change multiplied the step register
(
0x01 04 15 61) by 10 to approximate airflow. But the step is a 1–10 value,and the real airflow percentage lives in a separate register
(
0x00 04 17 81). On the live unit, step5coincides with an airflow of54 % — and
5 × 10 = 50 ≠ 54, so the ×10 was only an approximation.fan_stepnow returns the raw manual step, and…3. New
fan_speed_percentregister…the actual airflow percentage is exposed as
fan_speed_percent(
0x00 04 17 81, a raw 0–100 byte). Both values are now available and correct,serving both the default use case and the one from #5.
Live verification
read_all()from the patched client against the CCM:Tests
Adds
tests/test_danfossclient.py— 16 cases covering the changed decoding(battery raw, fan_step raw, fan_speed_percent) and guarding the unchanged paths
(humidity/filter still rescaled, temperatures in centidegrees, bypass truthiness,
automatic_bypass inversion). All pass on Python 3.14 / pytest 9.
Compatibility note
battery_percentandfan_stepnow return corrected values, so downstreamconsumers that compensated for the old scaling (e.g. multiplying
fan_stepbackdown, or treating battery as 0–39) should drop those workarounds. Would you be
able to cut a release (e.g.
0.4.0) once merged? The Home Assistant integrationwill then bump to it.