From 523d931f6a06b7c66fc7af7cdfac2abf8ebaa737 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 16 Jun 2024 22:37:25 -0500 Subject: [PATCH] refactor: remove and consolidate unused code in base (#81) --- src/uiprotect/data/base.py | 28 ++++------------------------ 1 file changed, 4 insertions(+), 24 deletions(-) diff --git a/src/uiprotect/data/base.py b/src/uiprotect/data/base.py index 72a0e056..77c660f2 100644 --- a/src/uiprotect/data/base.py +++ b/src/uiprotect/data/base.py @@ -185,12 +185,6 @@ def _get_unifi_remaps(cls) -> dict[str, str]: """ return {} - @classmethod - @cache - def _get_unifi_remaps_set(self) -> set[str]: - """Helper method to get set of all child UFP objects.""" - return set(self._get_unifi_remaps()) - @classmethod @cache def _get_to_unifi_remaps(cls) -> dict[str, str]: @@ -238,9 +232,9 @@ def _get_protect_objs(cls) -> dict[str, type[ProtectBaseObject]]: @classmethod @cache - def _get_protect_objs_set(cls) -> set[str]: - """Helper method to get all child UFP objects""" - return set(cls._get_protect_objs()) + def _get_excluded_fields(cls) -> set[str]: + """Helper method to get all excluded fields for the current object.""" + return set(cls._get_protect_objs()) | set(cls._get_protect_lists()) @classmethod @cache @@ -251,12 +245,6 @@ def _get_protect_lists(cls) -> dict[str, type[ProtectBaseObject]]: assert cls._protect_lists is not None return cls._protect_lists - @classmethod - @cache - def _get_protect_lists_set(cls) -> set[str]: - """Helper method to get all child UFP objects""" - return set(cls._get_protect_lists()) - @classmethod @cache def _get_protect_dicts(cls) -> dict[str, type[ProtectBaseObject]]: @@ -266,12 +254,6 @@ def _get_protect_dicts(cls) -> dict[str, type[ProtectBaseObject]]: assert cls._protect_dicts is not None return cls._protect_dicts - @classmethod - @cache - def _get_protect_dicts_set(cls) -> set[str]: - """Helper method to get all child UFP objects""" - return set(cls._get_protect_dicts()) - @classmethod def _clean_protect_obj( cls, @@ -448,9 +430,7 @@ def unifi_dict( """ use_obj = False if data is None: - excluded_fields = ( - self._get_protect_objs_set() | self._get_protect_lists_set() - ) + excluded_fields = self._get_excluded_fields() if exclude is not None: excluded_fields |= exclude data = self.dict(exclude=excluded_fields)