From cf7330baad208fb1b5df3a01f28ddcf154129d7f Mon Sep 17 00:00:00 2001 From: Olen Date: Wed, 20 Sep 2023 22:53:18 +0200 Subject: [PATCH 1/5] Add more activity types --- yalexs/activity.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/yalexs/activity.py b/yalexs/activity.py index 3cb6746..9e7b787 100644 --- a/yalexs/activity.py +++ b/yalexs/activity.py @@ -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, @@ -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}>" @@ -430,11 +443,25 @@ 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) + + @cached_property def operated_autorelock(self): """Operation done by automatic relock.""" return self.user_id == "automaticrelock" or self.action in AUTO_RELOCK_ACTIONS + + + @cached_property def operator_image_url(self): """URL to the image of the lock operator.""" From 397509a5c7399ae24617e03482e1885b4f58f51d Mon Sep 17 00:00:00 2001 From: Ola Thoresen Date: Wed, 20 Sep 2023 23:08:04 +0200 Subject: [PATCH 2/5] Fix whitespace --- yalexs/activity.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/yalexs/activity.py b/yalexs/activity.py index 9e7b787..ad2a4db 100644 --- a/yalexs/activity.py +++ b/yalexs/activity.py @@ -453,15 +453,11 @@ def operated_tag(self): """Operation used rfid tag.""" return self._info.get("tag", self.action in TAG_ACTIONS) - @cached_property def operated_autorelock(self): """Operation done by automatic relock.""" return self.user_id == "automaticrelock" or self.action in AUTO_RELOCK_ACTIONS - - - @cached_property def operator_image_url(self): """URL to the image of the lock operator.""" From 915f3df1719a08905471aaf132685f1f6ee49584 Mon Sep 17 00:00:00 2001 From: Ola Thoresen Date: Thu, 21 Sep 2023 07:34:18 +0200 Subject: [PATCH 3/5] Add tests for rf_unlock. Update other tests --- tests/fixtures/rf_unlock_activity_v4.json | 14 ++++++++ tests/test_activity.py | 42 +++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 tests/fixtures/rf_unlock_activity_v4.json diff --git a/tests/fixtures/rf_unlock_activity_v4.json b/tests/fixtures/rf_unlock_activity_v4.json new file mode 100644 index 0000000..1e98e79 --- /dev/null +++ b/tests/fixtures/rf_unlock_activity_v4.json @@ -0,0 +1,14 @@ +{ + "id": "b4e50f6c-730a-4ae1-991e-e5231d727c11", + "timestamp": 1665388800273, + "icon": "https://d33mytkkohwnk6.cloudfront.net/app/ActivityFeedIcons/rf_unlock@3x.png", + "action": "rf_unlock", + "deviceID": "102A6A4F31584849971D11807272E7A8", + "deviceType": "lock", + "user": { + "UserID": "83f02a1d-c08a-4c3d-9c30-3b66e185c7bd", + "FirstName": "89", + "LastName": "House" + }, + "title": "89 House unlocked Gate rf_unlock" +} diff --git a/tests/test_activity.py b/tests/test_activity.py index 57b80b9..9cf858b 100644 --- a/tests/test_activity.py +++ b/tests/test_activity.py @@ -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 manual_lock_activity.operated_manual is False + assert manual_lock_activity.operated_tag is False def test_bluetooth_lock_activity(self): bluetooth_lock_activity = LockOperationActivity( @@ -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 manual_lock_activity.operated_manual is False + assert manual_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" @@ -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 manual_lock_activity.operated_manual is False + assert manual_lock_activity.operated_tag is False assert keypad_lock_activity.operator_image_url is None assert keypad_lock_activity.operator_thumbnail_url is None @@ -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 manual_lock_activity.operated_manual is False + assert manual_lock_activity.operated_tag is False assert ( auto_lock_activity.operator_image_url == "https://d33mytkkohwnk6.cloudfront.net/app/ActivityFeedIcons/auto_lock@3x.png" @@ -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 manual_lock_activity.operated_manual is False + assert manual_lock_activity.operated_tag is False assert ( keypad_lock_activity.operator_image_url == "https://d33mytkkohwnk6.cloudfront.net/app/ActivityFeedIcons/pin_unlock@3x.png" @@ -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 manual_lock_activity.operated_manual is False + assert manual_lock_activity.operated_tag is False assert ( keypad_lock_activity.operator_image_url == "https://d33mytkkohwnk6.cloudfront.net/user/abc.jpg" @@ -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 manual_lock_activity.operated_manual is False + assert manual_lock_activity.operated_tag is False def test_remote_lock_activity_v4(self): remote_lock_activity = LockOperationActivity( @@ -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 manual_lock_activity.operated_manual is False + assert manual_lock_activity.operated_tag is False assert ( remote_lock_activity.operator_image_url == "https://d33mytkkohwnk6.cloudfront.net/app/ActivityFeedIcons/remote_lock@3x.png" @@ -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 manual_lock_activity.operated_manual is False + assert manual_lock_activity.operated_tag is False assert ( remote_unlock_activity.operator_image_url == "https://d33mytkkohwnk6.cloudfront.net/app/ActivityFeedIcons/remote_unlock@3x.png" @@ -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 manual_lock_activity.operated_manual is False + assert manual_lock_activity.operated_tag is False assert ( remote_unlock_activity.operator_image_url == "https://d33mytkkohwnk6.cloudfront.net/user/a45daa08-f4b0-4251-aacd-7bf5475851e5.jpg" @@ -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/manual_lock@3x.png" @@ -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_lock_activity.operated_manual is True + assert manual_lock_activity.operated_tag is False assert ( manual_unlock_activity.operator_image_url == "https://d33mytkkohwnk6.cloudfront.net/app/ActivityFeedIcons/manual_unlock@3x.png" @@ -301,6 +325,24 @@ def test_manual_unlock_activity_v4(self): == "https://d33mytkkohwnk6.cloudfront.net/app/ActivityFeedIcons/manual_unlock@3x.png" ) + def test_rf_unlock_activity_v4(self): + manual_unlock_activity = LockOperationActivity( + SOURCE_LOG, json.loads(load_fixture("rf_unlock_activity.json")) + ) + assert manual_unlock_activity.operated_by == "89 House" + assert manual_unlock_activity.operated_remote is False + assert manual_unlock_activity.operated_keypad is False + assert manual_lock_activity.operated_manual is False + assert manual_lock_activity.operated_tag is True + assert ( + manual_unlock_activity.operator_image_url + == "https://d33mytkkohwnk6.cloudfront.net/app/ActivityFeedIcons/rf_unlock@3x.png" + ) + assert ( + manual_unlock_activity.operator_thumbnail_url + == "https://d33mytkkohwnk6.cloudfront.net/app/ActivityFeedIcons/rf_unlock@3x.png" + ) + def test_lock_activity(self): lock_operation_activity = LockOperationActivity( SOURCE_LOG, json.loads(load_fixture("lock_activity.json")) From d66c6120ef803574c4f15896232e07ede475f696 Mon Sep 17 00:00:00 2001 From: Ola Thoresen Date: Thu, 21 Sep 2023 07:39:40 +0200 Subject: [PATCH 4/5] Fix tests --- tests/test_activity.py | 60 +++++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/tests/test_activity.py b/tests/test_activity.py index 9cf858b..cfb855e 100644 --- a/tests/test_activity.py +++ b/tests/test_activity.py @@ -142,8 +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 manual_lock_activity.operated_manual is False - assert manual_lock_activity.operated_tag 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( @@ -152,8 +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 manual_lock_activity.operated_manual is False - assert manual_lock_activity.operated_tag 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" @@ -164,8 +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 manual_lock_activity.operated_manual is False - assert manual_lock_activity.operated_tag is False + 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 @@ -176,8 +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 manual_lock_activity.operated_manual is False - assert manual_lock_activity.operated_tag 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/auto_lock@3x.png" @@ -194,8 +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 manual_lock_activity.operated_manual is False - assert manual_lock_activity.operated_tag is False + 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/pin_unlock@3x.png" @@ -212,8 +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 manual_lock_activity.operated_manual is False - assert manual_lock_activity.operated_tag is False + 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" @@ -230,8 +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 manual_lock_activity.operated_manual is False - assert manual_lock_activity.operated_tag 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( @@ -240,8 +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 manual_lock_activity.operated_manual is False - assert manual_lock_activity.operated_tag 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/remote_lock@3x.png" @@ -259,8 +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 manual_lock_activity.operated_manual is False - assert manual_lock_activity.operated_tag 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/remote_unlock@3x.png" @@ -278,8 +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 manual_lock_activity.operated_manual is False - assert manual_lock_activity.operated_tag 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" @@ -314,8 +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_lock_activity.operated_manual is True - assert manual_lock_activity.operated_tag 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/manual_unlock@3x.png" @@ -326,20 +326,20 @@ def test_manual_unlock_activity_v4(self): ) def test_rf_unlock_activity_v4(self): - manual_unlock_activity = LockOperationActivity( + rf_unlock_activity = LockOperationActivity( SOURCE_LOG, json.loads(load_fixture("rf_unlock_activity.json")) ) - assert manual_unlock_activity.operated_by == "89 House" - assert manual_unlock_activity.operated_remote is False - assert manual_unlock_activity.operated_keypad is False - assert manual_lock_activity.operated_manual is False - assert manual_lock_activity.operated_tag is True + 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 ( - manual_unlock_activity.operator_image_url + rf_unlock_activity.operator_image_url == "https://d33mytkkohwnk6.cloudfront.net/app/ActivityFeedIcons/rf_unlock@3x.png" ) assert ( - manual_unlock_activity.operator_thumbnail_url + rf_unlock_activity.operator_thumbnail_url == "https://d33mytkkohwnk6.cloudfront.net/app/ActivityFeedIcons/rf_unlock@3x.png" ) From 299d40ce3721844bc881d72200b89f2cce110001 Mon Sep 17 00:00:00 2001 From: Ola Thoresen Date: Thu, 21 Sep 2023 07:41:42 +0200 Subject: [PATCH 5/5] Fix filename --- tests/test_activity.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_activity.py b/tests/test_activity.py index cfb855e..db2b519 100644 --- a/tests/test_activity.py +++ b/tests/test_activity.py @@ -327,7 +327,7 @@ def test_manual_unlock_activity_v4(self): def test_rf_unlock_activity_v4(self): rf_unlock_activity = LockOperationActivity( - SOURCE_LOG, json.loads(load_fixture("rf_unlock_activity.json")) + 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