8000 Add support for Tuya fault sensors by MrAdam · Pull Request #125098 · home-assistant/core · GitHub
[go: up one dir, main page]

Skip to content

Add support for Tuya fault sensors #125098

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

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

Add support for Tuya fault sensors #125098

wants to merge 79 commits into from

Conversation

MrAdam
Copy link
@MrAdam MrAdam commented Sep 2, 2024

Proposed change

Added support for Tuya fault sensors, indicating any active fault sensors on a Tuya product.

I no 8000 ticed that my MeacoDry Arete Two 12L exposed a field called fault, with a type of Bitmap, and the following spec:

{
  "label": [
    "tankfull",
    "defrost",
    "E1",
    "E2",
    "L2",
    "L3",
    "L4",
    "wet"
  ]
}

I then found out through Tuya documentation that this is a general field, so I decided to try and implement detection and parsing of this field.

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • 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

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue:
  • Link to documentation pull request:

Checklist

  • 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.

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 link to the changelog, or at minimum a diff between library versions is added to the PR description.

To help with the load of incoming pull requests:

@home-assistant
Copy link
home-assistant bot commented Sep 2, 2024

Hey there @tuya, @zlinoliver, @frenck, mind taking a look at this pull request as it has been labeled with an integration (tuya) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of tuya can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign tuya Removes the current integration label and assignees on the pull request, add the integration domain after the command.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component) to the pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component) on the pull request.

@MrAdam
Copy link
Author
MrAdam commented Sep 2, 2024

I'm aware that some code changes might be needed, for example extracting the new logic in is_on(self) to separate methods. I just wanted to get some feedback on my code before I did the final prettifying.

This commit refactors the Tuya binary sensor setup in the `async_setup_entry` function. It introduces two new helper functions: `_get_fault_labels` and `_get_fault_sensors`. These functions are responsible for retrieving fault labels and creating fault sensors for the Tuya binary sensor device.
@MrAdam
Copy link
Author
MrAdam commented Sep 12, 2024

I've done some cleanup of the code and extracted the new logic to separate methods.
I hope maybe @frenck will get some time to look at it at some point - I'm very open to feedback.

@MrAdam MrAdam marked this pull request as ready for review March 13, 2025 16:33
@home-assistant home-assistant bot requested a review from frenck March 13, 2025 16:33
@MrAdam
Copy link
Author
MrAdam commented May 13, 2025

@frenck it looks like several PR's have been opened since I opened mine back in September, trying to solve the same issue:
#129437
#137771

We should probably figure out which one should be merged, and close the others as they solve the same problem.

@epenet and @jbouwh I can see that you have been reviewing one of the other PR's but it looks like the author hasn't gotten back yet - maybe you can help me get this reviewed and merged, so we can get this feature added?

@emontnemery emontnemery mentioned this pull request May 23, 2025
19 tasks
@emontnemery
Copy link
Contributor

I think this PR looks like the most promising of the three alternatives.

@MrAdam Could you please add some tests though? Note that we really want tests to set up the integration and check the resulting state in the state machine unlike what the tests in the alternative PRs do.

Please feel free to reach out to me on Discord if you need some help with implementing tests.

@MrAdam
Copy link
Author
MrAdam commented May 27, 2025

I think this PR looks like the most promising of the three alternatives.

@MrAdam Could you please add some tests though? Note that we really want tests to set up the integration and check the resulting state in the state machine unlike what the tests in the alternative PRs do.

Please feel free to reach out to me on Discord if you need some help with implementing tests.

I'll give it a try.
Do you have a reference to an integration that does it in the best possible way, just so I can see how it should be structured?

@frickua
Copy link
frickua commented May 27, 2025

I leave some review comments. Also, I think we need to expand this code to whole bitmap types not for faults only

@frickua
Copy link
frickua commented May 27, 2025

I resolve some own coments on this PR MrAdam#1

@frickua
Copy link
frickua commented May 28, 2025

@MrAdam, take a look, for pr to this branch, maybe it would be simple to merge it MrAdam#1

About bitmaps - padding is needed only when converted to binary string representation, bitwise shift with & works well with "all" numbers. Tuya API returning dec number, so loss is not possible.
Also, if shift used - array length no need any more.

@MrAdam
Copy link
Author
MrAdam commented Jun 3, 2025

It will probably take some time before I can look at this again (I have started looking into tests), as I just started a new job this week, and am a bit swamped.

9854

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

Successfully merging this pull request may close these issues.

4 participants
0