def test_bad_request(self, mock_sess): """Check that we raise an Exception with a bad request.""" self.blink.session = create_session() explog = ("WARNING:blinkpy.helpers.util:" "Response from server: 200 - foo") with self.assertRaises(BlinkException): http_req(self.blink, reqtype='bad') with self.assertLogs() as logrecord: http_req(self.blink, reqtype='post', is_retry=True) self.assertEqual(logrecord.output, [explog])
def __init__(self, username=None, password=None, cred_file=None, refresh_rate=DEFAULT_REFRESH, motion_interval=DEFAULT_MOTION_INTERVAL, legacy_subdomain=False): """ Initialize Blink system. :param username: Blink username (usually email address) :param password: Blink password :param cred_file: JSON formatted file to store credentials. If username and password are given, file is ignored. Otherwise, username and password are loaded from file. :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. :param legacy_subdomain: Set to TRUE to use old 'rest.region' endpoints (only use if you are having api issues). """ self._username = username self._password = password self._cred_file = cred_file self._token = None self._auth_header = None self._host = None self.account_id = None self.network_ids = [] self.urls = None self.sync = CaseInsensitiveDict({}) self.region = None self.region_id = None self.last_refresh = None self.refresh_rate = refresh_rate self.session = create_session() self.networks = [] self.cameras = CaseInsensitiveDict({}) self.video_list = CaseInsensitiveDict({}) self._login_url = LOGIN_URL self.login_urls = [] self.motion_interval = motion_interval self.version = __version__ self.legacy = legacy_subdomain
def setUp(self): """Set up Blink module.""" self.blink = blinkpy.Blink(username=USERNAME, password=PASSWORD) header = { 'Host': 'abc.zxc', 'TOKEN_AUTH': mresp.LOGIN_RESPONSE['authtoken']['authtoken'] } # pylint: disable=protected-access self.blink._auth_header = header self.blink.session = create_session() self.blink.urls = BlinkURLHandler('test') self.blink.sync['test'] = BlinkSyncModule(self.blink, 'test', 1234, []) self.camera = BlinkCamera(self.blink.sync['test']) self.camera.name = 'foobar' self.blink.sync['test'].cameras['foobar'] = self.camera
def setUp(self): """Set up Blink module.""" self.blink = blinkpy.Blink(username=USERNAME, password=PASSWORD) header = { "Host": "abc.zxc", "TOKEN_AUTH": mresp.LOGIN_RESPONSE["authtoken"]["authtoken"], } # pylint: disable=protected-access self.blink._auth_header = header self.blink.session = create_session() self.blink.urls = BlinkURLHandler("test") self.blink.sync["test"] = BlinkSyncModule(self.blink, "test", 1234, []) self.camera = BlinkCamera(self.blink.sync["test"]) self.camera.name = "foobar" self.blink.sync["test"].cameras["foobar"] = self.camera
def get_auth_token(self): """Retrieve the authentication token from Blink.""" if not isinstance(self._username, str): raise BlinkAuthenticationException(ERROR.USERNAME) if not isinstance(self._password, str): raise BlinkAuthenticationException(ERROR.PASSWORD) headers = {'Host': DEFAULT_URL, 'Content-Type': 'application/json'} data = json.dumps({ "email": self._username, "password": self._password, "client_specifier": "iPhone 9.2 | 2.2 | 222" }) self.session = create_session() response = http_req(self, url=self._login_url, headers=headers, data=data, json_resp=False, reqtype='post') if response.status_code == 200: response = response.json() (self.region_id, self.region), = response['region'].items() else: _LOGGER.debug(("Received response code %s " "when authenticating, " "trying new url"), response.status_code) self._login_url = LOGIN_BACKUP_URL response = http_req(self, url=self._login_url, headers=headers, data=data, reqtype='post') self.region_id = 'piri' self.region = "UNKNOWN" self._host = "{}.{}".format(self.region_id, BLINK_URL) self._token = response['authtoken']['authtoken'] self._auth_header = {'Host': self._host, 'TOKEN_AUTH': self._token} self.urls = BlinkURLHandler(self.region_id) return self._auth_header
def get_auth_token(self): """Retrieve the authentication token from Blink.""" if not isinstance(self._username, str): raise BlinkAuthenticationException(ERROR.USERNAME) if not isinstance(self._password, str): raise BlinkAuthenticationException(ERROR.PASSWORD) login_url = LOGIN_URL self.session = create_session() response = api.request_login(self, login_url, self._username, self._password) if response.status_code == 200: response = response.json() (self.region_id, self.region), = response['region'].items() else: _LOGGER.debug( ("Received response code %s " "when authenticating, " "trying new url"), response.status_code ) login_url = LOGIN_BACKUP_URL response = api.request_login(self, login_url, self._username, self._password) self.region_id = 'piri' self.region = "UNKNOWN" self._host = "{}.{}".format(self.region_id, BLINK_URL) self._token = response['authtoken']['authtoken'] self._auth_header = {'Host': self._host, 'TOKEN_AUTH': self._token} self.networks = response['networks'] self.urls = BlinkURLHandler(self.region_id) self._login_url = login_url return self._auth_header
def setUp(self): """Set up Blink module.""" self.blink = blinkpy.Blink(username=USERNAME, password=PASSWORD) self.camera_config = { 'device_id': 1111, 'name': 'foobar', 'armed': False, 'active': 'disarmed', 'thumbnail': '/test/image', 'video': '/test/clip/clip.mp4', 'temp': 70, 'battery': 3, 'notifications': 2, 'region_id': 'test' } header = { 'Host': 'abc.zxc', 'TOKEN_AUTH': mresp.LOGIN_RESPONSE['authtoken']['authtoken'] } self.blink.session = create_session() self.blink.urls = BlinkURLHandler('test') self.blink.network_id = '0000' self.sync = BlinkSyncModule(self.blink, header, self.blink.urls)
def __init__( self, username=None, password=None, cred_file=None, refresh_rate=DEFAULT_REFRESH, motion_interval=DEFAULT_MOTION_INTERVAL, legacy_subdomain=False, no_prompt=False, persist_key=None, device_id="Blinkpy", ): """ Initialize Blink system. :param username: Blink username (usually email address) :param password: Blink password :param cred_file: JSON formatted file to store credentials. If username and password are given, file is ignored. Otherwise, username and password are loaded from file. :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. :param legacy_subdomain: Set to TRUE to use old 'rest.region' 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. :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 self._host = None self.account_id = None self.client_id = None self.network_ids = [] self.urls = None self.sync = CaseInsensitiveDict({}) self.region = None self.region_id = None self.last_refresh = None self.refresh_rate = refresh_rate self.session = create_session() self.networks = [] self.cameras = CaseInsensitiveDict({}) self.video_list = CaseInsensitiveDict({}) self.login_url = LOGIN_URLS[0] self.login_urls = [] self.motion_interval = motion_interval self.version = __version__ self.legacy = legacy_subdomain self.no_prompt = no_prompt self.available = False self.key_required = False self.login_response = {}
def setUp(self): """Initialize the blink module.""" self.blink = Blink() self.blink.session = create_session() # pylint: disable=protected-access self.blink._auth_header = {}