-
-
Notifications
You must be signed in to change notification settings - Fork 34.4k
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
Conversation
Hey there @tuya, @zlinoliver, mind taking a look at this pull request as it has been labeled with an integration ( Code owner commandsCode owners of
|
There was a problem hiding this 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
andconversion_fn
fromUnitOfMeasurement
definitions. - Simplified sensor and number entities to only scale raw values (no per-unit conversion).
- Updated snapshots to reflect the change in unit (
A
→mA
), 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 removedself._uom
attribute. Consider renaming it to something likeunit_meta
orunit_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
andnative_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(
6341cd9
to
c945f5e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @epenet 👍
../Frenck
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
insteadPreliminary PR for #148596
Type of change
Additional information
Checklist
ruff format homeassistant tests
)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest
.requirements_all.txt
.Updated by running
python3 -m script.gen_requirements_all
.To help with the load of incoming pull requests: