예제 #1
0
 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
예제 #2
0
 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
예제 #3
0
    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
예제 #4
0
    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
예제 #5
0
    def get_auth_token(self, is_retry=False):
        """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)

        self.login_urls = [LOGIN_URL, OLD_LOGIN_URL, LOGIN_BACKUP_URL]

        response = self.login_request(is_retry=is_retry)

        if not response:
            return False

        self._host = "{}.{}".format(self.region_id, BLINK_URL)
        self._token = response['authtoken']['authtoken']
        self.networks = response['networks']

        self._auth_header = {'Host': self._host, 'TOKEN_AUTH': self._token}
        self.urls = BlinkURLHandler(self.region_id, legacy=self.legacy)

        return self._auth_header
예제 #6
0
    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)
예제 #7
0
파일: test_util.py 프로젝트: ohaak/blinkpy
 def test_legacy_subdomains(self):
     """Test that subdomain can be set to legacy mode."""
     urls = BlinkURLHandler('test')
     self.assertEqual(urls.subdomain, 'rest-test')
     urls = BlinkURLHandler('test', legacy=True)
     self.assertEqual(urls.subdomain, 'rest.test')
예제 #8
0
 def setUp(self):
     """Set up Blink module."""
     self.blink = blinkpy.Blink()
     self.blink.urls = BlinkURLHandler("test")