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 _mock_lock_operation_activity(lock, action, offset): return LockOperationActivity({ "dateTime": (time.time() + offset) * 1000, "deviceID": lock.device_id, "deviceType": "lock", "action": action, })
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_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_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
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_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 _activity_from_dict(activity_dict): action = activity_dict.get("action") if action in ACTIVITY_ACTIONS_DOORBELL_DING: return DoorbellDingActivity(activity_dict) if action in ACTIVITY_ACTIONS_DOORBELL_MOTION: return DoorbellMotionActivity(activity_dict) if action in ACTIVITY_ACTIONS_DOORBELL_VIEW: return DoorbellViewActivity(activity_dict) if action in ACTIVITY_ACTIONS_LOCK_OPERATION: return LockOperationActivity(activity_dict) if action in ACTIVITY_ACTIONS_DOOR_OPERATION: return DoorOperationActivity(activity_dict) return None
def get_house_activities(self, access_token, house_id, limit=8): response = self._call_api( "get", API_GET_HOUSE_ACTIVITIES_URL.format(house_id=house_id), access_token=access_token, params={ "limit": limit, }) activities = [] for activity_json in response.json(): action = activity_json.get("action") if action in ["doorbell_call_missed", "doorbell_call_hangup"]: activities.append(DoorbellDingActivity(activity_json)) elif action == "doorbell_motion_detected": activities.append(DoorbellMotionActivity(activity_json)) elif action == "doorbell_call_initiated": activities.append(DoorbellViewActivity(activity_json)) elif action in ["lock", "unlock"]: activities.append(LockOperationActivity(activity_json)) return activities
def test_update_lock_with_activity(self): lock = LockDetail( json.loads(load_fixture("get_lock.online_with_doorsense.json"))) self.assertEqual("ABC", lock.device_id) self.assertEqual(LockStatus.LOCKED, lock.lock_status) self.assertEqual(LockDoorStatus.OPEN, lock.door_state) self.assertEqual(dateutil.parser.parse("2017-12-10T04:48:30.272Z"), lock.lock_status_datetime) self.assertEqual(dateutil.parser.parse("2017-12-10T04:48:30.272Z"), lock.door_state_datetime) lock_operation_activity = LockOperationActivity( json.loads(load_fixture("lock_activity.json"))) unlock_operation_activity = LockOperationActivity( json.loads(load_fixture("unlock_activity.json"))) open_operation_activity = DoorOperationActivity( json.loads(load_fixture("door_open_activity.json"))) closed_operation_activity = DoorOperationActivity( json.loads(load_fixture("door_closed_activity.json"))) closed_operation_wrong_deviceid_activity = DoorOperationActivity( json.loads( load_fixture("door_closed_activity_wrong_deviceid.json"))) closed_operation_wrong_houseid_activity = DoorOperationActivity( json.loads( load_fixture("door_closed_activity_wrong_houseid.json"))) self.assertTrue( update_lock_detail_from_activity(lock, unlock_operation_activity)) self.assertEqual(LockStatus.UNLOCKED, lock.lock_status) self.assertEqual( as_utc_from_local( datetime.datetime.fromtimestamp(1582007217000 / 1000)), lock.lock_status_datetime, ) self.assertTrue( update_lock_detail_from_activity(lock, lock_operation_activity)) self.assertEqual(LockStatus.LOCKED, lock.lock_status) self.assertEqual( as_utc_from_local( datetime.datetime.fromtimestamp(1582007218000 / 1000)), lock.lock_status_datetime, ) # returns false we send an older activity self.assertFalse( update_lock_detail_from_activity(lock, unlock_operation_activity)) self.assertTrue( update_lock_detail_from_activity(lock, closed_operation_activity)) self.assertEqual(LockDoorStatus.CLOSED, lock.door_state) self.assertEqual( as_utc_from_local( datetime.datetime.fromtimestamp(1582007217000 / 1000)), lock.door_state_datetime, ) self.assertTrue( update_lock_detail_from_activity(lock, open_operation_activity)) self.assertEqual(LockDoorStatus.OPEN, lock.door_state) self.assertEqual( as_utc_from_local( datetime.datetime.fromtimestamp(1582007219000 / 1000)), lock.door_state_datetime, ) # returns false we send an older activity self.assertFalse( update_lock_detail_from_activity(lock, closed_operation_activity)) with self.assertRaises(ValueError): update_lock_detail_from_activity( lock, closed_operation_wrong_deviceid_activity) # We do not always have the houseid so we do not throw # as long as the deviceid is correct since they are unique self.assertFalse( update_lock_detail_from_activity( lock, closed_operation_wrong_houseid_activity)) self.assertEqual(LockDoorStatus.OPEN, lock.door_state) self.assertEqual(LockStatus.LOCKED, lock.lock_status) activities = _convert_lock_result_to_activities( json.loads(load_fixture("unlock.json"))) for activity in activities: self.assertTrue(update_lock_detail_from_activity(lock, activity)) self.assertEqual(LockDoorStatus.CLOSED, lock.door_state) self.assertEqual(LockStatus.UNLOCKED, lock.lock_status)