Skip to content

Commit

Permalink
refactor: reduce code to remove keys (#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco authored Jun 17, 2024
1 parent 3950fce commit 7b496cb
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 41 deletions.
15 changes: 6 additions & 9 deletions src/uiprotect/data/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -965,16 +965,13 @@ def unifi_dict(
exclude: set[str] | None = None,
) -> dict[str, Any]:
data = super().unifi_dict(data=data, exclude=exclude)

if "wiredConnectionState" in data and data["wiredConnectionState"] is None:
del data["wiredConnectionState"]
if "wifiConnectionState" in data and data["wifiConnectionState"] is None:
del data["wifiConnectionState"]
if (
"bluetoothConnectionState" in data
and data["bluetoothConnectionState"] is None
for key in (
"wiredConnectionState",
"wifiConnectionState",
"bluetoothConnectionState",
):
del data["bluetoothConnectionState"]
if key in data and data[key] is None:
del data[key]
return data

@classmethod
Expand Down
55 changes: 23 additions & 32 deletions src/uiprotect/data/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -1062,27 +1062,21 @@ def unifi_dict(
]

data = super().unifi_dict(data=data, exclude=exclude)
for key in (
"lastRingEventId",
"lastSmartDetect",
"lastSmartAudioDetect",
"lastSmartDetectEventId",
"lastSmartAudioDetectEventId",
"lastSmartDetects",
"lastSmartAudioDetects",
"lastSmartDetectEventIds",
"lastSmartAudioDetectEventIds",
"talkbackStream",
):
if key in data:
del data[key]

if "lastRingEventId" in data:
del data["lastRingEventId"]
if "lastSmartDetect" in data:
del data["lastSmartDetect"]
if "lastSmartAudioDetect" in data:
del data["lastSmartAudioDetect"]
if "lastSmartDetectEventId" in data:
del data["lastSmartDetectEventId"]
if "lastSmartAudioDetectEventId" in data:
del data["lastSmartAudioDetectEventId"]
if "lastSmartDetects" in data:
del data["lastSmartDetects"]
if "lastSmartAudioDetects" in data:
del data["lastSmartAudioDetects"]
if "lastSmartDetectEventIds" in data:
del data["lastSmartDetectEventIds"]
if "lastSmartAudioDetectEventIds" in data:
del data["lastSmartAudioDetectEventIds"]
if "talkbackStream" in data:
del data["talkbackStream"]
if "lcdMessage" in data and data["lcdMessage"] is None:
data["lcdMessage"] = {}

Expand Down Expand Up @@ -2820,18 +2814,15 @@ def unifi_dict(
exclude: set[str] | None = None,
) -> dict[str, Any]:
data = super().unifi_dict(data=data, exclude=exclude)

if "lastMotionEventId" in data:
del data["lastMotionEventId"]
if "lastContactEventId" in data:
del data["lastContactEventId"]
if "lastValueEventId" in data:
del data["lastValueEventId"]
if "lastAlarmEventId" in data:
del data["lastAlarmEventId"]
if "extremeValueDetectedAt" in data:
del data["extremeValueDetectedAt"]

for key in (
"lastMotionEventId",
"lastContactEventId",
"lastValueEventId",
"lastAlarmEventId",
"extremeValueDetectedAt",
):
if key in data:
del data[key]
return data

@property
Expand Down

0 comments on commit 7b496cb

Please sign in to comment.