Skip to content

Commit

Permalink
Merge pull request #47 from bdraco/operation_details
Browse files Browse the repository at this point in the history
Add additional details to the Lock activity
  • Loading branch information
snjoetw authored Mar 8, 2020
2 parents dee8716 + d11777b commit 3556550
Show file tree
Hide file tree
Showing 8 changed files with 315 additions and 1 deletion.
38 changes: 38 additions & 0 deletions august/activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,14 +167,52 @@ def __init__(self, data):
super().__init__(ActivityType.LOCK_OPERATION, data)

calling_user = data.get("callingUser", {})

info = data.get("info", {})
self._operated_remote = info.get("remote", False)
self._operated_keypad = info.get("keypad", False)
self._operated_autorelock = calling_user.get("UserID") == "automaticrelock"
self._operated_by = "{} {}".format(
calling_user.get("FirstName"), calling_user.get("LastName"),
)

image_info = calling_user.get("imageInfo", {})
self._operator_image_url = image_info.get("original", {}).get(
"secure_url", None
)
self._operator_thumbnail_url = image_info.get("thumbnail", {}).get(
"secure_url", None
)

@property
def operated_by(self):
return self._operated_by

@property
def operated_remote(self):
"""Operation was remote."""
return self._operated_remote

@property
def operated_keypad(self):
"""Operation used keypad."""
return self._operated_keypad

@property
def operated_autorelock(self):
"""Operation done by automatic relock."""
return self._operated_autorelock

@property
def operator_image_url(self):
"""URL to the image of the lock operator."""
return self._operator_image_url

@property
def operator_thumbnail_url(self):
"""URL to the thumbnail of the lock operator."""
return self._operator_thumbnail_url


class DoorOperationActivity(Activity):
def __init__(self, data):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name="py-august",
version="0.23.0",
version="0.24.0",
packages=["august"],
url="https://github.com/snjoetw/py-august",
license="MIT",
Expand Down
38 changes: 38 additions & 0 deletions tests/fixtures/auto_relock_activity.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"entities": {
"device": "deviceid",
"callingUser": "callinguser",
"otherUser": "deleted",
"house": "houseid",
"activity": "activityid"
},
"house": {
"houseID": "house",
"houseName": "namehouse"
},
"eventID": "eventid",
"dateTime": 1583535312002,
"action": "lock",
"deviceName": "lockname",
"deviceID": "deviceid",
"deviceType": "lock",
"callingUser": {
"FirstName": "I have no",
"LastName": "picture",
"UserID": "automaticrelock"
},
"otherUser": {
"UserID": "deleted",
"FirstName": "Unknown",
"LastName": "User",
"UserName": "deleteduser",
"PhoneNo": "deleted"
},
"info": {
"mechanical": "success",
"crypto": "success",
"dateTime": "2020-03-06T22:55:12.002Z",
"action": "lock",
"DateLogActionID": "uni"
}
}
38 changes: 38 additions & 0 deletions tests/fixtures/auto_unlock_activity.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"entities": {
"device": "deviceid",
"callingUser": "callinguser",
"otherUser": "deleted",
"house": "houseid",
"activity": "activityid"
},
"house": {
"houseID": "house",
"houseName": "namehouse"
},
"eventID": "eventid",
"dateTime": 1583535312002,
"action": "unlock",
"deviceName": "lockname",
"deviceID": "deviceid",
"deviceType": "lock",
"callingUser": {
"UserID": "userid",
"FirstName": "My",
"LastName": "Name"
},
"otherUser": {
"UserID": "deleted",
"FirstName": "Unknown",
"LastName": "User",
"UserName": "deleteduser",
"PhoneNo": "deleted"
},
"info": {
"mechanical": "success",
"crypto": "success",
"dateTime": "2020-03-06T22:55:12.002Z",
"action": "unlock",
"DateLogActionID": "uni"
}
}
52 changes: 52 additions & 0 deletions tests/fixtures/bluetooth_lock_activity.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"entities": {
"device": "deviceid",
"callingUser": "callinguser",
"otherUser": "deleted",
"house": "houseid",
"activity": "activityid"
},
"house": {
"houseID": "house",
"houseName": "namehouse"
},
"eventID": "eventid",
"dateTime": 1583535312002,
"action": "lock",
"deviceName": "lockname",
"deviceID": "deviceid",
"deviceType": "lock",
"callingUser": {
"UserID": "myuser",
"FirstName": "I have a",
"LastName": "picture",
"imageInfo": {
"original": {
"width": 400,
"height": 400,
"format": "jpg",
"secure_url": "https://image.url"
},
"thumbnail": {
"width": 128,
"height": 128,
"format": "jpg",
"secure_url": "https://thumbnail.url"
}
}
},
"otherUser": {
"UserID": "deleted",
"FirstName": "Unknown",
"LastName": "User",
"UserName": "deleteduser",
"PhoneNo": "deleted"
},
"info": {
"mechanical": "success",
"crypto": "success",
"dateTime": "2020-03-06T22:55:12.002Z",
"action": "lock",
"DateLogActionID": "uni"
}
}
38 changes: 38 additions & 0 deletions tests/fixtures/keypad_lock_activity.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"entities": {
"device": "deviceid",
"callingUser": "callinguser",
"otherUser": "deleted",
"house": "houseid",
"activity": "activityid"
},
"house": {
"houseID": "house",
"houseName": "namehouse"
},
"source": {
"sourceType": "mercury"
},
"eventID": "eventid",
"dateTime": 1583535312002,
"action": "lock",
"deviceName": "lockname",
"deviceID": "deviceid",
"deviceType": "lock",
"callingUser": {
"UserID": "userid",
"FirstName": "My",
"LastName": "Name"
},
"otherUser": {
"UserID": "deleted",
"FirstName": "Unknown",
"LastName": "User",
"UserName": "deleteduser",
"PhoneNo": "deleted"
},
"info": {
"agent": "mercury",
"keypad": true
}
}
37 changes: 37 additions & 0 deletions tests/fixtures/remote_lock_activity.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"entities": {
"device": "deviceid",
"callingUser": "callinguser",
"otherUser": "deleted",
"house": "houseid",
"activity": "activityid"
},
"house": {
"houseID": "house",
"houseName": "namehouse"
},
"source": {
"sourceType": "mercury"
},
"eventID": "eventid",
"dateTime": 1583535312002,
"action": "lock",
"deviceName": "lockname",
"deviceID": "deviceid",
"deviceType": "lock",
"callingUser": {
"UserID": "userid",
"FirstName": "My",
"LastName": "Name"
},
"otherUser": {
"UserID": "deleted",
"FirstName": "Unknown",
"LastName": "User",
"UserName": "deleteduser",
"PhoneNo": "deleted"
},
"info": {
"remote": true
}
}
73 changes: 73 additions & 0 deletions tests/test_activity.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import json
import unittest
import os

