Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: consolidate logic to remove keys #44

Merged
merged 2 commits into from
Jun 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions src/uiprotect/data/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
"recordingSchedules",
}
IGNORE_DEVICE_KEYS = {"nvrMac", "guid"}
STATS_AND_IGNORE_DEVICE_KEYS = STATS_KEYS | IGNORE_DEVICE_KEYS

CAMERA_EVENT_ATTR_MAP: dict[EventType, tuple[str, str]] = {
EventType.MOTION: ("last_motion", "last_motion_event_id"),
Expand All @@ -79,11 +80,6 @@
}


def _remove_stats_keys(data: dict[str, Any]) -> None:
for key in STATS_KEYS.intersection(data):
del data[key]


def _process_light_event(event: Event) -> None:
if event.light is None:
return
Expand Down Expand Up @@ -429,7 +425,8 @@
ignore_stats: bool,
) -> WSSubscriptionMessage | None:
if ignore_stats:
_remove_stats_keys(data)
for key in STATS_KEYS.intersection(data):
del data[key]

Check warning on line 429 in src/uiprotect/data/bootstrap.py

View check run for this annotation

Codecov / codecov/patch

src/uiprotect/data/bootstrap.py#L429

Added line #L429 was not covered by tests
# nothing left to process
if not data:
self._create_stat(packet, None, True)
Expand Down Expand Up @@ -467,9 +464,10 @@
ignore_stats: bool,
) -> WSSubscriptionMessage | None:
model_type = action["modelKey"]
if ignore_stats:
_remove_stats_keys(data)
for key in IGNORE_DEVICE_KEYS.intersection(data):
remove_keys = (
STATS_AND_IGNORE_DEVICE_KEYS if ignore_stats else IGNORE_DEVICE_KEYS
)
for key in remove_keys.intersection(data):
del data[key]
# `last_motion` from cameras update every 100 milliseconds when a motion event is active
# this overrides the behavior to only update `last_motion` when a new event starts
Expand Down
Loading