Skip to content

Commit

Permalink
Merge pull request #359 from fronzbot/dev
Browse files Browse the repository at this point in the history
0.16.2
  • Loading branch information
fronzbot authored Aug 2, 2020
2 parents f6ddfbe + 1790c1b commit 6bd8d14
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 13 deletions.
10 changes: 9 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,18 @@ Changelog

A list of changes between each release

0.16.2 (2020-08-01)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

- Add user-agent to header at login
- Remove extra data parameters at login (not-needed)
- Bump pytest to 6.0.1


0.16.1 (2020-07-29)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

- Unpin requeirements, set minimum version instead
- Unpin requirements, set minimum version instead
- Bump coverage to 5.2.1
- Bump pytest to 6.0.0

Expand Down
13 changes: 8 additions & 5 deletions blinkpy/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import logging
from json import dumps
from blinkpy.helpers.util import get_time, Throttle
from blinkpy.helpers.constants import DEFAULT_URL, TIMEOUT
from blinkpy.helpers.constants import DEFAULT_URL, TIMEOUT, DEFAULT_USER_AGENT

_LOGGER = logging.getLogger(__name__)

Expand All @@ -20,21 +20,24 @@ def request_login(
:param url: Login url.
:login_data: Dictionary containing blink login data.
"""
headers = {"Host": DEFAULT_URL, "Content-Type": "application/json"}
headers = {
"Host": DEFAULT_URL,
"Content-Type": "application/json",
"Accept": "/",
"user-agent": DEFAULT_USER_AGENT,
}
data = dumps(
{
"email": login_data["username"],
"password": login_data["password"],
"notification_key": login_data["notification_key"],
"unique_id": login_data["uid"],
"app_version": "6.0.7 (520300) #afb0be72a",
"device_identifier": login_data["device_id"],
"client_name": "Computer",
"client_type": "android",
"os_version": "5.1.1",
"reauth": "false",
}
)

return auth.query(
url=url,
headers=headers,
Expand Down
14 changes: 9 additions & 5 deletions blinkpy/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,7 @@ def refresh_token(self):
try:
_LOGGER.info("Token expired, attempting automatic refresh.")
self.login_response = self.login()
self.region_id = self.login_response["region"]["tier"]
self.host = f"{self.region_id}.{BLINK_URL}"
self.token = self.login_response["authtoken"]["authtoken"]
self.client_id = self.login_response["client"]["id"]
self.account_id = self.login_response["account"]["id"]
self.extract_login_info()
self.is_errored = False
except LoginError:
_LOGGER.error("Login endpoint failed. Try again later.")
Expand All @@ -122,6 +118,14 @@ def refresh_token(self):
raise TokenRefreshFailed
return True

def extract_login_info(self):
"""Extract login info from login response."""
self.region_id = self.login_response["region"]["tier"]
self.host = f"{self.region_id}.{BLINK_URL}"
self.token = self.login_response["authtoken"]["authtoken"]
self.client_id = self.login_response["client"]["id"]
self.account_id = self.login_response["account"]["id"]

def startup(self):
"""Initialize tokens for communication."""
self.validate_login()
Expand Down
3 changes: 2 additions & 1 deletion blinkpy/helpers/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

MAJOR_VERSION = 0
MINOR_VERSION = 16
PATCH_VERSION = 1
PATCH_VERSION = 2

__version__ = f"{MAJOR_VERSION}.{MINOR_VERSION}.{PATCH_VERSION}"

Expand Down Expand Up @@ -58,6 +58,7 @@
"""
OTHER
"""
DEFAULT_USER_AGENT = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36"
DEVICE_ID = "Blinkpy"
TIMESTAMP_FORMAT = "%Y-%m-%dT%H:%M:%S%z"
DEFAULT_MOTION_INTERVAL = 1
Expand Down
2 changes: 1 addition & 1 deletion requirements_test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ flake8-docstrings==1.5.0
pre-commit==2.6.0
pylint==2.5.3
pydocstyle==5.0.2
pytest==6.0.0
pytest==6.0.1
pytest-cov==2.10.0
pytest-sugar==0.9.4
pytest-timeout==1.4.2
Expand Down

0 comments on commit 6bd8d14

Please sign in to comment.