diff --git a/blinkpy/api.py b/blinkpy/api.py index 8f99e08..c850a2b 100644 --- a/blinkpy/api.py +++ b/blinkpy/api.py @@ -12,7 +12,14 @@ MIN_THROTTLE_TIME = 2 def request_login( - blink, url, username, password, notification_key, uid, is_retry=False + blink, + url, + username, + password, + notification_key, + uid, + is_retry=False, + device_id="Blinkpy", ): """ Login request. @@ -24,6 +31,7 @@ def request_login( :param notification_key: Randomly genereated key. :param uid: Randomly generated unique id key. :param is_retry: Is this part of a re-authorization attempt? + :param device_id: Name of application to send at login. """ headers = {"Host": DEFAULT_URL, "Content-Type": "application/json"} data = dumps( @@ -35,7 +43,7 @@ def request_login( "app_version": "6.0.7 (520300) #afb0be72a", "client_name": "Computer", "client_type": "android", - "device_identifier": "Blinkpy", + "device_identifier": device_id, "device_name": "Blinkpy", "os_version": "5.1.1", "reauth": "true", diff --git a/blinkpy/blinkpy.py b/blinkpy/blinkpy.py index 93befba..4809114 100644 --- a/blinkpy/blinkpy.py +++ b/blinkpy/blinkpy.py @@ -58,6 +58,7 @@ class Blink: legacy_subdomain=False, no_prompt=False, persist_key=None, + device_id="Blinkpy", ): """ Initialize Blink system. @@ -71,21 +72,26 @@ class Blink: :param refresh_rate: Refresh rate of blink information. Defaults to 15 (seconds) :param motion_interval: How far back to register motion in minutes. - Defaults to last refresh time. - Useful for preventing motion_detected property - from de-asserting too quickly. + Defaults to last refresh time. + Useful for preventing motion_detected property + from de-asserting too quickly. :param legacy_subdomain: Set to TRUE to use old 'rest.region' - endpoints (only use if you are having - api issues). + endpoints (only use if you are having + api issues). :param no_prompt: Set to TRUE if using an implementation that needs to - suppress command-line output. + suppress command-line output. :param persist_key: Location of persistant identifier. + :param device_id: Identifier for the application. Default is 'Blinkpy'. + This is used when logging in and should be changed to + fit the implementation (ie. "Home Assistant" in a + Home Assistant integration). """ self.login_handler = LoginHandler( username=username, password=password, cred_file=cred_file, persist_key=persist_key, + device_id=device_id, ) self._token = None self._auth_header = None @@ -151,6 +157,8 @@ class Blink: sync_module.start() self.sync[network_name] = sync_module self.cameras = self.merge_cameras() + self.available = self.refresh() + self.key_required = False def login(self): """Perform server login. DEPRECATED.""" @@ -163,6 +171,7 @@ class Blink: """Retrieve the authentication token from Blink.""" self.login_response = self.login_handler.login(self) if not self.login_response: + self.available = False return False self.setup_params(self.login_response) if self.login_handler.check_key_required(self): diff --git a/blinkpy/login_handler.py b/blinkpy/login_handler.py index 8041cef..2e978f7 100644 --- a/blinkpy/login_handler.py +++ b/blinkpy/login_handler.py @@ -13,7 +13,14 @@ _LOGGER = logging.getLogger(__name__) class LoginHandler: """Class to handle login communication.""" - def __init__(self, username=None, password=None, cred_file=None, persist_key=None): + def __init__( + self, + username=None, + password=None, + cred_file=None, + persist_key=None, + device_id="Blinkpy", + ): """ Initialize login handler. @@ -21,11 +28,13 @@ class LoginHandler: :param password: Blink password :param cred_file: JSON formatted credential file. :param persist_key: File location of persistant key. + :param device_id: Name of application to send at login. """ self.login_url = None self.login_urls = const.LOGIN_URLS self.cred_file = cred_file self.persist_key = persist_key + self.device_id = device_id self.data = { "username": username, "password": password, @@ -113,6 +122,7 @@ class LoginHandler: self.data["notification_key"], self.data["uid"], is_retry=False, + device_id=self.device_id, ) if self.validate_response(url, response): diff --git a/codecov.yml b/codecov.yml index aeade5e..abe7a21 100644 --- a/codecov.yml +++ b/codecov.yml @@ -4,7 +4,7 @@ coverage: status: project: default: - threshold: "2%" + threshold: 2% comment: true require_ci_to_pass: yes