Skip to content

Keep unit pickers and sibling platform refinements out of the catalog sync - #3013

Merged
J. Nick Koston (bdraco) merged 4 commits into
mainfrom
fix-sync-temperature-unit-bleed
Nov 5, 2026
Merged

J. Nick Koston (bdraco) merged 4 commits into
mainfrom
fix-sync-temperature-unit-bleed

Conversation

@bdraco

@bdraco J. Nick Koston (bdraco) commented Nov 5, 2026 •

Copy link
Copy Markdown
Member

What does this implement/fix?

Stop the catalog sync typing template unit_of_measurement as a temperature (°C/°F/K only), which the 2026.11.0b1 sync (#3010) shipped for sensor.template and number.template, and restore the base sensor fields 2026.11's nested sensor schemas lost, by fixing three sync bugs 2026.11 exposed.

# before: any validator whose name contains a table key gets that key's type
for k, t in by_name.items():
    if k in name:  # cv.temperature_unit matched "temperature"
        return t

# after: the longest name match wins, and a validator that accepts a bare unit is a picker
key = max((k for k in by_name if k in lowered), key=len, default=None)
validator(refined.unit_options[0])  # cv.temperature_unit accepts "°C" -> not refined
  • Effect: cv.temperature_unit (new in 2026.11, a unit picker) stays unrefined; a platform build sheds a sibling platform's refinement or range on a key its own schema types differently (previously only hub signals were shed); nested extends merge per field, so 2026.11 sensors built from mid-level schemas (ina3221's VOLTAGE_SCHEMA and about 200 others) keep their device_class / state_class options and integer accuracy_decimals.
  • Scope: script/sync_components.py only; no catalog in this PR. Re-run the 2026.11.0b1 sync after merge to refresh Sync component catalog from schema 2026.11.0b1 #3010.
  • Related: esphome schema-bundle gaps from the same audit (gree switch, tmp102, drayton) are fixed upstream separately.
Catalog diff vs #3010 (full 2026.11.0b1 sync run locally on this branch)
Entry #3010 This branch Why
sensor.template, number.template, climate.template, water_heater.template unit_of_measurement float_with_unit °C/°F/K string, 72 unit options, custom allowed unit picker no longer name-matched
text.template, datetime.template initial_value float string number.template's float no longer bleeds
number.template, text.template mode lambda string sibling bleed shed
number.tmp102 temperature_high / temperature_low float_with_unit nested (number entity) sensor.tmp102's cv.temperature no longer bleeds
text_sensor.modbus_controller response_size range 0..250 1..250 platform's own int_range(min=1, max=250)
speaker.resampler bits_per_sample range 8..32 none microphone's bound; speaker also takes passthrough
event.motion threshold range 0..90 none sibling binary_sensor's bound
~215 sensors (ina3221 channels, apc1, as734x, bh1745, ...) accuracy_decimals / state_class / device_class string, no options integer; 5 / 62 options nested extends merged per field
light effects (9), display update_interval default (8), i2s sample_rate (2), binary_sensor device_class (26) lost restored same

No other entry changed; a re-sync after the review fixes matched this content exactly. A first attempt that skipped every named cv validator also dropped real cv.temperature_with_unit refinements (49 climate min/max temperatures); the unit-suffix probe keeps those.

Related issue or feature (if applicable):

Types of changes

  • Bugfix (non-breaking change which fixes an issue) — bugfix
  • New feature (non-breaking change which adds functionality) — new-feature
  • Enhancement to an existing feature — enhancement
  • Breaking change (fix or feature that would cause existing functionality to not work as expected) — breaking-change
  • Refactor (no behaviour change) — refactor
  • Documentation only — docs
  • Maintenance / chore — maintenance
  • CI / workflow change — ci
  • Dependencies bump — dependencies

Frontend coordination

  • No frontend change needed
  • Companion frontend PR: esphome/device-builder-frontend#

