|
4 | 4 |
|
5 | 5 | import homeassistant.helpers.config_validation as cv
|
6 | 6 | import voluptuous as vol
|
| 7 | +from homeassistant.config_entries import ConfigEntry |
7 | 8 |
|
8 | 9 | try:
|
9 | 10 | from homeassistant.components.zha import Gateway as ZHAGateway
|
|
16 | 17 |
|
17 | 18 | from . import params as PARDEFS
|
18 | 19 | from . import utils as u
|
| 20 | +from .const import DOMAIN |
19 | 21 |
|
20 | 22 | DEPENDENCIES = ["zha"]
|
21 | 23 |
|
22 |
| -DOMAIN = "zha_toolkit" |
23 |
| - |
24 | 24 | # Legacy parameters
|
25 | 25 | ATTR_COMMAND = "command"
|
26 | 26 | ATTR_COMMAND_DATA = "command_data"
|
@@ -935,3 +935,51 @@ async def command_handler_register_services(
|
935 | 935 | app, listener, ieee, cmd, data, service, params, event_data
|
936 | 936 | ):
|
937 | 937 | await _register_services(u.get_hass(listener))
|
| 938 | + |
| 939 | + |
| 940 | +# For migrating from one version to another. |
| 941 | +# Added to migrate from a configuration.yaml entry to UI configuration |
| 942 | +# Example migration function |
| 943 | +# Return True when migration is successful |
| 944 | +# |
| 945 | +async def async_migrate_entry(hass, config_entry: ConfigEntry): |
| 946 | + """Migrate old entry.""" |
| 947 | + LOGGER.debug( |
| 948 | + "Migrating configuration from version %s.%s", |
| 949 | + config_entry.version, |
| 950 | + config_entry.minor_version, |
| 951 | + ) |
| 952 | + |
| 953 | + from .config_flow import ZhaToolkitCustomConfigFlow as CF |
| 954 | + |
| 955 | + new_data = {**config_entry.data} |
| 956 | + |
| 957 | + # Sample code to test version migration and update it |
| 958 | + # if config_entry.version > 1: |
| 959 | + # # This means the user has downgraded from a future version |
| 960 | + # return False |
| 961 | + |
| 962 | + # if config_entry.version == 1: |
| 963 | + |
| 964 | + # new_data = {**config_entry.data} |
| 965 | + # if config_entry.minor_version < 2: |
| 966 | + # # TODO: modify Config Entry data with changes in version 1.2 |
| 967 | + # pass |
| 968 | + # if config_entry.minor_version < 3: |
| 969 | + # # TODO: modify Config Entry data with changes in version 1.3 |
| 970 | + # pass |
| 971 | + |
| 972 | + hass.config_entries.async_update_entry( |
| 973 | + config_entry, |
| 974 | + data=new_data, |
| 975 | + minor_version=CF.MIN_VERSION, |
| 976 | + version=CF.VERSION, |
| 977 | + ) |
| 978 | + |
| 979 | + LOGGER.debug( |
| 980 | + "Migration to configuration version %s.%s successful", |
| 981 | + config_entry.version, |
| 982 | + config_entry.minor_version, |
| 983 | + ) |
| 984 | + |
| 985 | + return True |
0 commit comments