示例#1
0
 def test_update_doorbell_image_from_activity_missing_image_at_start(self):
     doorbell = DoorbellDetail(
         json.loads(load_fixture("get_doorbell_missing_image.json")))
     self.assertEqual("K98GiDT45GUL", doorbell.device_id)
     self.assertEqual(
         None,
         doorbell.image_created_at_datetime,
     )
     self.assertEqual(None, doorbell.image_url)
     doorbell_motion_activity_no_image = DoorbellMotionActivity(
         json.loads(load_fixture("doorbell_motion_activity_no_image.json")))
     self.assertFalse(
         update_doorbell_image_from_activity(
             doorbell, doorbell_motion_activity_no_image))
     doorbell_motion_activity = DoorbellMotionActivity(
         json.loads(load_fixture("doorbell_motion_activity.json")))
     self.assertTrue(
         update_doorbell_image_from_activity(doorbell,
                                             doorbell_motion_activity))
     self.assertEqual(
         dateutil.parser.parse("2020-02-20T17:44:45Z"),
         doorbell.image_created_at_datetime,
     )
     self.assertEqual("https://my.updated.image/image.jpg",
                      doorbell.image_url)
示例#2
0
    def test_update_doorbell_image_from_activity(self):
        doorbell = DoorbellDetail(json.loads(
            load_fixture("get_doorbell.json")))
        self.assertEqual("K98GiDT45GUL", doorbell.device_id)
        self.assertEqual(
            dateutil.parser.parse("2017-12-10T08:01:35Z"),
            doorbell.image_created_at_datetime,
        )
        self.assertEqual("https://image.com/vmk16naaaa7ibuey7sar.jpg",
                         doorbell.image_url)
        doorbell_motion_activity_no_image = DoorbellMotionActivity(
            json.loads(load_fixture("doorbell_motion_activity_no_image.json")))
        self.assertFalse(
            update_doorbell_image_from_activity(
                doorbell, doorbell_motion_activity_no_image))
        doorbell_motion_activity = DoorbellMotionActivity(
            json.loads(load_fixture("doorbell_motion_activity.json")))
        self.assertTrue(
            update_doorbell_image_from_activity(doorbell,
                                                doorbell_motion_activity))
        self.assertEqual(
            dateutil.parser.parse("2020-02-20T17:44:45Z"),
            doorbell.image_created_at_datetime,
        )
        self.assertEqual("https://my.updated.image/image.jpg",
                         doorbell.image_url)
        old_doorbell_motion_activity = DoorbellMotionActivity(
            json.loads(load_fixture("doorbell_motion_activity_old.json")))
        # returns false we send an older activity
        self.assertFalse(
            update_doorbell_image_from_activity(doorbell,
                                                old_doorbell_motion_activity))
        self.assertEqual(
            dateutil.parser.parse("2020-02-20T17:44:45Z"),
            doorbell.image_created_at_datetime,
        )
        self.assertEqual("https://my.updated.image/image.jpg",
                         doorbell.image_url)
        wrong_doorbell_motion_activity = DoorbellMotionActivity(
            json.loads(load_fixture("doorbell_motion_activity_wrong.json")))

        with self.assertRaises(ValueError):
            update_doorbell_image_from_activity(
                doorbell, wrong_doorbell_motion_activity)
示例#3
0
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
示例#4
0
    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