From 4234ed7cfeefc793a054318e882f7fd1e141e529 Mon Sep 17 00:00:00 2001 From: Tomaae <23486452+tomaae@users.noreply.github.com> Date: Thu, 25 Apr 2024 01:32:17 +0200 Subject: [PATCH] Fixed automatic removal of non-existing datasets,fixes #153 --- custom_components/truenas/coordinator.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/custom_components/truenas/coordinator.py b/custom_components/truenas/coordinator.py index 59750a4..f4f6dd9 100644 --- a/custom_components/truenas/coordinator.py +++ b/custom_components/truenas/coordinator.py @@ -870,7 +870,7 @@ def get_dataset(self) -> None: for device in device_registry.devices.values(): if ( self.config_entry.entry_id in device.config_entries - and device.name.endswith(" Datasets") + and device.name.endswith("Datasets") ): self.datasets_hass_device_id = device.id _LOGGER.debug(f"datasets device: {device.name}") @@ -887,7 +887,10 @@ def get_dataset(self) -> None: if ( entity.device_id == self.datasets_hass_device_id and entity.unique_id.removeprefix(f"{self.name.lower()}-dataset-") - not in map(str.lower, self.ds["dataset"].keys()) + not in map( + lambda x: str.replace(x, "/", "_"), + map(str.lower, self.ds["dataset"].keys()), + ) ): _LOGGER.debug(f"dataset to be removed: {entity.unique_id}") entities_to_be_removed.append(entity.entity_id)