Skip to content

Commit 0fc74c3

Browse files
authored
Merge pull request #319 from fronzbot/login-fix
Changed the way the new login method switch is handled
2 parents f8db8eb + 7b150eb commit 0fc74c3

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

blinkpy/auth.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def __init__(self, login_data=None, no_prompt=False, login_method="v4"):
3232
self.region_id = login_data.get("region_id", None)
3333
self.client_id = login_data.get("client_id", None)
3434
self.account_id = login_data.get("account_id", None)
35-
self.login_url = LOGIN_ENDPOINT[login_method]
35+
self.login_method = login_method
3636
self.login_response = None
3737
self.is_errored = False
3838
self.no_prompt = no_prompt
@@ -55,6 +55,13 @@ def header(self):
5555
return None
5656
return {"Host": self.host, "TOKEN_AUTH": self.token}
5757

58+
@property
59+
def login_url(self):
60+
"""Return login url."""
61+
if self.login_method not in LOGIN_ENDPOINT:
62+
return LOGIN_ENDPOINT["v4"]
63+
return LOGIN_ENDPOINT[self.login_method]
64+
5865
def create_session(self):
5966
"""Create a session for blink communication."""
6067
sess = Session()

blinkpy/helpers/constants.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
MAJOR_VERSION = 0
66
MINOR_VERSION = 16
7-
PATCH_VERSION = "0-rc9"
7+
PATCH_VERSION = "0-rc10"
88

99
__version__ = f"{MAJOR_VERSION}.{MINOR_VERSION}.{PATCH_VERSION}"
1010

tests/test_auth.py

+9
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,15 @@ def test_query_retry_failed(self, mock_refresh, mock_validate):
254254
mock_validate.side_effect = [UnauthorizedError, TokenRefreshFailed]
255255
self.assertEqual(self.auth.query(url="http://example.com"), None)
256256

257+
def test_login_methods(self):
258+
"""Test correct login url returned."""
259+
auth = Auth()
260+
self.assertEqual(auth.login_url, const.LOGIN_ENDPOINT["v4"])
261+
auth.login_method = "v3"
262+
self.assertEqual(auth.login_url, const.LOGIN_ENDPOINT["v3"])
263+
auth.login_method = "foobar"
264+
self.assertEqual(auth.login_url, const.LOGIN_ENDPOINT["v4"])
265+
257266

258267
class MockSession:
259268
"""Object to mock a session."""

0 commit comments

Comments
 (0)