From 2f907696f30bfd15ae6372a2238f4339d62367f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20H=C3=B8yer=20Iversen?= Date: Wed, 4 Jan 2017 23:20:30 +0100 Subject: [PATCH] =?UTF-8?q?[WIP]=20Spread=20the=20traffic=20to=20yr.no=20s?= =?UTF-8?q?ervers=20and=20remove=20yr.no=20from=20the=20default=E2=80=A6?= =?UTF-8?q?=20(#5171)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Spread the traffic to yr.no servers and remove yr.no from the default config * use unique address for yr.no * update yr tests * Wait 10 min extra before requesting new data * Update config.py * Update yr.py --- homeassistant/components/sensor/yr.py | 8 +++++--- tests/components/sensor/test_yr.py | 6 ++++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/homeassistant/components/sensor/yr.py b/homeassistant/components/sensor/yr.py index ef12ba392e1..7da72b6fd38 100644 --- a/homeassistant/components/sensor/yr.py +++ b/homeassistant/components/sensor/yr.py @@ -82,8 +82,9 @@ def async_setup_platform(hass, config, async_add_devices, discovery_info=None): weather = YrData(hass, coordinates, dev) # Update weather on the hour, spread seconds - async_track_utc_time_change(hass, weather.async_update, minute=0, - second=randrange(5, 25)) + async_track_utc_time_change(hass, weather.async_update, + minute=randrange(1, 10), + second=randrange(0, 59)) yield from weather.async_update() @@ -139,7 +140,8 @@ class YrData(object): def __init__(self, hass, coordinates, devices): """Initialize the data object.""" - self._url = 'http://api.yr.no/weatherapi/locationforecast/1.9/' + self._url = 'https://aa015h6buqvih86i1.api.met.no/'\ + 'weatherapi/locationforecast/1.9/' self._urlparams = coordinates self._nextrun = None self.devices = devices diff --git a/tests/components/sensor/test_yr.py b/tests/components/sensor/test_yr.py index 8d54037a379..d0504db963c 100644 --- a/tests/components/sensor/test_yr.py +++ b/tests/components/sensor/test_yr.py @@ -14,7 +14,8 @@ NOW = datetime(2016, 6, 9, 1, tzinfo=dt_util.UTC) @asyncio.coroutine def test_default_setup(hass, aioclient_mock): """Test the default setup.""" - aioclient_mock.get('http://api.yr.no/weatherapi/locationforecast/1.9/', + aioclient_mock.get('https://aa015h6buqvih86i1.api.met.no/' + 'weatherapi/locationforecast/1.9/', text=load_fixture('yr.no.json')) config = {'platform': 'yr', 'elevation': 0} @@ -32,7 +33,8 @@ def test_default_setup(hass, aioclient_mock): @asyncio.coroutine def test_custom_setup(hass, aioclient_mock): """Test a custom setup.""" - aioclient_mock.get('http://api.yr.no/weatherapi/locationforecast/1.9/', + aioclient_mock.get('https://aa015h6buqvih86i1.api.met.no/' + 'weatherapi/locationforecast/1.9/', text=load_fixture('yr.no.json')) config = {'platform': 'yr',