Skip to content

Fix test_attributes_updated_not_replaced test#4794

Draft
TheJulianJES wants to merge 5 commits intozigpy:devfrom
TheJulianJES:tjj/adjust_attributes_updated_not_replaced_test
Draft

Fix test_attributes_updated_not_replaced test#4794
TheJulianJES wants to merge 5 commits intozigpy:devfrom
TheJulianJES:tjj/adjust_attributes_updated_not_replaced_test

Conversation

@TheJulianJES
Copy link
Copy Markdown
Collaborator

DRAFT. Testing.

Proposed change

  • Update test_attributes_updated_not_replaced to validate inherited attributes using cluster._attributes_by_id instead of flat .attributes, so valid manufacturer-specific definitions sharing a ZCL ID are handled correctly.
  • Add a targeted guard that fails quirk-only attributes defined with manufacturer_code=None only when the ID collides with a base ZCL attribute, while allowing non-colliding IDs.
  • Keep explicit ignore entries for known Sinope cluster issues.

Additional information

Device diagnostics

None.

Checklist

  • The changes are tested and work correctly
  • pre-commit checks pass / the code has been formatted using Black
  • Tests have been added to verify that the new code works
  • Device diagnostics data has been attached

@codecov
Copy link
Copy Markdown

codecov bot commented Feb 27, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.65%. Comparing base (becb068) to head (42327c0).

Additional details and impacted files
@@           Coverage Diff           @@
##              dev    #4794   +/-   ##
=======================================
  Coverage   92.65%   92.65%           
=======================================
  Files         379      379           
  Lines       12745    12745           
=======================================
  Hits        11809    11809           
  Misses        936      936           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment on lines +804 to +805
zhaquirks.sinope.switch.SinopeTechnologiesBasicCluster,
zhaquirks.sinope.switch.SinopeTechnologiesMeteringCluster,
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The test didn't catch these before but they're really interesting:
Here, the default power_source attribute is overwritten (by name) with a manufacturer attribute and different attribute type:

class SinopeTechnologiesBasicCluster(CustomCluster, Basic):
"""SinopetechnologiesBasicCluster custom cluster ."""
EnergySource: Final = EnergySource
class AttributeDefs(Basic.AttributeDefs):
"""Sinope Manufacturer Basic Cluster Attributes."""
power_source: Final = foundation.ZCLAttributeDef(
id=0x0007, type=EnergySource, access="r", is_manufacturer_specific=True
)

And two ZCL attributes on the Metering cluster are overwritten here (by name as well) with a manufacturer attribute and different data type:

class AttributeDefs(Metering.AttributeDefs):
"""Sinope Manufacturer Metering Cluster Attributes."""
status: Final = foundation.ZCLAttributeDef(
id=0x0200, type=ValveStatus, access="r", is_manufacturer_specific=True
)
unit_of_measure: Final = foundation.ZCLAttributeDef(
id=0x0300, type=UnitOfMeasure, access="r", is_manufacturer_specific=True
)

There's a bit more discussion on that here: #4042 (comment)

Ultimately, this should not be allowed, right? Should it be possible for a quirk just to change the data type, e.g. do this without manufacturer_code or is_manufacturer_specific? Also no, right?

I guess we can just rename the colliding Sinope attributes and we're good?

@TheJulianJES
Copy link
Copy Markdown
Collaborator Author

There is another case we should consider:

pi_heating_demand: Final = ZCLAttributeDef(
id=VALVE_POSITION_ATTR_ID,
# Values range from 0-100
type=t.uint8_t,
zcl_type=DataTypeId.enum8,
is_manufacturer_specific=True,
)

Here, a ZCL attribute is overwritten with a manufacturer-specific one with the same name and a different data type, similar to the Sinope examples above, but the ID is also changed.
This should "mostly work", as ZHA reads attributes by name but it is likely still unexpected for a ZCL attribute to be replaced like this. We should look into validating this either directly in zigpy (but allowing exceptions?) or by improving this test.

For now, I'll try to see if I can add an exception for the Hue sensor in:

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant