Skip to content

Move Tuya type information classes to separate module#157958

Merged
epenet merged 3 commits into
devfrom
epenet-20251204-1446
Dec 4, 2025
Merged

Move Tuya type information classes to separate module#157958
epenet merged 3 commits into
devfrom
epenet-20251204-1446

Conversation

@epenet
Copy link
Copy Markdown
Contributor

@epenet epenet commented Dec 4, 2025

Proposed change

  • Move TypeInformation classes and corresponding find_dpcode function to separate module
  • Rename EnumTypeData to EnumTypeInformation
  • Rename IntegerTypeData to IntegerTypeInformation
  • Reorder TypeInformation classes in alphabetical order in the new module
  • Cleanup unused attribute _number in number platform

No functionnality changes - preliminary work for improving Tuya data validation.

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

  • 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 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
Copy Markdown
Contributor

home-assistant Bot commented Dec 4, 2025

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
Copy Markdown
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

This PR refactors the Tuya integration's type information classes by moving them from models.py to a new dedicated type_information.py module. The changes improve code organization without altering functionality.

  • Extracts TypeInformation classes and the find_dpcode function into a new module
  • Renames EnumTypeDataEnumTypeInformation and IntegerTypeDataIntegerTypeInformation for consistency
  • Alphabetically orders the TypeInformation class definitions (Bitmap, Enum, Integer)

Reviewed changes

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

Show a summary per file
File Description
homeassistant/components/tuya/type_information.py New module containing all TypeInformation classes (TypeInformation base, BitmapTypeInformation, EnumTypeInformation, IntegerTypeInformation), the type mappings dictionary, and find_dpcode function with overloads
homeassistant/components/tuya/models.py Removed TypeInformation classes and find_dpcode function; added imports from new type_information module
homeassistant/components/tuya/sensor.py Updated import to use EnumTypeInformation from type_information module instead of EnumTypeData from models
homeassistant/components/tuya/number.py Updated import to use IntegerTypeInformation from type_information module instead of IntegerTypeData from models
homeassistant/components/tuya/light.py Updated import and all references from IntegerTypeData to IntegerTypeInformation

Comment thread homeassistant/components/tuya/type_information.py Outdated
Comment thread homeassistant/components/tuya/models.py
Comment thread homeassistant/components/tuya/type_information.py Outdated
Comment thread homeassistant/components/tuya/type_information.py Outdated
epenet and others added 2 commits December 4, 2025 15:13
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

@jbouwh jbouwh left a comment

Choose a reason for hiding this comment

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

LGTM,
Thanks @epenet 👍

Comment on lines -486 to -487
_number: IntegerTypeData | None = None

Copy link
Copy Markdown
Contributor Author

@epenet epenet Dec 4, 2025

Choose a reason for hiding this comment

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

The attribute is fully unused (missed in previous wrapper migration) - better to just remove it than update the import and the type name.

@epenet epenet merged commit 81ed259 into dev Dec 4, 2025
36 checks passed
@epenet epenet deleted the epenet-20251204-1446 branch December 4, 2025 14:34
@epenet
Copy link
Copy Markdown
Contributor Author

epenet commented Dec 4, 2025

Thanks @jbouwh 👍

@github-actions github-actions Bot locked and limited conversation to collaborators Dec 5, 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