diff --git a/CHANGES.rst b/CHANGES.rst index 1671b96e..224ff61e 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -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 diff --git a/blinkpy/api.py b/blinkpy/api.py index 93d3ab3a..642e8af0 100644 --- a/blinkpy/api.py +++ b/blinkpy/api.py @@ -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__) @@ -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, diff --git a/blinkpy/auth.py b/blinkpy/auth.py index 59950da4..b3d6fe07 100644 --- a/blinkpy/auth.py +++ b/blinkpy/auth.py @@ -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.") @@ -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() diff --git a/blinkpy/helpers/constants.py b/blinkpy/helpers/constants.py index 80fa202a..9702acbf 100644 --- a/blinkpy/helpers/constants.py +++ b/blinkpy/helpers/constants.py @@ -4,7 +4,7 @@ MAJOR_VERSION = 0 MINOR_VERSION = 16 -PATCH_VERSION = 1 +PATCH_VERSION = 2 __version__ = f"{MAJOR_VERSION}.{MINOR_VERSION}.{PATCH_VERSION}" @@ -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 diff --git a/requirements_test.txt b/requirements_test.txt index 7a1acc25..b0f58b02 100644 --- a/requirements_test.txt +++ b/requirements_test.txt @@ -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