tyres: use HA's unit metadata instead of assuming kPa (#39) - #63
Open
ThinkOffApp wants to merge 1 commit into
Open
ThinkOffApp wants to merge 1 commit into
ThinkOffApp wants to merge 1 commit into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
To use Codex here, create an environment for this repo. |
@eclass told petrus his tyres were at "thirty bar" on 11 Sep. Thirty bar is ten times a car tyre, and it had been saying so for a week. The fetch already asks Home Assistant for every entity's attributes, which carry unit_of_measurement, and then dropped it: _norm_value only ever received the state string. Whatever HA reported - psi, bar, kPa - was filed under the hardcoded key "tires_kpa". The prompt then handed the model a bare number and a unit word and left it to convert, which is where a decade can go missing. - _pressure_kpa() converts from bar/psi/kPa/mbar/hPa explicitly, and returns None on an unknown or missing unit rather than assuming kPa. An unlabelled pressure is not a kPa reading. - the fetch passes attributes.unit_of_measurement through for tyre entities. - fmt_tyres_bar() renders bar to one decimal, so the model never converts at all, and flags a physically implausible reading (outside 1.0-4.5 bar) as a sensor fault instead of stating it as the pressure. - webchat was interpolating the raw dict into the prompt ("tyres {'front_left': 250, ...} kPa"); it now uses the same formatter as the agent. Tests cover each unit, the refusal on an unknown unit, 30 psi no longer becoming thirty-anything, wheel ordering, and the implausibility flag. Not yet confirmed against the live car: the Mini's snapshot is 59h stale and the local one is empty, so which unit this particular HA reports is still unverified. The fix removes the assumption either way. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
ThinkOffApp
force-pushed
the
fix/tyre-pressure-units
branch
from
September 18, 2026 16:56
70fc6bb to
fb34a6a
Compare
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.
Fixes #39 — @eclass reported "tyres holding steady at thirty bar" on 11 Sep. Thirty bar is ten times a car tyre, and it had been saying so for a week.
The trace, raw value to spoken value
@codexmb asked for this before any conversion was chosen, and it changes what the fix is:
GET /api/statesreturns each entity withstateandattributes.unit_of_measurement.mercedesme.pyreadsattrs(it already did, line 327) but passed only the state string to_norm_value.tires_kpawhatever unit HA actually reported.agent.pyemitted"tyre pressures kPa <n>"— a bare number plus a unit word.So the bug is not a missing conversion. The unit was fetched and thrown away.
What changed
_pressure_kpa()converts from bar / psi / kPa / mbar / hPa explicitly, and returnsNoneon an unknown or missing unit rather than assuming kPa. An unlabelled pressure is not a kPa reading.attributes.unit_of_measurementthrough for tyre entities.fmt_tyres_bar()renders bar to one decimal, as the issue asks, so the model never converts at all.webchat.pywas interpolating the raw dict into the prompt (tyres {'front_left': 250, ...} kPa); it now uses the same formatter.Tests
tests/test_tyre_units.py, 7 cases: every unit HA might report, the refusal on an unknown unit, 30 psi no longer becoming thirty-anything, bar-with-one-decimal output, wheel ordering, the implausibility flag, and non-pressure entities untouched.Run in isolation and with the suite.
tests.test_dash_loopfails onmainas well — pre-existing, unrelated to this change.Not verified
Which unit this particular car's HA reports is still unconfirmed — the Mini's snapshot is 59 h stale and the local one is empty. "30 meant psi" remains a hypothesis. The fix removes the assumption either way, and the implausibility flag catches the symptom regardless of cause. Worth confirming against the live car when it is next reachable.
🤖 Generated with Claude Code