Skip to content

Commit

Permalink
Login delay, removed info log, 0.6.1 version
Browse files Browse the repository at this point in the history
  • Loading branch information
MisterWil committed Jul 26, 2020
1 parent b3b255e commit 94d0bc4
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 14 deletions.
17 changes: 12 additions & 5 deletions skybellpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import os.path
import json
import logging
import time
import requests
from requests.exceptions import RequestException

Expand All @@ -35,7 +36,8 @@ class Skybell():
def __init__(self, username=None, password=None,
auto_login=False, get_devices=False,
cache_path=CONST.CACHE_PATH, disable_cache=False,
agent_identifier=CONST.DEFAULT_AGENT_IDENTIFIER):
agent_identifier=CONST.DEFAULT_AGENT_IDENTIFIER,
login_sleep=True):
"""Init Abode object."""
self._username = username
self._password = password
Expand All @@ -45,6 +47,7 @@ def __init__(self, username=None, password=None,
self._devices = None
self._session = requests.session()
self._user_agent = '{} ({})'.format(CONST.USER_AGENT, agent_identifier)
self._login_sleep = login_sleep

# Create a new cache template
self._cache = {
Expand All @@ -67,7 +70,7 @@ def __init__(self, username=None, password=None,
if get_devices:
self.get_devices()

def login(self, username=None, password=None):
def login(self, username=None, password=None, sleep=False):
"""Execute Skybell login."""
if username is not None:
self._username = username
Expand All @@ -85,6 +88,8 @@ def login(self, username=None, password=None):
CONST.ACCESS_TOKEN: None
})

self._session = requests.session()

login_data = {
'username': self._username,
'password': self._password,
Expand All @@ -105,7 +110,11 @@ def login(self, username=None, password=None):
self.update_cache({
CONST.ACCESS_TOKEN: response_object[CONST.ACCESS_TOKEN]})

_LOGGER.info("Login successful")
if self._login_sleep:
_LOGGER.info("Login successful, waiting 5 seconds...")
time.sleep(5)
else:
_LOGGER.info("Login successful")

return True

Expand Down Expand Up @@ -173,8 +182,6 @@ def send_request(self, method, url, headers=None,
headers['Authorization'] = 'Bearer ' + \
self.cache(CONST.ACCESS_TOKEN)

_LOGGER.info("User-Agent: %s", self._user_agent)

headers['user-agent'] = self._user_agent
headers['content-type'] = 'application/json'
headers['accepts'] = '*/*'
Expand Down
2 changes: 1 addition & 1 deletion skybellpy/helpers/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

MAJOR_VERSION = 0
MINOR_VERSION = 6
PATCH_VERSION = '0'
PATCH_VERSION = '1'

__version__ = '{}.{}.{}'.format(MAJOR_VERSION, MINOR_VERSION, PATCH_VERSION)

Expand Down
3 changes: 2 additions & 1 deletion tests/test_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ def setUp(self):
"""Set up Skybell module."""
self.skybell = skybellpy.Skybell(username=USERNAME,
password=PASSWORD,
disable_cache=True)
disable_cache=True,
login_sleep=False)

def tearDown(self):
"""Clean up after test."""
Expand Down
20 changes: 13 additions & 7 deletions tests/test_skybell.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ class TestSkybell(unittest.TestCase):

def setUp(self):
"""Set up Skybell module."""
self.skybell_no_cred = skybellpy.Skybell()
self.skybell_no_cred = skybellpy.Skybell(login_sleep=False)
self.skybell = skybellpy.Skybell(username=USERNAME,
password=PASSWORD,
disable_cache=True)
disable_cache=True,
login_sleep=False)

def tearDown(self):
"""Clean up after test."""
Expand Down Expand Up @@ -81,7 +82,8 @@ def tests_auto_login(self, m):
password='buzz',
auto_login=True,
get_devices=False,
disable_cache=True)
disable_cache=True,
login_sleep=False)

# pylint: disable=W0212
self.assertEqual(skybell._username, 'fizz')
Expand All @@ -105,7 +107,8 @@ def tests_auto_fetch(self, m):
skybell = skybellpy.Skybell(username='fizz',
password='buzz',
get_devices=True,
disable_cache=True)
disable_cache=True,
login_sleep=False)

# pylint: disable=W0212
self.assertEqual(skybell._username, 'fizz')
Expand Down Expand Up @@ -231,7 +234,8 @@ def tests_cookies(self, m):
skybell = skybellpy.Skybell(username='fizz',
password='buzz',
auto_login=False,
cache_path=cache_path)
cache_path=cache_path,
login_sleep=False)

# Test that our cookies are fully realized prior to login
# pylint: disable=W0212
Expand Down Expand Up @@ -265,7 +269,8 @@ def tests_cookies(self, m):
skybell = skybellpy.Skybell(username='fizz',
password='buzz',
auto_login=False,
cache_path=cache_path)
cache_path=cache_path,
login_sleep=False)

# Test that the cookie data is the same
self.assertEqual(skybell._cache['app_id'],
Expand Down Expand Up @@ -301,7 +306,8 @@ def test_empty_cookies(self, m):
empty_skybell = skybellpy.Skybell(username='fizz',
password='buzz',
auto_login=False,
cache_path=empty_cache_path)
cache_path=empty_cache_path,
login_sleep=False)

# Test that our cookies are fully realized prior to login
# pylint: disable=W0212
Expand Down

0 comments on commit 94d0bc4

Please sign in to comment.