Skip to content

Commit

Permalink
feat: remove deepcopy before calling update_from_dict (#140)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco authored Jul 3, 2024
1 parent 819ef2f commit 23bc68f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
5 changes: 2 additions & 3 deletions src/uiprotect/data/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import asyncio
import logging
from copy import deepcopy
from dataclasses import dataclass
from datetime import datetime
from typing import TYPE_CHECKING, Any
Expand Down Expand Up @@ -399,7 +398,7 @@ def _process_nvr_update(
return None

old_nvr = self.nvr.copy()
self.nvr = self.nvr.update_from_dict(deepcopy(data))
self.nvr = self.nvr.update_from_dict(data)

return WSSubscriptionMessage(
action=WSAction.UPDATE,
Expand Down Expand Up @@ -455,7 +454,7 @@ def _process_device_update(
return None

old_obj = obj.copy()
obj = obj.update_from_dict(deepcopy(data))
obj = obj.update_from_dict(data)

if model_type is ModelType.EVENT:
if TYPE_CHECKING:
Expand Down
11 changes: 6 additions & 5 deletions src/uiprotect/data/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -1090,11 +1090,12 @@ def get_changed(self, data_before_changes: dict[str, Any]) -> dict[str, Any]:
return updated

def update_from_dict(self, data: dict[str, Any]) -> Camera:
# a message in the past is actually a singal to wipe the message
reset_at = data.get("lcd_message", {}).get("reset_at")
if reset_at is not None:
reset_at = from_js_time(reset_at)
if utc_now() > reset_at:
# a message in the past is actually a signal to wipe the message
if (reset_at := data.get("lcd_message", {}).get("reset_at")) is not None:
if utc_now() > from_js_time(reset_at):
# Important: Make a copy of the data before modifying it
# since unifi_dict_to_dict will otherwise report incorrect changes
data = data.copy()
data["lcd_message"] = None

return super().update_from_dict(data)
Expand Down

0 comments on commit 23bc68f

Please sign in to comment.