Skip to content

Commit

Permalink
refactor: remove and consolidate unused code in base (#81)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco authored Jun 17, 2024
1 parent 9ec88ce commit 523d931
Showing 1 changed file with 4 additions and 24 deletions.
28 changes: 4 additions & 24 deletions src/uiprotect/data/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down Expand Up @@ -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
Expand All @@ -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]]:
Expand All @@ -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,
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 523d931

Please sign in to comment.