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

Add Tuya pool sensor quirk _TZE200_v1jqz5cy #3673

Open
wants to merge 6 commits into
base: dev
Choose a base branch
from

Conversation

danielp370
Copy link
Contributor

@danielp370 danielp370 commented Jan 4, 2025

Proposed change

This is an initial implementation of a standalone v2 quirk for _TZE200_v1jqz5cy Tuya Pool Sensor that works without HA or other modifications.

Additional information

What it does:

  • This implementation uses v2 quirks to instantiate a bunch of entities for each of the DP's.
  • Provides a derived class of EnchantedDevice for V2 to cast the Tuya spells. These have been tested.
  • Provides a refresh data command (via quirks v2), as per @tschiex 's implementation.
  • Provides and handles an automatic refresh config option for interval refresh in minutes.
  • Sensor readings look good to me.

What it does not do:

  • Does not yet expose the calibration config DPs.
  • A lot of units are missing as they either don't exist in HA, or are not exposed via zigpy, or are not in the validation list. I don't understand the history of unit's (aside from the need to handle conversions like C to F) but it seems unnecessarily complicated to have to define every unit. I wonder if a generic number could be provided via HA to capture these.
  • I couldn't figure out how to get a notification that the config number for auto_refresh_interval has changed, but wondering if there is a cleaner way to do this that what I did in handle_auto_update_..()

All sensors look pretty good to me, and the device on battery runs great. My only concern is chlorine seems to not change, but my CL pool levels are super low.

Suggested next steps:

  • I'd like to get this in as a quirk pretty much as-is as I think it makes the device usable.
  • Next, I can try help out on adding unit's to HA, and/or zigpy but need guidance here.

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 v2 quirk Quirks using v2 API. Might add custom entities that need translation keys in HA. labels Jan 4, 2025
@danielp370
Copy link
Contributor Author

Fixing pre-commit failures

Comment on lines 15 to 22
# Create a quirks v2 of Tuya's EnchantedDevice as we need Tuya spells
EnchantedDevice.__bases__ = (CustomDeviceV2,)


class EnchantedDeviceV2(EnchantedDevice):
"""Updated version of EnchantedDevice based on CustomDeviceV2."""

tuya_spell_data_query: bool = True # Enable data query spell
Copy link
Collaborator

@TheJulianJES TheJulianJES Jan 4, 2025

Choose a reason for hiding this comment

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

This can be done properly when #3661 is implemented. (Although I'd like to avoid duplicating the spell code in that PR if that's possible in a clean way.)
I think this implementation might cause the other tests to break at the moment(?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I changed the implementation so it doesn't conflict with the tests.

@TheJulianJES TheJulianJES changed the title _TZE200_v1jqz5cy Tuya Pool Sensor Add Tuya pool sensor quirk _TZE200_v1jqz5cy Jan 4, 2025
@TheJulianJES
Copy link
Collaborator

Regarding unit validation, we're also working on fixing this: zigpy/zha#327

Copy link

codecov bot commented Jan 5, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.89%. Comparing base (8124411) to head (b657708).
Report is 3 commits behind head on dev.

Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #3673      +/-   ##
==========================================
+ Coverage   89.85%   89.89%   +0.04%     
==========================================
  Files         322      323       +1     
  Lines       10379    10424      +45     
==========================================
+ Hits         9326     9371      +45     
  Misses       1053     1053              

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Tuya Request/PR regarding a Tuya device v2 quirk Quirks using v2 API. Might add custom entities that need translation keys in HA.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants