Skip to content

Use suggested unit of measurement in tuya #148599

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

Merged
merged 3 commits into from
Jul 15, 2025
Merged

Use suggested unit of measurement in tuya #148599

merged 3 commits into from
Jul 15, 2025

Conversation

epenet
Copy link
Contributor

@epenet epenet commented Jul 11, 2025

Proposed change

Custom unit conversions were added as part of #57913 before automatic unit conversions got implemented by the base number and sensor platforms.

Use suggested_unit_of_measurement instead

Preliminary PR for #148596

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:
  • Link to developer documentation pull request:
  • Link to frontend 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:

@Copilot Copilot AI review requested due to automatic review settings July 11, 2025 08:35
@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) 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.

Copy link
Contributor

@Copilot 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

This PR removes custom unit conversion logic from the Tuya integration now that the base number and sensor platforms handle conversions automatically. Key changes include:

  • Dropped conversion_unit and conversion_fn from UnitOfMeasurement definitions.
  • Simplified sensor and number entities to only scale raw values (no per-unit conversion).
  • Updated snapshots to reflect the change in unit (AmA), precision, and state values.

Reviewed Changes

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

File Description
tests/components/tuya/snapshots/test_sensor.ambr Updated expected unit, precision, and state in snapshot tests.
homeassistant/components/tuya/sensor.py Removed custom conversion logic and self._uom attribute.
homeassistant/components/tuya/number.py Mirrored simplification of conversion logic for number entities.
homeassistant/components/tuya/const.py Eliminated conversion_unit and conversion_fn from unit models.
Comments suppressed due to low confidence (2)

homeassistant/components/tuya/sensor.py:1418

  • [nitpick] The local variable uom is concise but may be unclear and shadows the removed self._uom attribute. Consider renaming it to something like unit_meta or unit_info for better clarity.
            uom = uoms.get(self.native_unit_of_measurement) or uoms.get(

homeassistant/components/tuya/number.py:385

  • Consider adding tests for number entities to verify that native_value and native_unit_of_measurement remain correct after removing custom conversion logic, covering both integer and float cases.
            uom = uoms.get(self.native_unit_of_measurement) or uoms.get(

@epenet epenet changed the title Drop custom unit conversion from tuya Use suggested_unit_of_measurement tuya Jul 11, 2025
@epenet epenet changed the title Use suggested_unit_of_measurement tuya Use suggested_unit_of_measurement in tuya Jul 11, 2025
@epenet epenet changed the title Use suggested_unit_of_measurement in tuya Use suggested unit of measurement in tuya Jul 11, 2025
@FredrikM97
Copy link
Contributor

@epenet Looks like this can solve the issue mentioned in #146599? Should I update my pr?

@epenet
Copy link
Contributor Author

epenet commented Jul 12, 2025

@epenet Looks like this can solve the issue mentioned in #146599? Should I update my pr?

Let's wait till this PR is accepted/merged

@epenet epenet force-pushed the epenet-20250711-1030 branch from 6341cd9 to c945f5e Compare July 14, 2025 11:55
Copy link
Member

@frenck frenck left a comment

Choose a reason for hiding this comment

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

Thanks, @epenet 👍

../Frenck

@frenck frenck merged commit 41e2610 into dev Jul 15, 2025
33 of 34 checks passed
@frenck frenck deleted the epenet-20250711-1030 branch July 15, 2025 08:34
@github-actions github-actions bot locked and limited conversation to collaborators Jul 16, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy