Remove Yahoo Weather integration (#34501)
This commit is contained in:
1 parent
5f2a9ed965
commit
220baed33a
9 files changed
-801
No files matched your search
@@ -1 +0,0 @@
|
||||
"""Tests for the yweather component."""
|
||||
@@ -1,229 +0,0 @@
|
||||
"""The tests for the Yahoo weather sensor component."""
|
||||
import json
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
|
||||
from homeassistant.setup import setup_component
|
||||
|
||||
from tests.common import MockDependency, get_test_home_assistant, load_fixture
|
||||
|
||||
VALID_CONFIG_MINIMAL = {
|
||||
"sensor": {"platform": "yweather", "monitored_conditions": ["weather"]}
|
||||
}
|
||||
|
||||
VALID_CONFIG_ALL = {
|
||||
"sensor": {
|
||||
"platform": "yweather",
|
||||
"monitored_conditions": [
|
||||
"weather",
|
||||
"weather_current",
|
||||
"temperature",
|
||||
"temp_min",
|
||||
"temp_max",
|
||||
"wind_speed",
|
||||
"pressure",
|
||||
"visibility",
|
||||
"humidity",
|
||||
],
|
||||
}
|
||||
}
|
||||
|
||||
BAD_CONF_RAW = {
|
||||
"sensor": {
|
||||
"platform": "yweather",
|
||||
"woeid": "12345",
|
||||
"monitored_conditions": ["weather"],
|
||||
}
|
||||
}
|
||||
|
||||
BAD_CONF_DATA = {
|
||||
"sensor": {
|
||||
"platform": "yweather",
|
||||
"woeid": "111",
|
||||
"monitored_conditions": ["weather"],
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def _yql_queryMock(yql): # pylint: disable=invalid-name
|
||||
"""Mock yahoo query language query."""
|
||||
return (
|
||||
'{"query": {"count": 1, "created": "2017-11-17T13:40:47Z", '
|
||||
'"lang": "en-US", "results": {"place": {"woeid": "23511632"}}}}'
|
||||
)
|
||||
|
||||
|
||||
def get_woeidMock(lat, lon): # pylint: disable=invalid-name
|
||||
"""Mock get woeid Where On Earth Identifiers."""
|
||||
return "23511632"
|
||||
|
||||
|
||||
def get_woeidNoneMock(lat, lon): # pylint: disable=invalid-name
|
||||
"""Mock get woeid Where On Earth Identifiers."""
|
||||
return None
|
||||
|
||||
|
||||
class YahooWeatherMock:
|
||||
"""Mock class for the YahooWeather object."""
|
||||
|
||||
def __init__(self, woeid, temp_unit):
|
||||
"""Initialize Telnet object."""
|
||||
self.woeid = woeid
|
||||
self.temp_unit = temp_unit
|
||||
self._data = json.loads(load_fixture("yahooweather.json"))
|
||||
|
||||
# pylint: disable=no-self-use
|
||||
def updateWeather(self): # pylint: disable=invalid-name
|
||||
"""Return sample values."""
|
||||
return True
|
||||
|
||||
@property
|
||||
def RawData(self): # pylint: disable=invalid-name
|
||||
"""Raw Data."""
|
||||
if self.woeid == "12345":
|
||||
return json.loads("[]")
|
||||
return self._data
|
||||
|
||||
@property
|
||||
def Units(self): # pylint: disable=invalid-name
|
||||
"""Return dict with units."""
|
||||
return self._data["query"]["results"]["channel"]["units"]
|
||||
|
||||
@property
|
||||
def Now(self): # pylint: disable=invalid-name
|
||||
"""Return current weather data."""
|
||||
if self.woeid == "111":
|
||||
raise ValueError
|
||||
return self._data["query"]["results"]["channel"]["item"]["condition"]
|
||||
|
||||
@property
|
||||
def Atmosphere(self): # pylint: disable=invalid-name
|
||||
"""Atmosphere weather data."""
|
||||
return self._data["query"]["results"]["channel"]["atmosphere"]
|
||||
|
||||
@property
|
||||
def Wind(self): # pylint: disable=invalid-name
|
||||
"""Wind weather data."""
|
||||
return self._data["query"]["results"]["channel"]["wind"]
|
||||
|
||||
@property
|
||||
def Forecast(self): # pylint: disable=invalid-name
|
||||
"""Forecast data 0-5 Days."""
|
||||
return self._data["query"]["results"]["channel"]["item"]["forecast"]
|
||||
|
||||
def getWeatherImage(self, code): # pylint: disable=invalid-name
|
||||
"""Create a link to weather image from yahoo code."""
|
||||
return f"https://l.yimg.com/a/i/us/we/52/{code}.gif"
|
||||
|
||||
|
||||
class TestWeather(unittest.TestCase):
|
||||
"""Test the Yahoo weather component."""
|
||||
|
||||
def setUp(self):
|
||||
"""Set up things to be run when tests are started."""
|
||||
self.hass = get_test_home_assistant()
|
||||
|
||||
def tearDown(self):
|
||||
"""Stop down everything that was started."""
|
||||
self.hass.stop()
|
||||
|
||||
@MockDependency("yahooweather")
|
||||
@patch("yahooweather._yql_query", new=_yql_queryMock)
|
||||
@patch("yahooweather.get_woeid", new=get_woeidMock)
|
||||
@patch("yahooweather.YahooWeather", new=YahooWeatherMock)
|
||||
def test_setup_minimal(self, mock_yahooweather):
|
||||
"""Test for minimal weather sensor config."""
|
||||
assert setup_component(self.hass, "sensor", VALID_CONFIG_MINIMAL)
|
||||
|
||||
state = self.hass.states.get("sensor.yweather_condition")
|
||||
assert state is not None
|
||||
|
||||
assert state.state == "Mostly Cloudy"
|
||||
assert state.attributes.get("friendly_name") == "Yweather Condition"
|
||||
|
||||
@MockDependency("yahooweather")
|
||||
@patch("yahooweather._yql_query", new=_yql_queryMock)
|
||||
@patch("yahooweather.get_woeid", new=get_woeidMock)
|
||||
@patch("yahooweather.YahooWeather", new=YahooWeatherMock)
|
||||
def test_setup_all(self, mock_yahooweather):
|
||||
"""Test for all weather data attributes."""
|
||||
assert setup_component(self.hass, "sensor", VALID_CONFIG_ALL)
|
||||
|
||||
state = self.hass.states.get("sensor.yweather_condition")
|
||||
assert state is not None
|
||||
assert state.state == "Mostly Cloudy"
|
||||
assert state.attributes.get("condition_code") == "28"
|
||||
assert state.attributes.get("friendly_name") == "Yweather Condition"
|
||||
|
||||
state = self.hass.states.get("sensor.yweather_current")
|
||||
assert state is not None
|
||||
assert state.state == "Cloudy"
|
||||
assert state.attributes.get("friendly_name") == "Yweather Current"
|
||||
|
||||
state = self.hass.states.get("sensor.yweather_temperature")
|
||||
assert state is not None
|
||||
assert state.state == "18"
|
||||
assert state.attributes.get("friendly_name") == "Yweather Temperature"
|
||||
|
||||
state = self.hass.states.get("sensor.yweather_temperature_max")
|
||||
assert state is not None
|
||||
assert state.state == "23"
|
||||
assert state.attributes.get("friendly_name") == "Yweather Temperature max"
|
||||
|
||||
state = self.hass.states.get("sensor.yweather_temperature_min")
|
||||
assert state is not None
|
||||
assert state.state == "16"
|
||||
assert state.attributes.get("friendly_name") == "Yweather Temperature min"
|
||||
|
||||
state = self.hass.states.get("sensor.yweather_wind_speed")
|
||||
assert state is not None
|
||||
assert state.state == "3.94"
|
||||
assert state.attributes.get("friendly_name") == "Yweather Wind speed"
|
||||
|
||||
state = self.hass.states.get("sensor.yweather_pressure")
|
||||
assert state is not None
|
||||
assert state.state == "1000.0"
|
||||
assert state.attributes.get("friendly_name") == "Yweather Pressure"
|
||||
|
||||
state = self.hass.states.get("sensor.yweather_visibility")
|
||||
assert state is not None
|
||||
assert state.state == "14.23"
|
||||
assert state.attributes.get("friendly_name") == "Yweather Visibility"
|
||||
|
||||
state = self.hass.states.get("sensor.yweather_humidity")
|
||||
assert state is not None
|
||||
assert state.state == "71"
|
||||
assert state.attributes.get("friendly_name") == "Yweather Humidity"
|
||||
|
||||
@MockDependency("yahooweather")
|
||||
@patch("yahooweather._yql_query", new=_yql_queryMock)
|
||||
@patch("yahooweather.get_woeid", new=get_woeidNoneMock)
|
||||
@patch("yahooweather.YahooWeather", new=YahooWeatherMock)
|
||||
def test_setup_bad_woied(self, mock_yahooweather):
|
||||
"""Test for bad woeid."""
|
||||
assert setup_component(self.hass, "sensor", VALID_CONFIG_MINIMAL)
|
||||
|
||||
state = self.hass.states.get("sensor.yweather_condition")
|
||||
assert state is None
|
||||
|
||||
@MockDependency("yahooweather")
|
||||
@patch("yahooweather._yql_query", new=_yql_queryMock)
|
||||
@patch("yahooweather.get_woeid", new=get_woeidMock)
|
||||
@patch("yahooweather.YahooWeather", new=YahooWeatherMock)
|
||||
def test_setup_bad_raw(self, mock_yahooweather):
|
||||
"""Test for bad RawData."""
|
||||
assert setup_component(self.hass, "sensor", BAD_CONF_RAW)
|
||||
|
||||
state = self.hass.states.get("sensor.yweather_condition")
|
||||
assert state is not None
|
||||
|
||||
@MockDependency("yahooweather")
|
||||
@patch("yahooweather._yql_query", new=_yql_queryMock)
|
||||
@patch("yahooweather.get_woeid", new=get_woeidMock)
|
||||
@patch("yahooweather.YahooWeather", new=YahooWeatherMock)
|
||||
def test_setup_bad_data(self, mock_yahooweather):
|
||||
"""Test for bad data."""
|
||||
assert setup_component(self.hass, "sensor", BAD_CONF_DATA)
|
||||
|
||||
state = self.hass.states.get("sensor.yweather_condition")
|
||||
assert state is None
|
||||
@@ -1,162 +0,0 @@
|
||||
"""The tests for the Yahoo weather component."""
|
||||
import json
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
|
||||
from homeassistant.components.weather import (
|
||||
ATTR_WEATHER_HUMIDITY,
|
||||
ATTR_WEATHER_PRESSURE,
|
||||
ATTR_WEATHER_TEMPERATURE,
|
||||
ATTR_WEATHER_WIND_BEARING,
|
||||
ATTR_WEATHER_WIND_SPEED,
|
||||
)
|
||||
from homeassistant.setup import setup_component
|
||||
from homeassistant.util.unit_system import METRIC_SYSTEM
|
||||
|
||||
from tests.common import MockDependency, get_test_home_assistant, load_fixture
|
||||
|
||||
|
||||
def _yql_queryMock(yql): # pylint: disable=invalid-name
|
||||
"""Mock yahoo query language query."""
|
||||
return (
|
||||
'{"query": {"count": 1, "created": "2017-11-17T13:40:47Z", '
|
||||
'"lang": "en-US", "results": {"place": {"woeid": "23511632"}}}}'
|
||||
)
|
||||
|
||||
|
||||
def get_woeidMock(lat, lon): # pylint: disable=invalid-name
|
||||
"""Mock get woeid Where On Earth Identifiers."""
|
||||
return "23511632"
|
||||
|
||||
|
||||
class YahooWeatherMock:
|
||||
"""Mock class for the YahooWeather object."""
|
||||
|
||||
def __init__(self, woeid, temp_unit):
|
||||
"""Initialize Telnet object."""
|
||||
self.woeid = woeid
|
||||
self.temp_unit = temp_unit
|
||||
self._data = json.loads(load_fixture("yahooweather.json"))
|
||||
|
||||
# pylint: disable=no-self-use
|
||||
def updateWeather(self): # pylint: disable=invalid-name
|
||||
"""Return sample values."""
|
||||
return True
|
||||
|
||||
@property
|
||||
def RawData(self): # pylint: disable=invalid-name
|
||||
"""Return raw Data."""
|
||||
if self.woeid == "12345":
|
||||
return json.loads("[]")
|
||||
return self._data
|
||||
|
||||
@property
|
||||
def Now(self): # pylint: disable=invalid-name
|
||||
"""Return current weather data."""
|
||||
if self.woeid == "111":
|
||||
raise ValueError
|
||||
return self._data["query"]["results"]["channel"]["item"]["condition"]
|
||||
|
||||
@property
|
||||
def Atmosphere(self): # pylint: disable=invalid-name
|
||||
"""Return atmosphere weather data."""
|
||||
return self._data["query"]["results"]["channel"]["atmosphere"]
|
||||
|
||||
@property
|
||||
def Wind(self): # pylint: disable=invalid-name
|
||||
"""Return wind weather data."""
|
||||
return self._data["query"]["results"]["channel"]["wind"]
|
||||
|
||||
@property
|
||||
def Forecast(self): # pylint: disable=invalid-name
|
||||
"""Return forecast data 0-5 Days."""
|
||||
if self.woeid == "123123":
|
||||
raise ValueError
|
||||
return self._data["query"]["results"]["channel"]["item"]["forecast"]
|
||||
|
||||
|
||||
class TestWeather(unittest.TestCase):
|
||||
"""Test the Yahoo weather component."""
|
||||
|
||||
DEVICES = []
|
||||
|
||||
def add_entities(self, devices):
|
||||
"""Mock add devices."""
|
||||
for device in devices:
|
||||
device.update()
|
||||
self.DEVICES.append(device)
|
||||
|
||||
def setUp(self):
|
||||
"""Set up things to be run when tests are started."""
|
||||
self.hass = get_test_home_assistant()
|
||||
self.hass.config.units = METRIC_SYSTEM
|
||||
|
||||
def tearDown(self):
|
||||
"""Stop down everything that was started."""
|
||||
self.hass.stop()
|
||||
|
||||
@MockDependency("yahooweather")
|
||||
@patch("yahooweather._yql_query", new=_yql_queryMock)
|
||||
@patch("yahooweather.get_woeid", new=get_woeidMock)
|
||||
@patch("yahooweather.YahooWeather", new=YahooWeatherMock)
|
||||
def test_setup(self, mock_yahooweather):
|
||||
"""Test for typical weather data attributes."""
|
||||
assert setup_component(
|
||||
self.hass, "weather", {"weather": {"platform": "yweather"}}
|
||||
)
|
||||
|
||||
state = self.hass.states.get("weather.yweather")
|
||||
assert state is not None
|
||||
|
||||
assert state.state == "cloudy"
|
||||
|
||||
data = state.attributes
|
||||
assert data.get(ATTR_WEATHER_TEMPERATURE) == 18.0
|
||||
assert data.get(ATTR_WEATHER_HUMIDITY) == 71
|
||||
assert data.get(ATTR_WEATHER_PRESSURE) == 1000.0
|
||||
assert data.get(ATTR_WEATHER_WIND_SPEED) == 3.94
|
||||
assert data.get(ATTR_WEATHER_WIND_BEARING) == 0
|
||||
assert state.attributes.get("friendly_name") == "Yweather"
|
||||
|
||||
@MockDependency("yahooweather")
|
||||
@patch("yahooweather._yql_query", new=_yql_queryMock)
|
||||
@patch("yahooweather.get_woeid", new=get_woeidMock)
|
||||
@patch("yahooweather.YahooWeather", new=YahooWeatherMock)
|
||||
def test_setup_no_data(self, mock_yahooweather):
|
||||
"""Test for note receiving data."""
|
||||
assert setup_component(
|
||||
self.hass,
|
||||
"weather",
|
||||
{"weather": {"platform": "yweather", "woeid": "12345"}},
|
||||
)
|
||||
|
||||
state = self.hass.states.get("weather.yweather")
|
||||
assert state is not None
|
||||
|
||||
@MockDependency("yahooweather")
|
||||
@patch("yahooweather._yql_query", new=_yql_queryMock)
|
||||
@patch("yahooweather.get_woeid", new=get_woeidMock)
|
||||
@patch("yahooweather.YahooWeather", new=YahooWeatherMock)
|
||||
def test_setup_bad_data(self, mock_yahooweather):
|
||||
"""Test for bad forecast data."""
|
||||
assert setup_component(
|
||||
self.hass,
|
||||
"weather",
|
||||
{"weather": {"platform": "yweather", "woeid": "123123"}},
|
||||
)
|
||||
|
||||
state = self.hass.states.get("weather.yweather")
|
||||
assert state is None
|
||||
|
||||
@MockDependency("yahooweather")
|
||||
@patch("yahooweather._yql_query", new=_yql_queryMock)
|
||||
@patch("yahooweather.get_woeid", new=get_woeidMock)
|
||||
@patch("yahooweather.YahooWeather", new=YahooWeatherMock)
|
||||
def test_setup_condition_error(self, mock_yahooweather):
|
||||
"""Test for bad forecast data."""
|
||||
assert setup_component(
|
||||
self.hass, "weather", {"weather": {"platform": "yweather", "woeid": "111"}}
|
||||
)
|
||||
|
||||
state = self.hass.states.get("weather.yweather")
|
||||
assert state is None
|
||||
Reference in new issue
Block a user