vNext: migrate a 4.x setup without user action - #519
Merged
Merged
Conversation
Releases 4.x used the domain gree. This moves a 4.x setup to gree_custom at start, in two phases (migration.py): - In async_setup: read the 4.x config entries and the gree: YAML block, convert every device (swing modes are matched on the value sent to the unit), and bring the devices in. When a YAML block manages the local devices they are merged into the YAML import, otherwise the new "migrate" flow step adds them to the local-only entry. - In async_setup_entry, before the platforms: unload the 4.x entry, move its entity rows (entity IDs, history and automations stay), then its device row (area and user name stay), then disable the 4.x entry while the 4.x folder exists, or remove it once the folder is gone. Moved rows that get no entity for a bound device are removed. Two repair issues guide the user: legacy_yaml shows the gree_custom: block to paste in place of gree:, and says the legacy import will be removed later; legacy_folder asks to delete custom_components/gree, which HACS leaves behind. Both are checked at every start. Home Assistant only sets up an integration with a config entry or a YAML key, so a 4.x user never starts gree_custom by itself. A small hook in the last 4.x release starts it (separate PR on master). Without it, opening the setup flow starts the migration and stops the flow. Tested on the dev instance against the real unit: UI entry, YAML block, both with the 4.x folder present and after it is deleted, the paste of the generated block, the flow fallback, and repeated starts.
A 4.x number or select that never had a value is stored as "unknown". The migration logged that as a value that is not valid, once per source of the device. Such states now count as no value and are skipped.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Users of 4.x (domain
gree) now move to this version without doing anything. Their config entries, theirgree:YAML block, and their device and entity registry rows come over. Entity IDs, areas, device names and history stay, so automations, scripts and dashboards keep working.gree:block stays YAML: it is converted at every start and goes through the normal YAML import. A repair issue shows thegree_custom:block to paste, and says that the legacy import will be removed in a later version.custom_components/gree, which HACS leaves behind.The design is in
docs/config-entry.md, section "Migration from 4.x".How it works
migration.pyworks in two phases.Phase 1, in
async_setup. It reads the 4.x entries and thegree:block and converts every device. The mapping table is in the docs. Two points matter:swing_downmostand 5.0swing_upperboth send 7, so a migrated unit moves its louvers the same way as before.When a YAML block manages the local devices, the devices are merged into the YAML import. Otherwise a new
migrateflow step adds them to the local-only entry. That step only adds devices.Phase 2, in
async_setup_entry, before the platforms.async_update_entity_platform.After the platforms are set up, moved rows without an entity are removed. 4.x created every switch, also for features the unit lacks.
What starts it
Home Assistant only sets up an integration that has a config entry or a YAML key. A 4.x user has neither for
gree_custom, so the migration code would never run by itself. Two ways cover this:gree_customwhen it is installed. This is the path without user action. It is a separate PR on master: Start the 5.0 integration when it is installed next to 4.x #520.Testing
On the dev instance against the real unit (192.168.252.99, firmware V3.75), with a UI entry that had an area, a user name and a stored temperature step of 0.5:
legacy_folderraisedgree:block, folder presentlegacy_yamlissue with a block that parses and validatesgree:legacy_yamlgonegree:block, folder deletedgree_customdoes not start. Opening the setup flow starts the migration with the same result.A conversion harness with 30 checks covers the field mapping, the swing value mapping, VRF keys, the unique ID mapping, and the round trip of the generated YAML through
ITEM_SCHEMA.pytestpasses: 227 tests.Ruff check and format pass. Mypy finds nothing new in the changed files. Pylint could not run with the Home Assistant plugin outside the devcontainer.
Notes
yamlblock, the same way core MQTT and Lovelace do.encryption_key, the same value that is already in theirconfiguration.yaml.nl.jsonhas the new strings. The other languages fall back to English.