Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix TuyaQuirkBuilder quirk_file location #3757

Merged

Conversation

TheJulianJES
Copy link
Collaborator

@TheJulianJES TheJulianJES commented Jan 23, 2025

Proposed change

This fixes the quirk_file location for quirks built with the TuyaQuirkBuilder always pointing to the TuyaQuirkBuilder and not where the TuyaQuirkBuilder instance was created (so the quirk file).

Additional information

Due to quirks v2 no longer having a unique class that inherits from CustomDevice per quirk, quirk_file and quirk_file_line were added to zigpy here: zigpy/quirks/v2/init.py#L549-L552

quirk_file(_line) is the line/file where a QuirkBuilder instance is constructed. Due to TuyaQuirkBuilder extending QuirkBuilder, this will always point to the super().__init__(manufacturer, model, registry) line in zhaquirks/tuya/builder/__init__.py, which is unexpected and relatively useless, as it will be the same across all quirks built with the TuyaQuirkBuilder.

To fix this for now, we just set the quirk_file and quirk_file_line again in our TuyaQuirkBuilder.

Future

In the future, we may want to fix this another way in zigpy, but this solution is fine IMO, so we can go with it for now.
We should also consider adding a test for this.

We could also consider doing this from add_to_registry()?

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

@TheJulianJES TheJulianJES added Tuya Request/PR regarding a Tuya device bugfix This PR fixes a bug labels Jan 23, 2025
Copy link

codecov bot commented Jan 23, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.13%. Comparing base (c00eb01) to head (09ad08c).
Report is 1 commits behind head on dev.

Additional details and impacted files
@@           Coverage Diff           @@
##              dev    #3757   +/-   ##
=======================================
  Coverage   90.12%   90.13%           
=======================================
  Files         320      320           
  Lines       10466    10473    +7     
=======================================
+ Hits         9433     9440    +7     
  Misses       1033     1033           

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

@TheJulianJES TheJulianJES merged commit d900f4b into zigpy:dev Jan 23, 2025
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix This PR fixes a bug Tuya Request/PR regarding a Tuya device
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant