Fix TuyaQuirkBuilder
quirk_file
location
#3757
Merged
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.
Proposed change
This fixes the
quirk_file
location for quirks built with theTuyaQuirkBuilder
always pointing to theTuyaQuirkBuilder
and not where theTuyaQuirkBuilder
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
andquirk_file_line
were added to zigpy here: zigpy/quirks/v2/init.py#L549-L552quirk_file(_line)
is the line/file where aQuirkBuilder
instance is constructed. Due toTuyaQuirkBuilder
extendingQuirkBuilder
, this will always point to thesuper().__init__(manufacturer, model, registry)
line inzhaquirks/tuya/builder/__init__.py
, which is unexpected and relatively useless, as it will be the same across all quirks built with theTuyaQuirkBuilder
.To fix this for now, we just set the
quirk_file
andquirk_file_line
again in ourTuyaQuirkBuilder
.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
pre-commit
checks pass / the code has been formatted using Black