Add legacy flag to be able to use old 'rest.region' subdomain

This commit is contained in:
Kevin Fronczak
2019-05-20 21:15:08 -04:00
parent 130aa8382a
commit cf65648293
3 changed files with 19 additions and 5 deletions
+6 -2
View File
@@ -45,7 +45,7 @@ class Blink():
"""Class to initialize communication."""
def __init__(self, username=None, password=None,
refresh_rate=REFRESH_RATE):
refresh_rate=REFRESH_RATE, legacy_subdomain=False):
"""
Initialize Blink system.
@@ -53,6 +53,9 @@ class Blink():
:param password: Blink password
:param refresh_rate: Refresh rate of blink information.
Defaults to 15 (seconds)
: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
@@ -73,6 +76,7 @@ class Blink():
self.video_list = CaseInsensitiveDict({})
self._login_url = LOGIN_URL
self.version = __version__
self.legacy = legacy_subdomain
@property
def auth_header(self):
@@ -136,7 +140,7 @@ class Blink():
self._auth_header = {'Host': self._host,
'TOKEN_AUTH': self._token}
self.urls = BlinkURLHandler(self.region_id)
self.urls = BlinkURLHandler(self.region_id, legacy=self.legacy)
return self._auth_header
+5 -2
View File
@@ -111,9 +111,12 @@ class BlinkAuthenticationException(BlinkException):
class BlinkURLHandler():
"""Class that handles Blink URLS."""
def __init__(self, region_id):
def __init__(self, region_id, legacy=False):
"""Initialize the urls."""
self.base_url = "https://rest-{}.{}".format(region_id, BLINK_URL)
self.subdomain = 'rest-{}'.format(region_id)
if legacy:
self.subdomain = 'rest.{}'.format(region_id)
self.base_url = "https://{}.{}".format(self.subdomain, BLINK_URL)
self.home_url = "{}/homescreen".format(self.base_url)
self.event_url = "{}/events/network".format(self.base_url)
self.network_url = "{}/network".format(self.base_url)
+8 -1
View File
@@ -3,7 +3,7 @@
import unittest
from unittest import mock
import time
from blinkpy.helpers.util import Throttle
from blinkpy.helpers.util import Throttle, BlinkURLHandler
class TestUtil(unittest.TestCase):
@@ -98,3 +98,10 @@ class TestUtil(unittest.TestCase):
with mock.patch('time.time', return_value=now_plus_6):
self.assertEqual(tester.test1(), None)
self.assertEqual(tester.test2(), True)
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')