From c8eb8321df6ff3c453a8b8a5fbd2685a85d58ed5 Mon Sep 17 00:00:00 2001 From: Malte Franken Date: Mon, 14 Oct 2019 21:50:51 +1100 Subject: [PATCH 1/3] move imports to top-level --- homeassistant/components/darksky/sensor.py | 3 +-- homeassistant/components/darksky/weather.py | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/darksky/sensor.py b/homeassistant/components/darksky/sensor.py index d4e7e7ec63a97c..cd8417e3e8467b 100644 --- a/homeassistant/components/darksky/sensor.py +++ b/homeassistant/components/darksky/sensor.py @@ -2,6 +2,7 @@ import logging from datetime import timedelta +import forecastio import voluptuous as vol from requests.exceptions import ConnectionError as ConnectError, HTTPError, Timeout @@ -797,8 +798,6 @@ def __init__(self, api_key, latitude, longitude, units, language, interval): def _update(self): """Get the latest data from Dark Sky.""" - import forecastio - try: self.data = forecastio.load_forecast( self._api_key, diff --git a/homeassistant/components/darksky/weather.py b/homeassistant/components/darksky/weather.py index dc5708d12a0cbe..41f063399c1a3e 100644 --- a/homeassistant/components/darksky/weather.py +++ b/homeassistant/components/darksky/weather.py @@ -2,6 +2,7 @@ from datetime import timedelta import logging +import forecastio from requests.exceptions import ConnectionError as ConnectError, HTTPError, Timeout import voluptuous as vol @@ -244,8 +245,6 @@ def __init__(self, api_key, latitude, longitude, units): @Throttle(MIN_TIME_BETWEEN_UPDATES) def update(self): """Get the latest data from Dark Sky.""" - import forecastio - try: self.data = forecastio.load_forecast( self._api_key, self.latitude, self.longitude, units=self.requested_units From 62aa6ab349001270d6d3ee8cbd1c0977b70e06e9 Mon Sep 17 00:00:00 2001 From: Malte Franken Date: Mon, 14 Oct 2019 21:52:31 +1100 Subject: [PATCH 2/3] modify patch path --- tests/components/darksky/test_sensor.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/tests/components/darksky/test_sensor.py b/tests/components/darksky/test_sensor.py index 23d16ed35f480e..de4c4aca3e99c3 100644 --- a/tests/components/darksky/test_sensor.py +++ b/tests/components/darksky/test_sensor.py @@ -112,7 +112,10 @@ def tearDown(self): # pylint: disable=invalid-name self.hass.stop() @MockDependency("forecastio") - @patch("forecastio.load_forecast", new=load_forecastMock) + @patch( + "homeassistant.components.darksky.sensor.forecastio.load_forecast", + new=load_forecastMock, + ) def test_setup_with_config(self, mock_forecastio): """Test the platform setup with configuration.""" setup_component(self.hass, "sensor", VALID_CONFIG_MINIMAL) @@ -130,7 +133,10 @@ def test_setup_with_invalid_config(self, mock_forecastio): assert state is None @MockDependency("forecastio") - @patch("forecastio.load_forecast", new=load_forecastMock) + @patch( + "homeassistant.components.darksky.sensor.forecastio.load_forecast", + new=load_forecastMock, + ) def test_setup_with_language_config(self, mock_forecastio): """Test the platform setup with language configuration.""" setup_component(self.hass, "sensor", VALID_CONFIG_LANG_DE) @@ -164,7 +170,10 @@ def test_setup_bad_api_key(self, mock_get_forecast): assert not response @MockDependency("forecastio") - @patch("forecastio.load_forecast", new=load_forecastMock) + @patch( + "homeassistant.components.darksky.sensor.forecastio.load_forecast", + new=load_forecastMock, + ) def test_setup_with_alerts_config(self, mock_forecastio): """Test the platform setup with alert configuration.""" setup_component(self.hass, "sensor", VALID_CONFIG_ALERTS) From 8bf632d654bfe463296d50ca277d0ba2da1ff313 Mon Sep 17 00:00:00 2001 From: Malte Franken Date: Mon, 14 Oct 2019 21:53:33 +1100 Subject: [PATCH 3/3] removed unused mocks and patches --- tests/components/darksky/test_sensor.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/tests/components/darksky/test_sensor.py b/tests/components/darksky/test_sensor.py index de4c4aca3e99c3..be66b74c186d3d 100644 --- a/tests/components/darksky/test_sensor.py +++ b/tests/components/darksky/test_sensor.py @@ -123,9 +123,7 @@ def test_setup_with_config(self, mock_forecastio): state = self.hass.states.get("sensor.dark_sky_summary") assert state is not None - @MockDependency("forecastio") - @patch("forecastio.load_forecast", new=load_forecastMock) - def test_setup_with_invalid_config(self, mock_forecastio): + def test_setup_with_invalid_config(self): """Test the platform setup with invalid configuration.""" setup_component(self.hass, "sensor", INVALID_CONFIG_MINIMAL) @@ -144,9 +142,7 @@ def test_setup_with_language_config(self, mock_forecastio): state = self.hass.states.get("sensor.dark_sky_summary") assert state is not None - @MockDependency("forecastio") - @patch("forecastio.load_forecast", new=load_forecastMock) - def test_setup_with_invalid_language_config(self, mock_forecastio): + def test_setup_with_invalid_language_config(self): """Test the platform setup with language configuration.""" setup_component(self.hass, "sensor", INVALID_CONFIG_LANG)