from august.activity import (
ACTION_DOOR_CLOSED,
Expand All @@ -16,10 +18,18 @@
ACTIVITY_ACTIONS_DOORBELL_MOTION,
ACTIVITY_ACTIONS_DOORBELL_VIEW,
ACTIVITY_ACTIONS_LOCK_OPERATION,
LockOperationActivity,
)
from august.lock import LockDoorStatus, LockStatus


def load_fixture(filename):
"""Load a fixture."""
path = os.path.join(os.path.dirname(__file__), "fixtures", filename)
with open(path) as fptr:
return fptr.read()


class TestActivity(unittest.TestCase):
def test_activity_action_states(self):
self.assertIs(
Expand Down Expand Up @@ -48,3 +58,66 @@ def test_activity_actions(self):
self.assertCountEqual(
ACTIVITY_ACTIONS_DOOR_OPERATION, [ACTION_DOOR_OPEN, ACTION_DOOR_CLOSED]
)

def test_auto_unlock_activity(self):
auto_unlock_activity = LockOperationActivity(
json.loads(load_fixture("auto_unlock_activity.json"))
)
assert auto_unlock_activity.operated_by == "My Name"
assert auto_unlock_activity.operated_remote is False
assert auto_unlock_activity.operated_keypad is False

def test_bluetooth_lock_activity(self):
bluetooth_lock_activity = LockOperationActivity(
json.loads(load_fixture("bluetooth_lock_activity.json"))
)
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.operator_image_url == "https://image.url"
assert bluetooth_lock_activity.operator_thumbnail_url == "https://thumbnail.url"

def test_keypad_lock_activity(self):
keypad_lock_activity = LockOperationActivity(
json.loads(load_fixture("keypad_lock_activity.json"))
)
assert keypad_lock_activity.operated_by == "My Name"
assert keypad_lock_activity.operated_remote is False
assert keypad_lock_activity.operated_keypad is True

def test_remote_lock_activity(self):
remote_lock_activity = LockOperationActivity(
json.loads(load_fixture("remote_lock_activity.json"))
)
assert remote_lock_activity.operated_by == "My Name"
assert remote_lock_activity.operated_remote is True
assert remote_lock_activity.operated_keypad is False

def test_lock_activity(self):
lock_operation_activity = LockOperationActivity(
json.loads(load_fixture("lock_activity.json"))
)
assert lock_operation_activity.operated_by == "MockHouse House"
assert lock_operation_activity.operated_remote is True
assert lock_operation_activity.operated_keypad is False
assert lock_operation_activity.operated_autorelock is False

def test_unlock_activity(self):
unlock_operation_activity = LockOperationActivity(
json.loads(load_fixture("unlock_activity.json"))
)
assert unlock_operation_activity.operated_by == "MockHouse House"
assert unlock_operation_activity.operated_keypad is False
assert unlock_operation_activity.operated_remote is True
assert unlock_operation_activity.operator_image_url is None
assert unlock_operation_activity.operated_autorelock is False
assert unlock_operation_activity.operator_thumbnail_url is None

def test_autorelock_activity(self):
auto_relock_operation_activity = LockOperationActivity(
json.loads(load_fixture("auto_relock_activity.json"))
)
assert auto_relock_operation_activity.operated_by == "I have no picture"
assert auto_relock_operation_activity.operated_remote is False
assert auto_relock_operation_activity.operated_autorelock is True
assert auto_relock_operation_activity.operated_keypad is False

0 comments on commit 3556550

Please sign in to comment.