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

Add more activity types #87

Merged
merged 5 commits into from
Sep 21, 2023
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
14 changes: 14 additions & 0 deletions tests/fixtures/rf_unlock_activity_v4.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"id": "b4e50f6c-730a-4ae1-991e-e5231d727c11",
"timestamp": 1665388800273,
"icon": "https://d33mytkkohwnk6.cloudfront.net/app/ActivityFeedIcons/[email protected]",
"action": "rf_unlock",
"deviceID": "102A6A4F31584849971D11807272E7A8",
"deviceType": "lock",
"user": {
"UserID": "83f02a1d-c08a-4c3d-9c30-3b66e185c7bd",
"FirstName": "89",
"LastName": "House"
},
"title": "<b>89 House</b> unlocked <b>Gate</b> rf_unlock"
}
42 changes: 42 additions & 0 deletions tests/test_activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ def test_auto_unlock_activity(self):
assert auto_unlock_activity.operated_by == "My Name"
assert auto_unlock_activity.operated_remote is False
assert auto_unlock_activity.operated_keypad is False
assert auto_unlock_activity.operated_manual is False
assert auto_unlock_activity.operated_tag is False

def test_bluetooth_lock_activity(self):
bluetooth_lock_activity = LockOperationActivity(
Expand All @@ -150,6 +152,8 @@ def test_bluetooth_lock_activity(self):
assert bluetooth_lock_activity.operated_by == "I have a picture"
assert bluetooth_lock_activity.operated_remote is False
assert bluetooth_lock_activity.operated_keypad is False
assert bluetooth_lock_activity.operated_manual is False
assert bluetooth_lock_activity.operated_tag is False
assert bluetooth_lock_activity.operator_image_url == "https://image.url"
assert bluetooth_lock_activity.operator_thumbnail_url == "https://thumbnail.url"

Expand All @@ -160,6 +164,8 @@ def test_keypad_lock_activity(self):
assert keypad_lock_activity.operated_by == "My Name"
assert keypad_lock_activity.operated_remote is False
assert keypad_lock_activity.operated_keypad is True
assert keypad_lock_activity.operated_manual is False
assert keypad_lock_activity.operated_tag is False
assert keypad_lock_activity.operator_image_url is None
assert keypad_lock_activity.operator_thumbnail_url is None

Expand All @@ -170,6 +176,8 @@ def test_auto_lock_activity(self):
assert auto_lock_activity.operated_by == "Auto Lock"
assert auto_lock_activity.operated_remote is False
assert auto_lock_activity.operated_keypad is False
assert auto_lock_activity.operated_manual is False
assert auto_lock_activity.operated_tag is False
assert (
auto_lock_activity.operator_image_url
== "https://d33mytkkohwnk6.cloudfront.net/app/ActivityFeedIcons/[email protected]"
Expand All @@ -186,6 +194,8 @@ def test_pin_unlock_activity(self):
assert keypad_lock_activity.operated_by == "Sample Person"
assert keypad_lock_activity.operated_remote is False
assert keypad_lock_activity.operated_keypad is True
assert keypad_lock_activity.operated_manual is False
assert keypad_lock_activity.operated_tag is False
assert (
keypad_lock_activity.operator_image_url
== "https://d33mytkkohwnk6.cloudfront.net/app/ActivityFeedIcons/[email protected]"
Expand All @@ -202,6 +212,8 @@ def test_pin_unlock_activity_with_image(self):
assert keypad_lock_activity.operated_by == "Zip Zoo"
assert keypad_lock_activity.operated_remote is False
assert keypad_lock_activity.operated_keypad is True
assert keypad_lock_activity.operated_manual is False
assert keypad_lock_activity.operated_tag is False
assert (
keypad_lock_activity.operator_image_url
== "https://d33mytkkohwnk6.cloudfront.net/user/abc.jpg"
Expand All @@ -218,6 +230,8 @@ def test_remote_lock_activity(self):
assert remote_lock_activity.operated_by == "My Name"
assert remote_lock_activity.operated_remote is True
assert remote_lock_activity.operated_keypad is False
assert remote_lock_activity.operated_manual is False
assert remote_lock_activity.operated_tag is False

def test_remote_lock_activity_v4(self):
remote_lock_activity = LockOperationActivity(
Expand All @@ -226,6 +240,8 @@ def test_remote_lock_activity_v4(self):
assert remote_lock_activity.operated_by == "89 House"
assert remote_lock_activity.operated_remote is True
assert remote_lock_activity.operated_keypad is False
assert remote_lock_activity.operated_manual is False
assert remote_lock_activity.operated_tag is False
assert (
remote_lock_activity.operator_image_url
== "https://d33mytkkohwnk6.cloudfront.net/app/ActivityFeedIcons/[email protected]"
Expand All @@ -243,6 +259,8 @@ def test_remote_unlock_activity_v4(self):
assert remote_unlock_activity.operated_by == "89 House"
assert remote_unlock_activity.operated_remote is True
assert remote_unlock_activity.operated_keypad is False
assert remote_unlock_activity.operated_manual is False
assert remote_unlock_activity.operated_tag is False
assert (
remote_unlock_activity.operator_image_url
== "https://d33mytkkohwnk6.cloudfront.net/app/ActivityFeedIcons/[email protected]"
Expand All @@ -260,6 +278,8 @@ def test_remote_unlock_activity_v4_2(self):
assert remote_unlock_activity.operated_by == "Zipper Zoomer"
assert remote_unlock_activity.operated_remote is True
assert remote_unlock_activity.operated_keypad is False
assert remote_unlock_activity.operated_manual is False
assert remote_unlock_activity.operated_tag is False
assert (
remote_unlock_activity.operator_image_url
== "https://d33mytkkohwnk6.cloudfront.net/user/a45daa08-f4b0-4251-aacd-7bf5475851e5.jpg"
Expand All @@ -276,6 +296,8 @@ def test_manual_lock_activity_v4(self):
assert manual_lock_activity.operated_by == "Manual Lock"
assert manual_lock_activity.operated_remote is False
assert manual_lock_activity.operated_keypad is False
assert manual_lock_activity.operated_manual is True
assert manual_lock_activity.operated_tag is False
assert (
manual_lock_activity.operator_image_url
== "https://d33mytkkohwnk6.cloudfront.net/app/ActivityFeedIcons/[email protected]"
Expand All @@ -292,6 +314,8 @@ def test_manual_unlock_activity_v4(self):
assert manual_unlock_activity.operated_by == "Manual Unlock"
assert manual_unlock_activity.operated_remote is False
assert manual_unlock_activity.operated_keypad is False
assert manual_unlock_activity.operated_manual is True
assert manual_unlock_activity.operated_tag is False
assert (
manual_unlock_activity.operator_image_url
== "https://d33mytkkohwnk6.cloudfront.net/app/ActivityFeedIcons/[email protected]"
Expand All @@ -301,6 +325,24 @@ def test_manual_unlock_activity_v4(self):
== "https://d33mytkkohwnk6.cloudfront.net/app/ActivityFeedIcons/[email protected]"
)

def test_rf_unlock_activity_v4(self):
rf_unlock_activity = LockOperationActivity(
SOURCE_LOG, json.loads(load_fixture("rf_unlock_activity_v4.json"))
)
assert rf_unlock_activity.operated_by == "89 House"
assert rf_unlock_activity.operated_remote is False
assert rf_unlock_activity.operated_keypad is False
assert rf_unlock_activity.operated_manual is False
assert rf_unlock_activity.operated_tag is True
assert (
rf_unlock_activity.operator_image_url
== "https://d33mytkkohwnk6.cloudfront.net/app/ActivityFeedIcons/[email protected]"
)
assert (
rf_unlock_activity.operator_thumbnail_url
== "https://d33mytkkohwnk6.cloudfront.net/app/ActivityFeedIcons/[email protected]"
)

def test_lock_activity(self):
lock_operation_activity = LockOperationActivity(
SOURCE_LOG, json.loads(load_fixture("lock_activity.json"))
Expand Down
23 changes: 23 additions & 0 deletions yalexs/activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,17 @@
}
AUTO_RELOCK_ACTIONS = {ACTION_LOCK_AUTO_LOCK}

TAG_ACTIONS = {
ACTION_RF_SECURE,
ACTION_RF_LOCK,
ACTION_RF_UNLOCK,
}

MANUAL_ACTIONS = {
ACTION_LOCK_MANUAL_LOCK,
ACTION_LOCK_MANUAL_UNLOCK,
}

ACTIVITY_ACTION_STATES = {
ACTION_RF_SECURE: LockStatus.LOCKED,
ACTION_RF_LOCK: LockStatus.LOCKED,
Expand Down Expand Up @@ -396,6 +407,8 @@ def __repr__(self):
f"operated_by={self.operated_by} "
f"operated_remote={self.operated_remote} "
f"operated_keypad={self.operated_keypad} "
f"operated_tag={self.operated_tag} "
f"operated_manual={self.operated_manual} "
f"operated_autorelock={self.operated_autorelock} "
f"operator_image_url={self.operator_image_url} "
f"operator_thumbnail_url={self.operator_thumbnail_url}>"
Expand Down Expand Up @@ -430,6 +443,16 @@ def operated_keypad(self):
"""Operation used keypad."""
return self._info.get("keypad", self.action in KEYPAD_ACTIONS)

@cached_property
def operated_manual(self):
"""Operation done manually using the knob."""
return self._info.get("manual", self.action in MANUAL_ACTIONS)

@cached_property
def operated_tag(self):
"""Operation used rfid tag."""
return self._info.get("tag", self.action in TAG_ACTIONS)
Comment on lines +446 to +454
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this is only hitting coverage from the repr, we should have an explicit test for both of these to make sure its true when its operated by the knob/tag


@cached_property
def operated_autorelock(self):
"""Operation done by automatic relock."""
Expand Down
Loading