From b3b255ec5b17a18640b9e8564a39b2769d1e8109 Mon Sep 17 00:00:00 2001 From: MisterWil Date: Sun, 26 Jul 2020 10:04:45 -0700 Subject: [PATCH] Pass in specific User-Agent #14 --- skybellpy/__init__.py | 10 ++++++---- skybellpy/__main__.py | 3 ++- skybellpy/helpers/constants.py | 8 +++++++- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/skybellpy/__init__.py b/skybellpy/__init__.py index f920db5..84155b7 100644 --- a/skybellpy/__init__.py +++ b/skybellpy/__init__.py @@ -34,7 +34,8 @@ class Skybell(): def __init__(self, username=None, password=None, auto_login=False, get_devices=False, - cache_path=CONST.CACHE_PATH, disable_cache=False): + cache_path=CONST.CACHE_PATH, disable_cache=False, + agent_identifier=CONST.DEFAULT_AGENT_IDENTIFIER): """Init Abode object.""" self._username = username self._password = password @@ -43,6 +44,7 @@ def __init__(self, username=None, password=None, self._disable_cache = disable_cache self._devices = None self._session = requests.session() + self._user_agent = '{} ({})'.format(CONST.USER_AGENT, agent_identifier) # Create a new cache template self._cache = { @@ -171,9 +173,9 @@ def send_request(self, method, url, headers=None, headers['Authorization'] = 'Bearer ' + \ self.cache(CONST.ACCESS_TOKEN) - headers['user-agent'] = ( - 'SkyBell/3.4.1 (iPhone9,2; iOS 11.0; loc=en_US; lang=en-US) ' - 'com.skybell.doorbell/1') + _LOGGER.info("User-Agent: %s", self._user_agent) + + headers['user-agent'] = self._user_agent headers['content-type'] = 'application/json' headers['accepts'] = '*/*' headers['x-skybell-app-id'] = self.cache(CONST.APP_ID) diff --git a/skybellpy/__main__.py b/skybellpy/__main__.py index f2c7721..e2e8e30 100644 --- a/skybellpy/__main__.py +++ b/skybellpy/__main__.py @@ -158,7 +158,8 @@ def call(): # Create skybellpy instance. skybell = skybellpy.Skybell(username=args.username, password=args.password, - get_devices=True) + get_devices=True, + agent_identifier='skybellcl') # # Set setting # for setting in args.set or []: diff --git a/skybellpy/helpers/constants.py b/skybellpy/helpers/constants.py index 7135cb0..c971d5d 100644 --- a/skybellpy/helpers/constants.py +++ b/skybellpy/helpers/constants.py @@ -2,7 +2,7 @@ import os MAJOR_VERSION = 0 -MINOR_VERSION = 5 +MINOR_VERSION = 6 PATCH_VERSION = '0' __version__ = '{}.{}.{}'.format(MAJOR_VERSION, MINOR_VERSION, PATCH_VERSION) @@ -40,6 +40,12 @@ CACHE_PATH = './skybell.pickle' +USER_AGENT = 'skybellpy/{}.{}.{}'.format(MAJOR_VERSION, + MINOR_VERSION, + PATCH_VERSION) + +DEFAULT_AGENT_IDENTIFIER = 'default' + # URLS BASE_URL = 'https://cloud.myskybell.com/api/v3/' BASE_URL_V4 = 'https://cloud.myskybell.com/api/v4/'