Skip to content

Add inverted status option for Tuya covers#166020

Open
nishantapatil3 wants to merge 18 commits intohome-assistant:devfrom
nishantapatil3:codex/tuya-cover-invert-status
Open

Add inverted status option for Tuya covers#166020
nishantapatil3 wants to merge 18 commits intohome-assistant:devfrom
nishantapatil3:codex/tuya-cover-invert-status

Conversation

@nishantapatil3
Copy link

@nishantapatil3 nishantapatil3 commented Mar 19, 2026

Proposed change

This PR adds a local per-cover config switch for the Tuya integration to invert cover status semantics for devices where Tuya and Home Assistant disagree on open/closed state.

When enabled, the inversion is applied consistently to:

  • the interpreted open/closed state
  • the reported current position percentage
  • open_cover / close_cover behavior
  • set_cover_position
  • button-mode open/close commands

It also adds tests covering inverted state, percentage mapping, and command dispatch.

Type of change

  • New feature (which adds functionality to an existing integration)
  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • 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:
  • Link to developer documentation pull request:
  • Link to frontend pull request:

Checklist

  • I understand the code I am submitting and can explain how it works.
  • 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.
  • Any generated code has been carefully reviewed for correctness and compliance with project standards.

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 diff between library versions and ideally a link to the changelog/release notes is added to the PR description.

To help with the load of incoming pull requests:

Copilot AI review requested due to automatic review settings March 19, 2026 18:40
Copy link

@home-assistant home-assistant bot left a comment

Choose a reason for hiding this comment

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

Hi @nishantapatil3

It seems you haven't yet signed a CLA. Please do so here.

Once you do that we will be able to review and accept this pull request.

Thanks!

@home-assistant home-assistant bot marked this pull request as draft March 19, 2026 18:40
@home-assistant
Copy link

Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍

Learn more about our pull request process.

@home-assistant
Copy link

Hey there @tuya, @zlinoliver, 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, problem in config, problem in device, feature-request) to the pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component, problem in config, problem in device, feature-request) on the pull request.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a per-cover, locally stored configuration switch for the Tuya integration that inverts cover status semantics, and wires that inversion into position/state interpretation and outgoing commands.

Changes:

  • Introduces a config switch entity per Tuya cover to toggle “Invert status”, with state restoration and dispatcher signaling.
  • Applies inversion logic in the Tuya cover entity for is_closed, current position, open/close, and set-position behaviors.
  • Adds tests validating inverted state/position mapping and command dispatch when inversion is enabled.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
homeassistant/components/tuya/cover.py Applies the inversion flag to cover state/position and outgoing commands; subscribes to inversion change signals.
homeassistant/components/tuya/switch.py Adds a local config switch entity per cover to toggle inversion, restores its state, and notifies covers via dispatcher.
homeassistant/components/tuya/const.py Adds constants for storing inversion state in hass.data and for the dispatcher signal format.
homeassistant/components/tuya/strings.json Adds the "invert_status" translation key for the new config switch name.
tests/components/tuya/test_cover.py Adds coverage for inverted state/position mapping and inverted command dispatch.

Copilot AI review requested due to automatic review settings March 19, 2026 19:02
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds an opt-in, per-cover configuration switch for the Tuya integration to invert cover status semantics, allowing users to correct devices whose reported/open-close behavior is reversed.

Changes:

  • Introduces a local “Invert status” config switch (with restore support) per discovered Tuya cover.
  • Applies inversion to interpreted cover state/position and to outgoing open/close/set-position commands.
  • Adds tests validating inverted state/position mapping and command dispatch for both percentage-based and enum-action covers.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
homeassistant/components/tuya/const.py Adds constants for storing inversion state and signaling inversion updates.
homeassistant/components/tuya/cover.py Applies inversion logic to cover state/position and outgoing commands; listens for inversion toggle signals.
homeassistant/components/tuya/switch.py Adds a per-cover config switch (RestoreEntity) to toggle inversion and notify related cover entities.
homeassistant/components/tuya/strings.json Adds translated names for the new inversion switch (indexed and non-indexed).
tests/components/tuya/test_cover.py Adds test coverage for inverted behavior (state/position + command mapping).

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings March 19, 2026 19:09
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a per-cover, locally stored config switch to the Tuya integration to invert cover open/closed semantics for devices that report (and/or interpret) position/state opposite to Home Assistant’s expectations.

Changes:

  • Add a new config SwitchEntity (with restore support) to toggle “Invert status” per Tuya cover entity.
  • Apply inversion consistently in the cover entity for position/state interpretation and for outgoing open/close/set_position commands.
  • Add tests validating inverted state/position mapping and command dispatch.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
homeassistant/components/tuya/cover.py Applies the inversion flag to reported position/state and outgoing commands; listens for inversion-toggle signals to refresh state.
homeassistant/components/tuya/switch.py Introduces a restore-capable config switch per cover to toggle inversion and dispatch update signals.
homeassistant/components/tuya/const.py Adds constants for the inversion state store key and dispatcher signal format.
homeassistant/components/tuya/strings.json Adds localized entity names for the new “Invert status” switch (indexed + non-indexed).
tests/components/tuya/test_cover.py Adds tests for inverted state/position mapping and inverted outgoing command payloads.

Copilot AI review requested due to automatic review settings March 19, 2026 19:28
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.

Copilot AI review requested due to automatic review settings March 19, 2026 19:51
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Copilot AI review requested due to automatic review settings March 19, 2026 20:17
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated no new comments.

@nishantapatil3 nishantapatil3 marked this pull request as ready for review March 19, 2026 20:28
Copilot AI review requested due to automatic review settings March 19, 2026 20:28
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.

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.

2 participants