-
-
Notifications
You must be signed in to change notification settings - Fork 36.2k
Replace Tuya remap methods with helper class #158718
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 refactors the Tuya integration's value remapping functionality by introducing a new RemapHelper class to replace the previous confusing methods. The changes improve code clarity by making source and target ranges explicit, converting reverse to a keyword-only argument, and eliminating fake IntegerTypeInformation instances that were previously created just to access helper methods.
Key changes:
- Introduced
RemapHelperdataclass with explicit source/target ranges and factory methods - Replaced
IntegerTypeInformation.remap_value_to/frommethods withRemapHelperinstances - Made
type_datafield non-optional inTypeInformationclass since it's always provided
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| homeassistant/components/tuya/util.py | Added new RemapHelper dataclass with remap_value_to, remap_value_from, and static remap_value methods; includes factory methods for creating instances from type information or function data |
| homeassistant/components/tuya/type_information.py | Removed remap_value_to and remap_value_from methods from IntegerTypeInformation; changed type_data from optional to required field |
| homeassistant/components/tuya/light.py | Replaced fake IntegerTypeInformation instances with RemapHelper instances for HSV defaults; updated brightness, color temperature, and color data wrappers to use RemapHelper |
| homeassistant/components/tuya/fan.py | Updated _FanSpeedIntegerWrapper to use RemapHelper instance for value remapping |
| homeassistant/components/tuya/cover.py | Updated _DPCodePercentageMappingWrapper to use RemapHelper instance; contains import error (uses .utils instead of .util) |
Proposed change
The current remap methods are confusing:
0-100in cover,1-100in fan,0-360/0-100/0-255/MIN_MIREDS-MAX_MIREDSin light) were passed in bothremap_value_fromandremap_value_toIntegerTypeInformationclasses in order to access the helper method thereThis replaces the current methods with a helper class so that:
IntegerTypeInformationinstances are replaced withRemapHelperinstancesType 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: