Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions homeassistant/components/darksky/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions homeassistant/components/darksky/weather.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
23 changes: 14 additions & 9 deletions tests/components/darksky/test_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,35 +112,37 @@ 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)

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)

state = self.hass.states.get("sensor.dark_sky_summary")
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)

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)

Expand All @@ -164,7 +166,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)
Expand Down