Updated headers to include user-agent, removed extra data at login
This commit is contained in:
+9
-6
@@ -3,7 +3,7 @@
|
|||||||
import logging
|
import logging
|
||||||
from json import dumps
|
from json import dumps
|
||||||
from blinkpy.helpers.util import get_time, Throttle
|
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__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -20,21 +20,24 @@ def request_login(
|
|||||||
:param url: Login url.
|
:param url: Login url.
|
||||||
:login_data: Dictionary containing blink login data.
|
: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(
|
data = dumps(
|
||||||
{
|
{
|
||||||
"email": login_data["username"],
|
"email": login_data["username"],
|
||||||
"password": login_data["password"],
|
"password": login_data["password"],
|
||||||
"notification_key": login_data["notification_key"],
|
"notification_key": login_data["notification_key"],
|
||||||
"unique_id": login_data["uid"],
|
"unique_id": login_data["uid"],
|
||||||
"app_version": "6.0.12",
|
|
||||||
"device_identifier": login_data["device_id"],
|
"device_identifier": login_data["device_id"],
|
||||||
"client_name": "Computer",
|
"client_name": "Computer",
|
||||||
"client_type": "android",
|
"reauth": "false",
|
||||||
"os_version": "5.1.1",
|
|
||||||
"reauth": "true",
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
return auth.query(
|
return auth.query(
|
||||||
url=url,
|
url=url,
|
||||||
headers=headers,
|
headers=headers,
|
||||||
|
|||||||
+9
-5
@@ -108,11 +108,7 @@ class Auth:
|
|||||||
try:
|
try:
|
||||||
_LOGGER.info("Token expired, attempting automatic refresh.")
|
_LOGGER.info("Token expired, attempting automatic refresh.")
|
||||||
self.login_response = self.login()
|
self.login_response = self.login()
|
||||||
self.region_id = self.login_response["region"]["tier"]
|
self.extract_login_info()
|
||||||
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.is_errored = False
|
self.is_errored = False
|
||||||
except LoginError:
|
except LoginError:
|
||||||
_LOGGER.error("Login endpoint failed. Try again later.")
|
_LOGGER.error("Login endpoint failed. Try again later.")
|
||||||
@@ -122,6 +118,14 @@ class Auth:
|
|||||||
raise TokenRefreshFailed
|
raise TokenRefreshFailed
|
||||||
return True
|
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):
|
def startup(self):
|
||||||
"""Initialize tokens for communication."""
|
"""Initialize tokens for communication."""
|
||||||
self.validate_login()
|
self.validate_login()
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import os
|
|||||||
|
|
||||||
MAJOR_VERSION = 0
|
MAJOR_VERSION = 0
|
||||||
MINOR_VERSION = 16
|
MINOR_VERSION = 16
|
||||||
PATCH_VERSION = "2-rc0"
|
PATCH_VERSION = "2-rc1"
|
||||||
|
|
||||||
__version__ = f"{MAJOR_VERSION}.{MINOR_VERSION}.{PATCH_VERSION}"
|
__version__ = f"{MAJOR_VERSION}.{MINOR_VERSION}.{PATCH_VERSION}"
|
||||||
|
|
||||||
@@ -58,6 +58,7 @@ ONLINE = {"online": True, "offline": False}
|
|||||||
"""
|
"""
|
||||||
OTHER
|
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"
|
DEVICE_ID = "Blinkpy"
|
||||||
TIMESTAMP_FORMAT = "%Y-%m-%dT%H:%M:%S%z"
|
TIMESTAMP_FORMAT = "%Y-%m-%dT%H:%M:%S%z"
|
||||||
DEFAULT_MOTION_INTERVAL = 1
|
DEFAULT_MOTION_INTERVAL = 1
|
||||||
|
|||||||
Reference in New Issue
Block a user