Skip to content

Commit

Permalink
Merge 7fb3cf4 into 19bc8ca
Browse files Browse the repository at this point in the history
  • Loading branch information
nhorvath committed Dec 14, 2018
2 parents 19bc8ca + 7fb3cf4 commit fe93296
Show file tree
Hide file tree
Showing 9 changed files with 168 additions and 27 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,6 @@ ENV/
/.pydevproject
.settings/
*.pickle

# pycharm IDE settings
.idea/
7 changes: 6 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@ Changelog

A list of changes between each release.

0.3.0 (2018-12-14)
^^^^^^^^^^^^^^^^^^
- Switch device image back to avatar url (fixed)
- Preserve last activity image functionality via `device.activity_image`

0.2.0 (2018-12-07)
^^^^^^^^^^^^^^^^^^
- Swtich device image from avatar url (broken) to last activity image.
- Switch device image from avatar url (broken) to last activity image.

0.1.0 (2017-09-24)
^^^^^^^^^^^^^^^^^^
Expand Down
11 changes: 11 additions & 0 deletions skybell.http
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,17 @@ authorization: {{access_token}}

###

// Get avatar url for a single device

GET https://cloud.myskybell.com/api/v3/devices/{{device_id}}/avatar HTTP/1.1
content-type: application/json
user-agent: SkyBell/3.4.1 (iPhone9,2; iOS 11.0; loc=en_US; lang=en-US) com.skybell.doorbell/1
x-skybell-app-id: {{app_id}}
x-skybell-client-id: {{client_id}}
authorization: {{access_token}}

###

// Get activities for a single device

GET https://cloud.myskybell.com/api/v3/devices/{{device_id}}/activities HTTP/1.1
Expand Down
33 changes: 25 additions & 8 deletions skybellpy/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,19 @@ def get_arguments():
required=False, action='append')

parser.add_argument(
'--last-json',
'--activity-json',
metavar='device_id',
help='Output the last activity json for device_id',
help='Output the activity activity json for device_id',
required=False, action='append')

parser.add_argument(
'--last-image',
'--avatar-image',
metavar='device_id',
help='Output the avatar image url for device_id',
required=False, action='append')

parser.add_argument(
'--activity-image',
metavar='device_id',
help='Output the last activity image url for device_id',
required=False, action='append')
Expand Down Expand Up @@ -193,8 +199,8 @@ def _device_print(dev, append=''):
"Could not find device with id: %s", device_id)

# Print out last motion event
if args.last_json:
for device_id in args.last_json:
if args.activity_json:
for device_id in args.activity_json:
device = skybell.get_device(device_id)

if device:
Expand All @@ -203,9 +209,9 @@ def _device_print(dev, append=''):
_LOGGER.warning(
"Could not find device with id: %s", device_id)

# Print out last motion event
if args.last_image:
for device_id in args.last_image:
# Print out avatar image
if args.avatar_image:
for device_id in args.avatar_image:
device = skybell.get_device(device_id)

if device:
Expand All @@ -214,6 +220,17 @@ def _device_print(dev, append=''):
_LOGGER.warning(
"Could not find device with id: %s", device_id)

# Print out last motion event image
if args.activity_image:
for device_id in args.activity_image:
device = skybell.get_device(device_id)

if device:
_LOGGER.info(device.activity_image)
else:
_LOGGER.warning(
"Could not find device with id: %s", device_id)

except SkybellException as exc:
_LOGGER.error(exc)
# finally:
Expand Down
27 changes: 22 additions & 5 deletions skybellpy/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def __init__(self, device_json, skybell):
self._type = device_json.get(CONST.TYPE)
self._skybell = skybell

self._avatar_json = self._avatar_request()
self._info_json = self._info_request()
self._settings_json = self._settings_request()

Expand All @@ -33,6 +34,10 @@ def refresh(self):
new_device_json = self._device_request()
_LOGGER.debug("Device Refresh Response: %s", new_device_json)

# Update avatar url
new_avatar_json = self._avatar_request()
_LOGGER.debug("Avatar Refresh Response: %s", new_avatar_json)

# Update device detail info
new_info_json = self._info_request()
_LOGGER.debug("Device Info Refresh Response: %s", new_info_json)
Expand All @@ -43,7 +48,8 @@ def refresh(self):
new_settings_json)

# Update the stored data
self.update(new_device_json, new_info_json, new_settings_json)
self.update(new_device_json, new_info_json, new_settings_json,
new_avatar_json)

# Update the activities
self._update_activities()
Expand All @@ -53,6 +59,11 @@ def _device_request(self):
response = self._skybell.send_request(method="get", url=url)
return json.loads(response.text)

def _avatar_request(self):
url = str.replace(CONST.DEVICE_AVATAR_URL, '$DEVID$', self.device_id)
response = self._skybell.send_request(method="get", url=url)
return json.loads(response.text)

def _info_request(self):
url = str.replace(CONST.DEVICE_INFO_URL, '$DEVID$', self.device_id)
response = self._skybell.send_request(method="get", url=url)
Expand All @@ -71,11 +82,15 @@ def _activities_request(self):
response = self._skybell.send_request(method="get", url=url)
return json.loads(response.text)

def update(self, device_json=None, info_json=None, settings_json=None):
def update(self, device_json=None, info_json=None, settings_json=None,
avatar_json=None):
"""Update the internal device json data."""
if device_json:
UTILS.update(self._device_json, device_json)

if avatar_json:
UTILS.update(self._avatar_json, avatar_json)

if info_json:
UTILS.update(self._info_json, info_json)

Expand Down Expand Up @@ -193,9 +208,11 @@ def location(self):
@property
def image(self):
"""Get the most recent 'avatar' image."""
# avatar AWS url stopped working October 2018
# switched to last activity url
# return self._device_json.get(CONST.AVATAR, {}).get(CONST.AVATAR_URL)
return self._avatar_json.get(CONST.AVATAR_URL)

@property
def activity_image(self):
"""Get the most recent activity image."""
return self.latest().get(CONST.MEDIA_URL)

@property
Expand Down
2 changes: 1 addition & 1 deletion skybellpy/helpers/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import os

MAJOR_VERSION = 0
MINOR_VERSION = 2
MINOR_VERSION = 3
PATCH_VERSION = '0'

__version__ = '{}.{}.{}'.format(MAJOR_VERSION, MINOR_VERSION, PATCH_VERSION)
Expand Down
12 changes: 12 additions & 0 deletions tests/mock/device_avatar.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
"""Mock Skybell Device Avatar Response."""


def get_response_ok(data=''):
"""Return the successful device info response json."""
return '''
{
"createdAt": "2018-12-14T21:20:06.198Z",
"url":
"https://v3-production-devices-avatar.s3-us-west-2.amazonaws.com/''' + \
data + '''"
}'''

0 comments on commit fe93296

Please sign in to comment.