diff --git a/custom_components/proxmoxve/__init__.py b/custom_components/proxmoxve/__init__.py index 5e3ca18..6913314 100644 --- a/custom_components/proxmoxve/__init__.py +++ b/custom_components/proxmoxve/__init__.py @@ -204,8 +204,13 @@ async def async_migrate_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> CONF_LXC: config_entry.data.get(CONF_LXC), } - config_entry.version = 2 - hass.config_entries.async_update_entry(config_entry, data=data_new, options={}) + hass.config_entries.async_update_entry( + config_entry, + data=data_new, + options={}, + version=2, + minor_version=1, + ) LOGGER.debug("Migration - remove devices: %s", device_identifiers) for device_identifier in device_identifiers: @@ -235,9 +240,12 @@ async def async_migrate_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> for resource in config_entry.data[CONF_LXC]: device_identifiers.append(f"{ProxmoxType.LXC.upper()}_{resource}") - config_entry.version = 3 hass.config_entries.async_update_entry( - config_entry, data=config_entry.data, options={} + config_entry, + data=config_entry.data, + options={}, + version=3, + minor_version=1, ) LOGGER.debug("Migration - remove devices: %s", device_identifiers) @@ -260,7 +268,6 @@ async def async_migrate_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> ) if config_entry.version == 3: - config_entry.version = 4 data_new = { CONF_HOST: config_entry.data.get(CONF_HOST), CONF_PORT: config_entry.data.get(CONF_PORT), @@ -273,7 +280,52 @@ async def async_migrate_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> CONF_LXC: config_entry.data.get(CONF_LXC), CONF_STORAGE: [], } - hass.config_entries.async_update_entry(config_entry, data=data_new, options={}) + hass.config_entries.async_update_entry( + config_entry, + data=data_new, + options={}, + version=4, + minor_version=1, + ) + + if config_entry.version == 4: + for storage in config_entry.data.get(CONF_STORAGE): + dev_reg = dr.async_get(hass) + device = dev_reg.async_get_or_create( + config_entry_id=config_entry.entry_id, + identifiers={ + ( + DOMAIN, + ( + f"{config_entry.entry_id}_{ProxmoxType.Storage.upper()}_{storage}" + ), + ) + }, + ) + dev_reg.async_update_device( + device_id=device.id, + remove_config_entry_id=config_entry.entry_id, + ) + + data_new = { + CONF_HOST: config_entry.data.get(CONF_HOST), + CONF_PORT: config_entry.data.get(CONF_PORT), + CONF_USERNAME: config_entry.data.get(CONF_USERNAME), + CONF_PASSWORD: config_entry.data.get(CONF_PASSWORD), + CONF_REALM: config_entry.data.get(CONF_REALM), + CONF_VERIFY_SSL: config_entry.data.get(CONF_VERIFY_SSL), + CONF_NODES: config_entry.data.get(CONF_NODES), + CONF_QEMU: config_entry.data.get(CONF_QEMU), + CONF_LXC: config_entry.data.get(CONF_LXC), + CONF_STORAGE: [], + } + hass.config_entries.async_update_entry( + config_entry, + data=data_new, + options={}, + version=5, + minor_version=1, + ) LOGGER.info("Migration to version %s successful", config_entry.version) @@ -488,7 +540,7 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b for storage_id in config_entry.data[CONF_STORAGE]: if storage_id in [ - (resource.get("storage", None)) + (resource.get("id", None)) for resource in (resources if resources is not None else []) ]: ir.async_delete_issue( @@ -519,7 +571,7 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b "port": config_entry.data[CONF_PORT], "resource_type": ProxmoxType.Storage.capitalize(), "resource": storage_id, - "permission": f"['perm','/storage/{storage_id}',['Datastore.Audit'],'any',1]", + "permission": f"['perm','{storage_id}',['Datastore.Audit'],'any',1]", }, ) @@ -610,8 +662,8 @@ def device_info( node = coordinator_data.node name = cordinator_resource.name - identifier = f"{config_entry.entry_id}_{api_category.upper()}_{resource_id}" - url = f"https://{host}:{port}/#v1:0:={api_category}/{node}/{resource_id}" + identifier = f"{config_entry.entry_id}_{api_category.upper()}_{resource_id.replace("storage/", "")}" + url = f"https://{host}:{port}/#v1:0:={resource_id}" via_device = ( DOMAIN, f"{config_entry.entry_id}_{ProxmoxType.Node.upper()}_{node}", diff --git a/custom_components/proxmoxve/config_flow.py b/custom_components/proxmoxve/config_flow.py index 4c71b03..07ab838 100644 --- a/custom_components/proxmoxve/config_flow.py +++ b/custom_components/proxmoxve/config_flow.py @@ -246,13 +246,7 @@ async def async_step_change_expose( resource_lxc[str(resource["vmid"])] = f"{resource['vmid']}" if ("type" in resource) and (resource["type"] == ProxmoxType.Storage): if "storage" in resource: - resource_storage[str(resource["storage"])] = ( - f"{resource['storage']} {resource['id']}" - ) - else: - resource_storage[str(resource["storage"])] = ( - f"{resource['storage']}" - ) + resource_storage[str(resource["id"])] = resource["id"] return self.async_show_form( step_id="change_expose", @@ -469,7 +463,7 @@ async def async_process_selection_changes( class ProxmoxVEConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): """ProxmoxVE Config Flow class.""" - VERSION = 4 + VERSION = 5 _reauth_entry: config_entries.ConfigEntry | None = None def __init__(self) -> None: diff --git a/custom_components/proxmoxve/coordinator.py b/custom_components/proxmoxve/coordinator.py index 1cfd1a7..7800867 100644 --- a/custom_components/proxmoxve/coordinator.py +++ b/custom_components/proxmoxve/coordinator.py @@ -419,7 +419,7 @@ async def _async_update_data(self) -> ProxmoxStorageData: for resource in resources if resources is not None else []: if "storage" in resource: - if resource["storage"] == self.resource_id: + if resource["id"] == self.resource_id: node_name = resource["node"] api_path = "cluster/resources?type=storage" @@ -435,13 +435,12 @@ async def _async_update_data(self) -> ProxmoxStorageData: api_status = [] for api_storage in api_storages: - if api_storage["storage"] == self.resource_id: + if api_storage["id"] == self.resource_id: api_status = api_storage if api_status is None or "content" not in api_status: raise UpdateFailed(f"Storage {self.resource_id} unable to be found") - update_device_via(self, ProxmoxType.Storage, node_name) storage_id = api_status["id"] name = f"Storage {storage_id.replace("storage/", "")}" return ProxmoxStorageData(