def get_doorbell_detail(self, access_token, doorbell_id): response = self._call_api( "get", API_GET_DOORBELL_URL.format(doorbell_id=doorbell_id), access_token=access_token) return DoorbellDetail(response.json())
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)
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)
def get_doorbell_detail(self, access_token, doorbell_id): return DoorbellDetail( self._dict_to_api( self._build_get_doorbell_detail_request( access_token, doorbell_id)).json())
async def _mock_doorbell_from_fixture(hass, path): json_dict = await _load_json_fixture(hass, path) return DoorbellDetail(json_dict)
async def async_get_doorbell_detail(self, access_token, doorbell_id): response = await self._async_dict_to_api( self._build_get_doorbell_detail_request(access_token, doorbell_id)) return DoorbellDetail(await response.json())