Skip to content
New issue

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

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

Already on GitHub? # to your account

Don't create activity from lock status polls #95

Merged
merged 1 commit into from
Feb 25, 2024
Merged
Show file tree
Hide file tree
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
34 changes: 34 additions & 0 deletions tests/test_pubnub_activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,40 @@ def test_update_lock_details_from_pubnub_message(self):
)
assert activities[0].operated_by is None

# status polls should not create activities
activities = activities_from_pubnub_message(
lock,
dateutil.parser.parse("2017-12-10T05:48:30.272Z"),
{
"remoteEvent": 1,
"status": "kAugLockState_Locked",
"info": {
"action": "status",
"startTime": "2024-02-15T07:33:50.804Z",
"context": {
"transactionID": "RP99lHGUIx",
"startDate": "2024-02-15T07:33:50.793Z",
"retryCount": 1,
},
"lockType": "lock_version_17",
"serialNumber": "L.....",
"rssi": 0,
"wlanRSSI": -35,
"wlanSNR": -1,
"duration": 991,
"lockID": "AF5EFD84.....",
"bridgeID": "652e35ba7e.....",
"serial": "L.....",
},
"doorState": "kAugDoorState_Closed",
"retryCount": 1,
"totalTime": 1028,
"resultsFromOperationCache": False,
},
)

assert len(activities) == 0


class TestDetail(unittest.TestCase):
def test_update_doorbell_details_from_pubnub_message(self):
Expand Down
10 changes: 10 additions & 0 deletions yalexs/pubnub_activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,16 @@ def activities_from_pubnub_message(
activity_dict["deviceType"] = "lock"
activity_dict["info"] = info
calling_user_id = message.get("callingUserID")

# Some locks sometimes send lots of status messages, triggered by the app. Ignore these.
if (
info.get("action") == "status"
and not message.get("error")
and not message.get("result") == "failed"
):
_LOGGER.debug("Not creating lock activity from status pubnub")
return activities

# Only accept a UserID if we have a date/time
# as otherwise it is a duplicate of the previous
# activity
Expand Down
Loading