Checklist

  • The code change is tested and works locally.
  • Pre-commit hooks pass (ruff, codespell, yaml/json/python checks).
  • Tests have been added or updated under tests/ where applicable.
  • components.index.json / definitions/components/*.json have not been hand-edited (regenerate via script/sync_components.py if a sync is needed).
  • Architecture-level changes are reflected in docs/ARCHITECTURE.md and/or docs/API.md.

@bdraco

Copy link
Copy Markdown
Member Author

ESPHome Bot (@esphbot) review

@github-actions github-actions Bot added the bugfix Bug fix label Nov 5, 2026
@codspeed

codspeed Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

1 warning

⚠️ 1 benchmark is dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

✅ 28 untouched benchmarks
⏩ 1 skipped benchmark1


Comparing fix-sync-temperature-unit-bleed (ae3bf02) with main (d2eac18)

Open in CodSpeed

Footnotes

  1. 1 benchmark was skipped, so the baseline result was used instead. If it was deleted from the codebase, click here and archive it to remove it from the performance reports. ↩

@codecov

codecov Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.76%. Comparing base (d2eac18) to head (ae3bf02).

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #3013   +/-   ##
=======================================
  Coverage   99.76%   99.76%           
=======================================
  Files         300      300           
  Lines       26388    26388           
=======================================
  Hits        26326    26326           
  Misses         62       62           
Flag Coverage Δ
py3.12 99.73% <ø> (ø)
py3.14 99.61% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@esphbot

ESPHome Bot (esphbot) commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Previous review — superseded by a newer review below.

@esphbot ESPHome Bot (esphbot) left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tip

No blocking issues found — ready to merge.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The merge comparison misses sibling type leakage when an initial templatable-only refinement is later upgraded to float, incorrectly retyping a platform’s string field.

1 open issue
What changed in this PR

This PR corrects catalog-sync type inference so unit pickers and sibling platform schemas do not introduce inappropriate field types or ranges. Catalog regeneration is deferred to a follow-up refresh of #3010.

Changes:

  • Require name-matched unit validators to accept a unit-suffixed number before applying a unit-aware numeric type.
  • Extend platform-specific filtering to remove or replace conflicting sibling refinements and ranges.
  • Add regression tests for unit-picker classification and sibling refinement isolation.
File Description
tests/​test_sync_components_hex_display.py Adds regression coverage for unit validators and sibling platform refinements.
script/​sync_components.py Tightens validator classification and filters conflicting merged platform metadata.

Review effort: Balanced

Comment thread script/sync_components.py Resolved
@bdraco

Copy link
Copy Markdown
Member Author

Addressed in e7506f2.

  • Suggestion 1 (hub_* names): renamed to merged_ranges / merged_refined; introspect_component now computes the merges once and passes them in, so no platform manifest is walked twice for the shed.
  • MEDIUM 2 (catch-all exception read as "picker"): the probe is inverted. A picker is now identified positively: it must accept a bare unit name (validator("°C")). Any raise, vol.Invalid or otherwise, keeps the name-matched refinement.
  • MEDIUM 3 (a bounded coercer rejecting the 1 magnitude): resolved by the same inversion, since no magnitude is probed any more. A new test pins a cv.All(cv.temperature, cv.Range(min=5.0)) closure keeping float_with_unit.

The same commit also fixes a third sync bug from the 2026.11 audit: _resolve_extends now merges nested extends per field, so a mid-level partial override (VOLTAGE_SCHEMA's device_class: {default: voltage}) keeps the base sensor field's type and options. A full 2026.11.0b1 sync on this commit matches the previous run's content exactly.

ESPHome Bot (@esphbot) review

@esphbot

ESPHome Bot (esphbot) commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Previous review — superseded by a newer review below.

@esphbot ESPHome Bot (esphbot) left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tip

No blocking issues found — ready to merge.

@bdraco

Copy link
Copy Markdown
Member Author

Addressed in 1772c5a.

  • Suggestion 1: the call-site comment now says merged hub and sibling signals are shed from fields a platform domain types differently.
  • Suggestion 2: the duplicated _bleed helpers are replaced by one collect_bleed fixture in tests/conftest.py (the narrowest conftest covering both files). It applies _upgrade_stamp_only_refinements before calling _collect_bleed_keys, matching introspect_component.

ESPHome Bot (@esphbot) review

@esphbot

Copy link
Copy Markdown
Contributor

J. Nick Koston (@bdraco): Addressed in 1772c5a.

Confirmed both fixed. Comment at 5894-5895 matches contract. collect_bleed fixture applies stamp-only upgrade. No leftover _bleed callers.

@esphbot

ESPHome Bot (esphbot) commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Previous review — superseded by a newer review below.

@bdraco
J. Nick Koston (bdraco) requested a balanced review from Copilot November 5, 2026 00:35

@esphbot ESPHome Bot (esphbot) left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tip

No blocking issues found — ready to merge.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are reported for the catalog-generation fixes.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@bdraco

Copy link
Copy Markdown
Member Author

Addressed in ae3bf02: _refined_type_by_name now logs at debug level when a validator accepts a bare unit and the name-matched refinement is dropped as a unit picker, so a future catalog type change can be traced back to the probe.

ESPHome Bot (@esphbot) review

@esphbot

ESPHome Bot (esphbot) commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

PR Review — Keep unit pickers and sibling platform refinements out of the catalog sync

Ready to merge. The one suggestion from the last review is fixed in ae3bf02.

What the PR does well:

  • _refined_type_by_name (script/sync_components.py:7092-7094) now logs at debug level when a validator accepts a bare unit and its name-matched refinement is dropped. A future catalog change from float_with_unit to string can now be traced back to the probe.
  • The probe treats a validator as a unit picker only when it accepts a bare unit. If the call raises anything, the refinement is kept. Real coercers such as cv.temperature_with_unit keep their float_with_unit type.
  • The shed compares each platform against the merged ranges and refinements that platform builds actually receive. For refinements, that is the version after _upgrade_stamp_only_refinements. Sibling bleed is handled, including the stamp-only case Copilot raised.
  • _overlay_field merges each nested extends field over its inherited version key by key, with the closer schema winning. test_resolve_extends_merges_a_partial_override_over_a_grandparent_field pins this.

No open issues.



Checklist

  • Probe-driven refinement drops are observable
  • Name-match probe keeps the refinement on unexpected exceptions
  • Shed compares against the upgraded merge that platform builds receive
  • Single shared test helper matches the production merge
  • No hand-edited catalog files

Silent Failure Analysis

🟡 **1. MEDIUM** — broad exception treated as a classification signal
script/sync_components.py:7088-7091

Risk: The probe reads any exception as "this is a unit coercer". A unit picker that rejects unit_options[0] for an unrelated reason (a different casing or unit subset in its one_of, missing CORE/context state, or a TypeError from an unexpected argument type) is quietly classified as float_with_unit, which is the misclassification this change is meant to prevent, and nothing is logged on that path.

try:
    validator(refined.unit_options[0])
except Exception:
    return refined

Fix: Catch only cv.Invalid (or vol.Invalid) as the coercer-rejection signal, and log any other exception at debug level with the validator name before keeping the refinement, so a failed probe shows up in the sync log.


Automated review by Kōan (Claude) HEAD=ae3bf02 18s

@esphbot ESPHome Bot (esphbot) left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tip

No blocking issues found — ready to merge.

@bdraco
J. Nick Koston (bdraco) marked this pull request as ready for review November 5, 2026 00:52
@bdraco
J. Nick Koston (bdraco) merged commit e1e2450 into main Nov 5, 2026
26 checks passed
@bdraco
J. Nick Koston (bdraco) deleted the fix-sync-temperature-unit-bleed branch November 5, 2026 00:53
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 7, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

bugfix Bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants