fix(common): 🐛 keep decimals in luxtronik2.write values - #813
Merged
Merged
Conversation
- the service ran every value through int(), so -1.5 on the 0.5 K heating curve offset reached the pump as -1 with no error, and the post-write confirmation compared the truncated value with itself and passed - numeric strings (the service's text selector in UI mode) were written correctly but then failed confirmation against the numeric read-back - rename convert_to_int_if_possible to normalize_write_value: integral numbers become int (identity datatypes need it, Luxtronik.write() skips non-ints), fractional numbers stay float for the scaled datatypes to convert, bools, selection names and nan/inf pass through unchanged - Energy2.to_heatpump rounds instead of truncating (0.29 * 100 wrote 28) Resolves #811 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
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.
🔍 What this fixes
Resolves #811, reported and diagnosed by @webmaster-lars.
luxtronik2.writeran every value throughint()before queuing it:-1.5forID_Einst_WK_akt(heating curve offset, 0.5 K steps) reached the pump as-1, with no error and no log entry. The post-write confirmation compared the truncated value with the read-back, both-1, so it passed.valueuses atext:selector."22.5"was written correctly, since the Celsius datatype parses it, but the confirmation then compared the string"22.5"against the numeric read-back22.5and raised "did not confirm".As a result, no decimal value could be written through the service without either silent truncation or an error.
✨ Changes
common.py:convert_to_int_if_possibleis renamed tonormalize_write_value. Every value still ends up as aninton the wire. The rule is:int. Identity datatypes (Unknown,Seconds, …) queue the value unchanged, andLuxtronik.write()skips anything that isn't an int, which is why the originalint()was added in 3c052b5.float, so scaled datatypes (Celsius×10, …) convert them to the raw int themselves."Automatic"),"HH:MM"andnan/infpass through unchanged.lux_overrides.py:Energy2.to_heatpumpnow usesround(value * 100)instead ofint(value * 100).0.29 * 100is28.999…in binary floating point, so 0.29 was written as 28. The same kind of truncation, found while checking this one.A fractional value sent to an identity-datatype parameter (e.g.
1.5to anUnknownregister) is no longer half-applied as1. The library skips it and the confirmation raises an error. There's no scale that could turn it into a valid raw value, so an error is the correct result.🧪 Tests
test_common.py: fractional float, whole-number float and string, numeric string, int, bool and non-finite cases. The old test asserting that"3.14"stays a string encoded the bug and is replaced.test_init.py: a service-level test runs-1.5and"-1.5"through the realSERVICE_WRITE_SCHEMAand asserts thatasync_writereceives-1.5. The redundant pure-function test there is removed.test_lux_overrides.py:Energy2rounding for three values that used to truncate.Full run: 1382 passed, 1 skipped, coverage 100% (unchanged).
ruff check,ruff format --check,basedpyright(0 errors) andcodespellare clean.🤖 Generated with Claude Code