Skip to content

Commit

Permalink
fix: broken include/exclude behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
jcwillox committed Aug 9, 2022
1 parent f684b66 commit d6bfb42
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions custom_components/auto_backup/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@
),
)


MAP_SERVICES = {
SERVICE_BACKUP: SCHEMA_BACKUP,
SERVICE_BACKUP_FULL: SCHEMA_BACKUP_FULL,
Expand Down Expand Up @@ -240,7 +239,9 @@ def state(self):
return self._state

@classmethod
def ensure_slugs(cls, inclusion, installed_addons) -> Tuple[List, List]:
def ensure_slugs(
cls, inclusion: Dict[str, List[str]], installed_addons: List[Dict]
) -> Tuple[List[str], List[str]]:
"""Helper method to slugify both the addon and folder sections"""
addons = inclusion[ATTR_ADDONS]
folders = inclusion[ATTR_FOLDERS]
Expand All @@ -250,7 +251,7 @@ def ensure_slugs(cls, inclusion, installed_addons) -> Tuple[List, List]:
)

@staticmethod
def ensure_addon_slugs(addons, installed_addons) -> List[str]:
def ensure_addon_slugs(addons: List[str], installed_addons: List[Dict]):
"""Expand wildcards and replace addon names with their appropriate slugs."""
if not addons:
return []
Expand All @@ -270,7 +271,7 @@ def ensure_addon_slugs(addons, installed_addons) -> List[str]:
yield addon

@staticmethod
def ensure_folder_slugs(folders) -> List[str]:
def ensure_folder_slugs(folders: List[str]) -> List[str]:
"""Convert folder name to lower case and replace friendly folder names."""
if not folders:
return []
Expand Down Expand Up @@ -329,8 +330,11 @@ async def async_create_backup(self, data: Dict):
else:
installed_addons = await self._handler.get_addons()

addons = installed_addons
folders = set(DEFAULT_BACKUP_FOLDERS.values())
_LOGGER.debug("Installed addons: %s", installed_addons)

# default to include all addons and folders
addons: List[str] = [addon["slug"] for addon in installed_addons]
folders: List[str] = list(set(DEFAULT_BACKUP_FOLDERS.values()))

if include:
addons, folders = self.ensure_slugs(include, installed_addons)
Expand All @@ -341,11 +345,8 @@ async def async_create_backup(self, data: Dict):
excluded_addons, excluded_folders = self.ensure_slugs(
exclude, installed_addons
)
addons = [
addon["slug"]
for addon in addons
if addon["slug"] not in excluded_addons
]

addons = [addon for addon in addons if addon not in excluded_addons]
folders = [
folder for folder in folders if folder not in excluded_folders
]
Expand Down

0 comments on commit d6bfb42

Please sign in to comment.