Skip to content

Add cluster_revision filtering to Matter discovery schema - #175693

Open
lboue wants to merge 1 commit into
home-assistant:devfrom
lboue:matter-cluster-revision-discovery
Open

Add cluster_revision filtering to Matter discovery schema#175693
lboue wants to merge 1 commit into
home-assistant:devfrom
lboue:matter-cluster-revision-discovery

Conversation

@lboue

@lboue lboue commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

Proposed change

Adds optional cluster_revision_min / cluster_revision_max attributes to MatterDiscoverySchema, so discovery can select a different entity schema based on the Matter cluster's ClusterRevision attribute (0xFFFD).

This is used to fix the Thermostat TemperatureOffset number entity: the LocalTemperatureCalibration attribute's constraint changed between Matter cluster revisions:

  • Revision ≤ 6 (Matter 1.3 and earlier): spec-constrained to raw values -25..25 (±2.5°C).
  • Revision ≥ 7 (Matter 1.4): no explicit spec constraint, so the entity now falls back to the underlying int8 storage range (±12.7°C).

This also fixes a pre-existing bug in the TemperatureOffset schema where native_max_value/native_min_value were set in raw Matter units (±25) instead of the entity's native unit (°C, after the /10 conversion), letting the UI/service calls send values 10x larger than the device actually accepts.

This is a redo of #161793 (closed due to inactivity), addressing the review from @TheJulianJES and Copilot on that PR:

  • Moved the ClusterRevision attribute ID magic number into const.py (next to FEATUREMAP_ATTRIBUTE_ID), instead of hardcoding it in the discovery loop.
  • Normalized NullValue/unreadable ClusterRevision before comparing, to avoid a runtime crash.
  • Fixed the native_max_value/native_min_value units for both the revision ≤6 and revision ≥7 schemas.
  • Replaced the previous unit tests (which duplicated the filtering logic inline) with a test that exercises real discovery through a node fixture, overriding the ClusterRevision attribute value, as suggested in review.

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New feature (which adds functionality to an existing integration)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

Checklist

  • I understand the code I am submitting and can explain how it works.
  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • I have followed the perfect PR recommendations
  • The code has been formatted using Ruff (ruff format homeassistant tests)
  • Tests have been added to verify that the new code works.
  • Any generated code has been carefully reviewed for correctness and compliance with project standards.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies a diff between library versions and ideally a link to the changelog/release notes is added to the PR description.

To help with the load of incoming pull requests:

Allows discovery schemas to filter by the Matter ClusterRevision
attribute, so entity behavior can differ across cluster spec
revisions. Applied to the Thermostat TemperatureOffset number entity,
whose LocalTemperatureCalibration constraint changed between Matter
1.3 (±2.5°C) and 1.4 (no explicit spec constraint).
Copilot AI review requested due to automatic review settings July 5, 2026 16:47
@lboue
lboue requested a review from a team as a code owner July 5, 2026 16:47
@home-assistant home-assistant Bot added cla-signed has-tests integration: matter new-feature Top 100 Integration is ranked within the top 100 by usage Top 200 Integration is ranked within the top 200 by usage Top 50 Integration is ranked within the top 50 by usage by-code-owner Quality Scale: No score labels Jul 5, 2026
@home-assistant

home-assistant Bot commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

Hey there @home-assistant/matter, mind taking a look at this pull request as it has been labeled with an integration (matter) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of matter can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant mark-draft Mark the pull request as draft.
  • @home-assistant ready-for-review Remove the draft status from the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign matter Removes the current integration label and assignees on the pull request, add the integration domain after the command.
  • @home-assistant update-branch Update the pull request branch with the base branch.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component, problem in config, problem in device, feature-request) to the pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component, problem in config, problem in device, feature-request) on the pull request.

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.

Pull request overview

This PR adds optional cluster_revision_min/cluster_revision_max filtering to MatterDiscoverySchema, letting Matter discovery pick a different entity schema based on a cluster's ClusterRevision attribute (0xFFFD). It applies this to fix the Thermostat TemperatureOffset number entity, whose LocalTemperatureCalibration constraint changed between Matter 1.3 (rev ≤6, ±2.5 °C) and Matter 1.4 (rev ≥7, no spec constraint → int8 range). It also corrects a pre-existing bug where the entity's native_min/max_value were expressed in raw Matter units (±25) instead of the entity's native °C unit after the /10 conversion.

Changes:

  • Add CLUSTER_REVISION_ATTRIBUTE_ID constant and cluster_revision_min/max schema fields plus a cluster_revision field on MatterEntityInfo.
  • Add _resolve_cluster_revision in discovery and split the TemperatureOffset schema into rev ≤6 (±2.5 °C) and rev ≥7 (±12.7 °C) variants with corrected units.
  • Add a parametrized discovery test overriding ClusterRevision, and update snapshots.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
homeassistant/components/matter/const.py Adds CLUSTER_REVISION_ATTRIBUTE_ID = 65533.
homeassistant/components/matter/models.py Adds cluster_revision to MatterEntityInfo and cluster_revision_min/max to MatterDiscoverySchema.
homeassistant/components/matter/discovery.py Adds _resolve_cluster_revision helper and wires revision filtering into discovery.
homeassistant/components/matter/number.py Splits TemperatureOffset into rev ≤6/≥7 schemas and fixes native min/max units.
tests/components/matter/test_number.py Adds parametrized test asserting bounds per ClusterRevision.
tests/components/matter/snapshots/test_number.ambr Updates snapshots to °C bounds (±2.5 / ±12.7).

Comment on lines +64 to +65
# [optional] cluster revision value if required by discovery schema
cluster_revision: int | None = None
Comment on lines +361 to +362
# Matter 1.4 dropped the ±2.5°C constraint; fall back to the
# int8 storage range of the raw attribute (-128..127 in 0.1°C units)
Comment on lines +518 to +525
@pytest.mark.parametrize("node_fixture", ["mock_thermostat"])
async def test_temperature_offset_cluster_revision(
hass: HomeAssistant,
matter_client: MagicMock,
matter_node: MatterNode,
expected_min: float,
expected_max: float,
) -> None:
@lboue

lboue commented Jul 28, 2026

Copy link
Copy Markdown
Contributor Author

Is it OK?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

by-code-owner cla-signed has-tests integration: matter new-feature Quality Scale: No score Top 50 Integration is ranked within the top 50 by usage Top 100 Integration is ranked within the top 100 by usage Top 200 Integration is ranked within the top 200 by usage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants