diff --git a/blinkpy/blinkpy.py b/blinkpy/blinkpy.py index 0e4569f..cf6dcb6 100644 --- a/blinkpy/blinkpy.py +++ b/blinkpy/blinkpy.py @@ -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 diff --git a/blinkpy/helpers/util.py b/blinkpy/helpers/util.py index 2d0e1c8..165c3fa 100644 --- a/blinkpy/helpers/util.py +++ b/blinkpy/helpers/util.py @@ -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) diff --git a/tests/test_util.py b/tests/test_util.py index f75cf76..21524bf 100644 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -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')