Improve tests for AccuWeather integration (#38621)
* Add more tests * Add tests for sensor platform * Add more tests * More tests * Simplify parsing of attributes * Change Quality scale to platinum * Patch the library in the manual update entity test * Add unsupported condition icon test * Do not patch _async_get_data * Apply suggestions from code review * Update config_flow.py * Apply suggestions from code review * Apply suggestions from code review * Apply suggestions from code review * Update tests/components/accuweather/test_weather.py * Apply suggestions from code review * Add return_value Co-authored-by: Chris Talkington <chris@talkingtontech.com>
This commit is contained in:
1 parent
ca3842b150
commit
a7e19c8896
9 files changed
+1844
-11
No files matched your search
@@ -1 +1,48 @@
|
||||
"""Tests for AccuWeather."""
|
||||
import json
|
||||
|
||||
from homeassistant.components.accuweather.const import DOMAIN
|
||||
|
||||
from tests.async_mock import patch
|
||||
from tests.common import MockConfigEntry, load_fixture
|
||||
|
||||
|
||||
async def init_integration(
|
||||
hass, forecast=False, unsupported_icon=False
|
||||
) -> MockConfigEntry:
|
||||
"""Set up the AccuWeather integration in Home Assistant."""
|
||||
options = {}
|
||||
if forecast:
|
||||
options["forecast"] = True
|
||||
|
||||
entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
title="Home",
|
||||
unique_id="0123456",
|
||||
data={
|
||||
"api_key": "32-character-string-1234567890qw",
|
||||
"latitude": 55.55,
|
||||
"longitude": 122.12,
|
||||
"name": "Home",
|
||||
},
|
||||
options=options,
|
||||
)
|
||||
|
||||
current = json.loads(load_fixture("accuweather/current_conditions_data.json"))
|
||||
forecast = json.loads(load_fixture("accuweather/forecast_data.json"))
|
||||
|
||||
if unsupported_icon:
|
||||
current["WeatherIcon"] = 999
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.accuweather.AccuWeather.async_get_current_conditions",
|
||||
return_value=current,
|
||||
), patch(
|
||||
"homeassistant.components.accuweather.AccuWeather.async_get_forecast",
|
||||
return_value=forecast,
|
||||
):
|
||||
entry.add_to_hass(hass)
|
||||
await hass.config_entries.async_setup(entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
return entry
|
||||
@@ -0,0 +1,59 @@
|
||||
"""Test init of AccuWeather integration."""
|
||||
from homeassistant.components.accuweather.const import DOMAIN
|
||||
from homeassistant.config_entries import (
|
||||
ENTRY_STATE_LOADED,
|
||||
ENTRY_STATE_NOT_LOADED,
|
||||
ENTRY_STATE_SETUP_RETRY,
|
||||
)
|
||||
from homeassistant.const import STATE_UNAVAILABLE
|
||||
|
||||
from tests.async_mock import patch
|
||||
from tests.common import MockConfigEntry
|
||||
from tests.components.accuweather import init_integration
|
||||
|
||||
|
||||
async def test_async_setup_entry(hass):
|
||||
"""Test a successful setup entry."""
|
||||
await init_integration(hass)
|
||||
|
||||
state = hass.states.get("weather.home")
|
||||
assert state is not None
|
||||
assert state.state != STATE_UNAVAILABLE
|
||||
assert state.state == "sunny"
|
||||
|
||||
|
||||
async def test_config_not_ready(hass):
|
||||
"""Test for setup failure if connection to AccuWeather is missing."""
|
||||
entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
title="Home",
|
||||
unique_id="0123456",
|
||||
data={
|
||||
"api_key": "32-character-string-1234567890qw",
|
||||
"latitude": 55.55,
|
||||
"longitude": 122.12,
|
||||
"name": "Home",
|
||||
},
|
||||
)
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.accuweather.AccuWeather._async_get_data",
|
||||
side_effect=ConnectionError(),
|
||||
):
|
||||
entry.add_to_hass(hass)
|
||||
await hass.config_entries.async_setup(entry.entry_id)
|
||||
assert entry.state == ENTRY_STATE_SETUP_RETRY
|
||||
|
||||
|
||||
async def test_unload_entry(hass):
|
||||
"""Test successful unload of entry."""
|
||||
entry = await init_integration(hass)
|
||||
|
||||
assert len(hass.config_entries.async_entries(DOMAIN)) == 1
|
||||
assert entry.state == ENTRY_STATE_LOADED
|
||||
|
||||
assert await hass.config_entries.async_unload(entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert entry.state == ENTRY_STATE_NOT_LOADED
|
||||
assert not hass.data.get(DOMAIN)
|
||||
@@ -0,0 +1,598 @@
|
||||
"""Test sensor of AccuWeather integration."""
|
||||
from datetime import timedelta
|
||||
import json
|
||||
|
||||
from homeassistant.components.accuweather.const import (
|
||||
ATTRIBUTION,
|
||||
CONCENTRATION_PARTS_PER_CUBIC_METER,
|
||||
DOMAIN,
|
||||
LENGTH_MILIMETERS,
|
||||
)
|
||||
from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN
|
||||
from homeassistant.const import (
|
||||
ATTR_ATTRIBUTION,
|
||||
ATTR_DEVICE_CLASS,
|
||||
ATTR_ENTITY_ID,
|
||||
ATTR_ICON,
|
||||
ATTR_UNIT_OF_MEASUREMENT,
|
||||
DEVICE_CLASS_TEMPERATURE,
|
||||
LENGTH_METERS,
|
||||
SPEED_KILOMETERS_PER_HOUR,
|
||||
STATE_UNAVAILABLE,
|
||||
TEMP_CELSIUS,
|
||||
TIME_HOURS,
|
||||
UNIT_PERCENTAGE,
|
||||
UV_INDEX,
|
||||
)
|
||||
from homeassistant.setup import async_setup_component
|
||||
from homeassistant.util.dt import utcnow
|
||||
|
||||
from tests.async_mock import patch
|
||||
from tests.common import async_fire_time_changed, load_fixture
|
||||
from tests.components.accuweather import init_integration
|
||||
|
||||
|
||||
async def test_sensor_without_forecast(hass):
|
||||
"""Test states of the sensor without forecast."""
|
||||
await init_integration(hass)
|
||||
registry = await hass.helpers.entity_registry.async_get_registry()
|
||||
|
||||
state = hass.states.get("sensor.home_cloud_ceiling")
|
||||
assert state
|
||||
assert state.state == "3200"
|
||||
assert state.attributes.get(ATTR_ATTRIBUTION) == ATTRIBUTION
|
||||
assert state.attributes.get(ATTR_ICON) == "mdi:weather-fog"
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == LENGTH_METERS
|
||||
|
||||
entry = registry.async_get("sensor.home_cloud_ceiling")
|
||||
assert entry
|
||||
assert entry.unique_id == "0123456-ceiling"
|
||||
|
||||
state = hass.states.get("sensor.home_precipitation")
|
||||
assert state
|
||||
assert state.state == "0.0"
|
||||
assert state.attributes.get(ATTR_ATTRIBUTION) == ATTRIBUTION
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == LENGTH_MILIMETERS
|
||||
assert state.attributes.get(ATTR_ICON) == "mdi:weather-rainy"
|
||||
assert state.attributes.get("type") is None
|
||||
|
||||
entry = registry.async_get("sensor.home_precipitation")
|
||||
assert entry
|
||||
assert entry.unique_id == "0123456-precipitation"
|
||||
|
||||
state = hass.states.get("sensor.home_pressure_tendency")
|
||||
assert state
|
||||
assert state.state == "falling"
|
||||
assert state.attributes.get(ATTR_ATTRIBUTION) == ATTRIBUTION
|
||||
assert state.attributes.get(ATTR_ICON) == "mdi:gauge"
|
||||
assert state.attributes.get(ATTR_DEVICE_CLASS) == "accuweather__pressure_tendency"
|
||||
|
||||
entry = registry.async_get("sensor.home_pressure_tendency")
|
||||
assert entry
|
||||
assert entry.unique_id == "0123456-pressuretendency"
|
||||
|
||||
state = hass.states.get("sensor.home_realfeel_temperature")
|
||||
assert state
|
||||
assert state.state == "25.1"
|
||||
assert state.attributes.get(ATTR_ATTRIBUTION) == ATTRIBUTION
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == TEMP_CELSIUS
|
||||
assert state.attributes.get(ATTR_DEVICE_CLASS) == DEVICE_CLASS_TEMPERATURE
|
||||
|
||||
entry = registry.async_get("sensor.home_realfeel_temperature")
|
||||
assert entry
|
||||
assert entry.unique_id == "0123456-realfeeltemperature"
|
||||
|
||||
state = hass.states.get("sensor.home_uv_index")
|
||||
assert state
|
||||
assert state.state == "6"
|
||||
assert state.attributes.get(ATTR_ATTRIBUTION) == ATTRIBUTION
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UV_INDEX
|
||||
assert state.attributes.get("level") == "High"
|
||||
|
||||
entry = registry.async_get("sensor.home_uv_index")
|
||||
assert entry
|
||||
assert entry.unique_id == "0123456-uvindex"
|
||||
|
||||
|
||||
async def test_sensor_with_forecast(hass):
|
||||
"""Test states of the sensor with forecast."""
|
||||
await init_integration(hass, forecast=True)
|
||||
registry = await hass.helpers.entity_registry.async_get_registry()
|
||||
|
||||
state = hass.states.get("sensor.home_hours_of_sun_0d")
|
||||
assert state
|
||||
assert state.state == "7.2"
|
||||
assert state.attributes.get(ATTR_ATTRIBUTION) == ATTRIBUTION
|
||||
assert state.attributes.get(ATTR_ICON) == "mdi:weather-partly-cloudy"
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == TIME_HOURS
|
||||
|
||||
entry = registry.async_get("sensor.home_hours_of_sun_0d")
|
||||
assert entry
|
||||
assert entry.unique_id == "0123456-hoursofsun-0"
|
||||
|
||||
state = hass.states.get("sensor.home_realfeel_temperature_max_0d")
|
||||
assert state
|
||||
assert state.state == "29.8"
|
||||
assert state.attributes.get(ATTR_ATTRIBUTION) == ATTRIBUTION
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == TEMP_CELSIUS
|
||||
assert state.attributes.get(ATTR_DEVICE_CLASS) == DEVICE_CLASS_TEMPERATURE
|
||||
|
||||
entry = registry.async_get("sensor.home_realfeel_temperature_max_0d")
|
||||
assert entry
|
||||
|
||||
state = hass.states.get("sensor.home_realfeel_temperature_min_0d")
|
||||
assert state
|
||||
assert state.state == "15.1"
|
||||
assert state.attributes.get(ATTR_ATTRIBUTION) == ATTRIBUTION
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == TEMP_CELSIUS
|
||||
assert state.attributes.get(ATTR_DEVICE_CLASS) == DEVICE_CLASS_TEMPERATURE
|
||||
|
||||
entry = registry.async_get("sensor.home_realfeel_temperature_min_0d")
|
||||
assert entry
|
||||
assert entry.unique_id == "0123456-realfeeltemperaturemin-0"
|
||||
|
||||
state = hass.states.get("sensor.home_thunderstorm_probability_day_0d")
|
||||
assert state
|
||||
assert state.state == "40"
|
||||
assert state.attributes.get(ATTR_ATTRIBUTION) == ATTRIBUTION
|
||||
assert state.attributes.get(ATTR_ICON) == "mdi:weather-lightning"
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UNIT_PERCENTAGE
|
||||
|
||||
entry = registry.async_get("sensor.home_thunderstorm_probability_day_0d")
|
||||
assert entry
|
||||
assert entry.unique_id == "0123456-thunderstormprobabilityday-0"
|
||||
|
||||
state = hass.states.get("sensor.home_thunderstorm_probability_night_0d")
|
||||
assert state
|
||||
assert state.state == "40"
|
||||
assert state.attributes.get(ATTR_ATTRIBUTION) == ATTRIBUTION
|
||||
assert state.attributes.get(ATTR_ICON) == "mdi:weather-lightning"
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UNIT_PERCENTAGE
|
||||
|
||||
entry = registry.async_get("sensor.home_thunderstorm_probability_night_0d")
|
||||
assert entry
|
||||
assert entry.unique_id == "0123456-thunderstormprobabilitynight-0"
|
||||
|
||||
state = hass.states.get("sensor.home_uv_index_0d")
|
||||
assert state
|
||||
assert state.state == "5"
|
||||
assert state.attributes.get(ATTR_ATTRIBUTION) == ATTRIBUTION
|
||||
assert state.attributes.get(ATTR_ICON) == "mdi:weather-sunny"
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UV_INDEX
|
||||
assert state.attributes.get("level") == "Moderate"
|
||||
|
||||
entry = registry.async_get("sensor.home_uv_index_0d")
|
||||
assert entry
|
||||
assert entry.unique_id == "0123456-uvindex-0"
|
||||
|
||||
|
||||
async def test_sensor_disabled(hass):
|
||||
"""Test sensor disabled by default."""
|
||||
await init_integration(hass)
|
||||
registry = await hass.helpers.entity_registry.async_get_registry()
|
||||
|
||||
entry = registry.async_get("sensor.home_apparent_temperature")
|
||||
assert entry
|
||||
assert entry.unique_id == "0123456-apparenttemperature"
|
||||
assert entry.disabled
|
||||
assert entry.disabled_by == "integration"
|
||||
|
||||
# Test enabling entity
|
||||
updated_entry = registry.async_update_entity(
|
||||
entry.entity_id, **{"disabled_by": None}
|
||||
)
|
||||
|
||||
assert updated_entry != entry
|
||||
assert updated_entry.disabled is False
|
||||
|
||||
|
||||
async def test_sensor_enabled_without_forecast(hass):
|
||||
"""Test enabling an advanced sensor."""
|
||||
registry = await hass.helpers.entity_registry.async_get_registry()
|
||||
|
||||
registry.async_get_or_create(
|
||||
SENSOR_DOMAIN,
|
||||
DOMAIN,
|
||||
"0123456-apparenttemperature",
|
||||
suggested_object_id="home_apparent_temperature",
|
||||
disabled_by=None,
|
||||
)
|
||||
registry.async_get_or_create(
|
||||
SENSOR_DOMAIN,
|
||||
DOMAIN,
|
||||
"0123456-cloudcover",
|
||||
suggested_object_id="home_cloud_cover",
|
||||
disabled_by=None,
|
||||
)
|
||||
registry.async_get_or_create(
|
||||
SENSOR_DOMAIN,
|
||||
DOMAIN,
|
||||
"0123456-dewpoint",
|
||||
suggested_object_id="home_dew_point",
|
||||
disabled_by=None,
|
||||
)
|
||||
registry.async_get_or_create(
|
||||
SENSOR_DOMAIN,
|
||||
DOMAIN,
|
||||
"0123456-realfeeltemperatureshade",
|
||||
suggested_object_id="home_realfeel_temperature_shade",
|
||||
disabled_by=None,
|
||||
)
|
||||
registry.async_get_or_create(
|
||||
SENSOR_DOMAIN,
|
||||
DOMAIN,
|
||||
"0123456-wetbulbtemperature",
|
||||
suggested_object_id="home_wet_bulb_temperature",
|
||||
disabled_by=None,
|
||||
)
|
||||
registry.async_get_or_create(
|
||||
SENSOR_DOMAIN,
|
||||
DOMAIN,
|
||||
"0123456-windchilltemperature",
|
||||
suggested_object_id="home_wind_chill_temperature",
|
||||
disabled_by=None,
|
||||
)
|
||||
registry.async_get_or_create(
|
||||
SENSOR_DOMAIN,
|
||||
DOMAIN,
|
||||
"0123456-windgust",
|
||||
suggested_object_id="home_wind_gust",
|
||||
disabled_by=None,
|
||||
)
|
||||
registry.async_get_or_create(
|
||||
SENSOR_DOMAIN,
|
||||
DOMAIN,
|
||||
"0123456-cloudcoverday-0",
|
||||
suggested_object_id="home_cloud_cover_day_0d",
|
||||
disabled_by=None,
|
||||
)
|
||||
registry.async_get_or_create(
|
||||
SENSOR_DOMAIN,
|
||||
DOMAIN,
|
||||
"0123456-cloudcovernight-0",
|
||||
suggested_object_id="home_cloud_cover_night_0d",
|
||||
disabled_by=None,
|
||||
)
|
||||
registry.async_get_or_create(
|
||||
SENSOR_DOMAIN,
|
||||
DOMAIN,
|
||||
"0123456-grass-0",
|
||||
suggested_object_id="home_grass_pollen_0d",
|
||||
disabled_by=None,
|
||||
)
|
||||
registry.async_get_or_create(
|
||||
SENSOR_DOMAIN,
|
||||
DOMAIN,
|
||||
"0123456-mold-0",
|
||||
suggested_object_id="home_mold_pollen_0d",
|
||||
disabled_by=None,
|
||||
)
|
||||
registry.async_get_or_create(
|
||||
SENSOR_DOMAIN,
|
||||
DOMAIN,
|
||||
"0123456-ozone-0",
|
||||
suggested_object_id="home_ozone_0d",
|
||||
disabled_by=None,
|
||||
)
|
||||
registry.async_get_or_create(
|
||||
SENSOR_DOMAIN,
|
||||
DOMAIN,
|
||||
"0123456-ragweed-0",
|
||||
suggested_object_id="home_ragweed_pollen_0d",
|
||||
disabled_by=None,
|
||||
)
|
||||
registry.async_get_or_create(
|
||||
SENSOR_DOMAIN,
|
||||
DOMAIN,
|
||||
"0123456-realfeeltemperatureshademax-0",
|
||||
suggested_object_id="home_realfeel_temperature_shade_max_0d",
|
||||
disabled_by=None,
|
||||
)
|
||||
registry.async_get_or_create(
|
||||
SENSOR_DOMAIN,
|
||||
DOMAIN,
|
||||
"0123456-realfeeltemperatureshademin-0",
|
||||
suggested_object_id="home_realfeel_temperature_shade_min_0d",
|
||||
disabled_by=None,
|
||||
)
|
||||
registry.async_get_or_create(
|
||||
SENSOR_DOMAIN,
|
||||
DOMAIN,
|
||||
"0123456-tree-0",
|
||||
suggested_object_id="home_tree_pollen_0d",
|
||||
disabled_by=None,
|
||||
)
|
||||
registry.async_get_or_create(
|
||||
SENSOR_DOMAIN,
|
||||
DOMAIN,
|
||||
"0123456-windgustday-0",
|
||||
suggested_object_id="home_wind_gust_day_0d",
|
||||
disabled_by=None,
|
||||
)
|
||||
registry.async_get_or_create(
|
||||
SENSOR_DOMAIN,
|
||||
DOMAIN,
|
||||
"0123456-windgustnight-0",
|
||||
suggested_object_id="home_wind_gust_night_0d",
|
||||
disabled_by=None,
|
||||
)
|
||||
|
||||
await init_integration(hass, forecast=True)
|
||||
|
||||
state = hass.states.get("sensor.home_apparent_temperature")
|
||||
assert state
|
||||
assert state.state == "22.8"
|
||||
assert state.attributes.get(ATTR_ATTRIBUTION) == ATTRIBUTION
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == TEMP_CELSIUS
|
||||
assert state.attributes.get(ATTR_DEVICE_CLASS) == DEVICE_CLASS_TEMPERATURE
|
||||
|
||||
entry = registry.async_get("sensor.home_apparent_temperature")
|
||||
assert entry
|
||||
assert entry.unique_id == "0123456-apparenttemperature"
|
||||
|
||||
state = hass.states.get("sensor.home_cloud_cover")
|
||||
assert state
|
||||
assert state.state == "10"
|
||||
assert state.attributes.get(ATTR_ATTRIBUTION) == ATTRIBUTION
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UNIT_PERCENTAGE
|
||||
assert state.attributes.get(ATTR_ICON) == "mdi:weather-cloudy"
|
||||
|
||||
entry = registry.async_get("sensor.home_cloud_cover")
|
||||
assert entry
|
||||
assert entry.unique_id == "0123456-cloudcover"
|
||||
|
||||
state = hass.states.get("sensor.home_dew_point")
|
||||
assert state
|
||||
assert state.state == "16.2"
|
||||
assert state.attributes.get(ATTR_ATTRIBUTION) == ATTRIBUTION
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == TEMP_CELSIUS
|
||||
assert state.attributes.get(ATTR_DEVICE_CLASS) == DEVICE_CLASS_TEMPERATURE
|
||||
|
||||
entry = registry.async_get("sensor.home_dew_point")
|
||||
assert entry
|
||||
assert entry.unique_id == "0123456-dewpoint"
|
||||
|
||||
state = hass.states.get("sensor.home_realfeel_temperature_shade")
|
||||
assert state
|
||||
assert state.state == "21.1"
|
||||
assert state.attributes.get(ATTR_ATTRIBUTION) == ATTRIBUTION
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == TEMP_CELSIUS
|
||||
assert state.attributes.get(ATTR_DEVICE_CLASS) == DEVICE_CLASS_TEMPERATURE
|
||||
|
||||
entry = registry.async_get("sensor.home_realfeel_temperature_shade")
|
||||
assert entry
|
||||
assert entry.unique_id == "0123456-realfeeltemperatureshade"
|
||||
|
||||
state = hass.states.get("sensor.home_wet_bulb_temperature")
|
||||
assert state
|
||||
assert state.state == "18.6"
|
||||
assert state.attributes.get(ATTR_ATTRIBUTION) == ATTRIBUTION
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == TEMP_CELSIUS
|
||||
assert state.attributes.get(ATTR_DEVICE_CLASS) == DEVICE_CLASS_TEMPERATURE
|
||||
|
||||
entry = registry.async_get("sensor.home_wet_bulb_temperature")
|
||||
assert entry
|
||||
assert entry.unique_id == "0123456-wetbulbtemperature"
|
||||
|
||||
state = hass.states.get("sensor.home_wind_chill_temperature")
|
||||
assert state
|
||||
assert state.state == "22.8"
|
||||
assert state.attributes.get(ATTR_ATTRIBUTION) == ATTRIBUTION
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == TEMP_CELSIUS
|
||||
assert state.attributes.get(ATTR_DEVICE_CLASS) == DEVICE_CLASS_TEMPERATURE
|
||||
|
||||
entry = registry.async_get("sensor.home_wind_chill_temperature")
|
||||
assert entry
|
||||
assert entry.unique_id == "0123456-windchilltemperature"
|
||||
|
||||
state = hass.states.get("sensor.home_wind_gust")
|
||||
assert state
|
||||
assert state.state == "20.3"
|
||||
assert state.attributes.get(ATTR_ATTRIBUTION) == ATTRIBUTION
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == SPEED_KILOMETERS_PER_HOUR
|
||||
assert state.attributes.get(ATTR_ICON) == "mdi:weather-windy"
|
||||
|
||||
entry = registry.async_get("sensor.home_wind_gust")
|
||||
assert entry
|
||||
assert entry.unique_id == "0123456-windgust"
|
||||
|
||||
state = hass.states.get("sensor.home_cloud_cover_day_0d")
|
||||
assert state
|
||||
assert state.state == "58"
|
||||
assert state.attributes.get(ATTR_ATTRIBUTION) == ATTRIBUTION
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UNIT_PERCENTAGE
|
||||
assert state.attributes.get(ATTR_ICON) == "mdi:weather-cloudy"
|
||||
|
||||
entry = registry.async_get("sensor.home_cloud_cover_day_0d")
|
||||
assert entry
|
||||
assert entry.unique_id == "0123456-cloudcoverday-0"
|
||||
|
||||
state = hass.states.get("sensor.home_cloud_cover_night_0d")
|
||||
assert state
|
||||
assert state.state == "65"
|
||||
assert state.attributes.get(ATTR_ATTRIBUTION) == ATTRIBUTION
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UNIT_PERCENTAGE
|
||||
assert state.attributes.get(ATTR_ICON) == "mdi:weather-cloudy"
|
||||
|
||||
entry = registry.async_get("sensor.home_cloud_cover_night_0d")
|
||||
assert entry
|
||||
|
||||
state = hass.states.get("sensor.home_grass_pollen_0d")
|
||||
assert state
|
||||
assert state.state == "0"
|
||||
assert state.attributes.get(ATTR_ATTRIBUTION) == ATTRIBUTION
|
||||
assert (
|
||||
state.attributes.get(ATTR_UNIT_OF_MEASUREMENT)
|
||||
== CONCENTRATION_PARTS_PER_CUBIC_METER
|
||||
)
|
||||
assert state.attributes.get("level") == "Low"
|
||||
assert state.attributes.get(ATTR_ICON) == "mdi:grass"
|
||||
|
||||
entry = registry.async_get("sensor.home_grass_pollen_0d")
|
||||
assert entry
|
||||
assert entry.unique_id == "0123456-grass-0"
|
||||
|
||||
state = hass.states.get("sensor.home_mold_pollen_0d")
|
||||
assert state
|
||||
assert state.state == "0"
|
||||
assert state.attributes.get(ATTR_ATTRIBUTION) == ATTRIBUTION
|
||||
assert (
|
||||
state.attributes.get(ATTR_UNIT_OF_MEASUREMENT)
|
||||
== CONCENTRATION_PARTS_PER_CUBIC_METER
|
||||
)
|
||||
assert state.attributes.get("level") == "Low"
|
||||
assert state.attributes.get(ATTR_ICON) == "mdi:blur"
|
||||
|
||||
entry = registry.async_get("sensor.home_mold_pollen_0d")
|
||||
assert entry
|
||||
assert entry.unique_id == "0123456-mold-0"
|
||||
|
||||
state = hass.states.get("sensor.home_ozone_0d")
|
||||
assert state
|
||||
assert state.state == "32"
|
||||
assert state.attributes.get(ATTR_ATTRIBUTION) == ATTRIBUTION
|
||||
assert state.attributes.get("level") == "Good"
|
||||
assert state.attributes.get(ATTR_ICON) == "mdi:vector-triangle"
|
||||
|
||||
entry = registry.async_get("sensor.home_ozone_0d")
|
||||
assert entry
|
||||
assert entry.unique_id == "0123456-ozone-0"
|
||||
|
||||
state = hass.states.get("sensor.home_ragweed_pollen_0d")
|
||||
assert state
|
||||
assert state.state == "0"
|
||||
assert state.attributes.get(ATTR_ATTRIBUTION) == ATTRIBUTION
|
||||
assert (
|
||||
state.attributes.get(ATTR_UNIT_OF_MEASUREMENT)
|
||||
== CONCENTRATION_PARTS_PER_CUBIC_METER
|
||||
)
|
||||
assert state.attributes.get("level") == "Low"
|
||||
assert state.attributes.get(ATTR_ICON) == "mdi:sprout"
|
||||
|
||||
entry = registry.async_get("sensor.home_ragweed_pollen_0d")
|
||||
assert entry
|
||||
assert entry.unique_id == "0123456-ragweed-0"
|
||||
|
||||
state = hass.states.get("sensor.home_realfeel_temperature_shade_max_0d")
|
||||
assert state
|
||||
assert state.state == "28.0"
|
||||
assert state.attributes.get(ATTR_ATTRIBUTION) == ATTRIBUTION
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == TEMP_CELSIUS
|
||||
assert state.attributes.get(ATTR_DEVICE_CLASS) == DEVICE_CLASS_TEMPERATURE
|
||||
|
||||
entry = registry.async_get("sensor.home_realfeel_temperature_shade_max_0d")
|
||||
assert entry
|
||||
assert entry.unique_id == "0123456-realfeeltemperatureshademax-0"
|
||||
|
||||
state = hass.states.get("sensor.home_realfeel_temperature_shade_min_0d")
|
||||
assert state
|
||||
assert state.state == "15.1"
|
||||
assert state.attributes.get(ATTR_ATTRIBUTION) == ATTRIBUTION
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == TEMP_CELSIUS
|
||||
assert state.attributes.get(ATTR_DEVICE_CLASS) == DEVICE_CLASS_TEMPERATURE
|
||||
|
||||
entry = registry.async_get("sensor.home_realfeel_temperature_shade_min_0d")
|
||||
assert entry
|
||||
assert entry.unique_id == "0123456-realfeeltemperatureshademin-0"
|
||||
|
||||
state = hass.states.get("sensor.home_tree_pollen_0d")
|
||||
assert state
|
||||
assert state.state == "0"
|
||||
assert state.attributes.get(ATTR_ATTRIBUTION) == ATTRIBUTION
|
||||
assert (
|
||||
state.attributes.get(ATTR_UNIT_OF_MEASUREMENT)
|
||||
== CONCENTRATION_PARTS_PER_CUBIC_METER
|
||||
)
|
||||
assert state.attributes.get("level") == "Low"
|
||||
assert state.attributes.get(ATTR_ICON) == "mdi:tree-outline"
|
||||
|
||||
entry = registry.async_get("sensor.home_tree_pollen_0d")
|
||||
assert entry
|
||||
assert entry.unique_id == "0123456-tree-0"
|
||||
|
||||
state = hass.states.get("sensor.home_wind_gust_day_0d")
|
||||
assert state
|
||||
assert state.state == "29.6"
|
||||
assert state.attributes.get(ATTR_ATTRIBUTION) == ATTRIBUTION
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == SPEED_KILOMETERS_PER_HOUR
|
||||
assert state.attributes.get("direction") == "S"
|
||||
assert state.attributes.get(ATTR_ICON) == "mdi:weather-windy"
|
||||
|
||||
entry = registry.async_get("sensor.home_wind_gust_day_0d")
|
||||
assert entry
|
||||
assert entry.unique_id == "0123456-windgustday-0"
|
||||
|
||||
state = hass.states.get("sensor.home_wind_gust_night_0d")
|
||||
assert state
|
||||
assert state.state == "18.5"
|
||||
assert state.attributes.get(ATTR_ATTRIBUTION) == ATTRIBUTION
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == SPEED_KILOMETERS_PER_HOUR
|
||||
assert state.attributes.get("direction") == "WSW"
|
||||
assert state.attributes.get(ATTR_ICON) == "mdi:weather-windy"
|
||||
|
||||
entry = registry.async_get("sensor.home_wind_gust_night_0d")
|
||||
assert entry
|
||||
assert entry.unique_id == "0123456-windgustnight-0"
|
||||
|
||||
|
||||
async def test_availability(hass):
|
||||
"""Ensure that we mark the entities unavailable correctly when service is offline."""
|
||||
await init_integration(hass)
|
||||
|
||||
state = hass.states.get("sensor.home_cloud_ceiling")
|
||||
assert state
|
||||
assert state.state != STATE_UNAVAILABLE
|
||||
assert state.state == "3200"
|
||||
|
||||
future = utcnow() + timedelta(minutes=60)
|
||||
with patch(
|
||||
"homeassistant.components.accuweather.AccuWeather.async_get_current_conditions",
|
||||
side_effect=ConnectionError(),
|
||||
):
|
||||
async_fire_time_changed(hass, future)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get("sensor.home_cloud_ceiling")
|
||||
assert state
|
||||
assert state.state == STATE_UNAVAILABLE
|
||||
|
||||
future = utcnow() + timedelta(minutes=120)
|
||||
with patch(
|
||||
"homeassistant.components.accuweather.AccuWeather.async_get_current_conditions",
|
||||
return_value=json.loads(
|
||||
load_fixture("accuweather/current_conditions_data.json")
|
||||
),
|
||||
):
|
||||
async_fire_time_changed(hass, future)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get("sensor.home_cloud_ceiling")
|
||||
assert state
|
||||
assert state.state != STATE_UNAVAILABLE
|
||||
assert state.state == "3200"
|
||||
|
||||
|
||||
async def test_manual_update_entity(hass):
|
||||
"""Test manual update entity via service homeasasistant/update_entity."""
|
||||
await init_integration(hass, forecast=True)
|
||||
|
||||
await async_setup_component(hass, "homeassistant", {})
|
||||
|
||||
current = json.loads(load_fixture("accuweather/current_conditions_data.json"))
|
||||
forecast = json.loads(load_fixture("accuweather/forecast_data.json"))
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.accuweather.AccuWeather.async_get_current_conditions",
|
||||
return_value=current,
|
||||
) as mock_current, patch(
|
||||
"homeassistant.components.accuweather.AccuWeather.async_get_forecast",
|
||||
return_value=forecast,
|
||||
) as mock_forecast:
|
||||
await hass.services.async_call(
|
||||
"homeassistant",
|
||||
"update_entity",
|
||||
{ATTR_ENTITY_ID: ["sensor.home_cloud_ceiling"]},
|
||||
blocking=True,
|
||||
)
|
||||
assert mock_current.call_count == 1
|
||||
assert mock_forecast.call_count == 1
|
||||
@@ -0,0 +1,155 @@
|
||||
"""Test weather of AccuWeather integration."""
|
||||
from datetime import timedelta
|
||||
import json
|
||||
|
||||
from homeassistant.components.accuweather.const import ATTRIBUTION
|
||||
from homeassistant.components.weather import (
|
||||
ATTR_FORECAST,
|
||||
ATTR_FORECAST_CONDITION,
|
||||
ATTR_FORECAST_PRECIPITATION,
|
||||
ATTR_FORECAST_PRECIPITATION_PROBABILITY,
|
||||
ATTR_FORECAST_TEMP,
|
||||
ATTR_FORECAST_TEMP_LOW,
|
||||
ATTR_FORECAST_TIME,
|
||||
ATTR_FORECAST_WIND_BEARING,
|
||||
ATTR_FORECAST_WIND_SPEED,
|
||||
ATTR_WEATHER_HUMIDITY,
|
||||
ATTR_WEATHER_OZONE,
|
||||
ATTR_WEATHER_PRESSURE,
|
||||
ATTR_WEATHER_TEMPERATURE,
|
||||
ATTR_WEATHER_VISIBILITY,
|
||||
ATTR_WEATHER_WIND_BEARING,
|
||||
ATTR_WEATHER_WIND_SPEED,
|
||||
)
|
||||
from homeassistant.const import ATTR_ATTRIBUTION, ATTR_ENTITY_ID, STATE_UNAVAILABLE
|
||||
from homeassistant.setup import async_setup_component
|
||||
from homeassistant.util.dt import utcnow
|
||||
|
||||
from tests.async_mock import patch
|
||||
from tests.common import async_fire_time_changed, load_fixture
|
||||
from tests.components.accuweather import init_integration
|
||||
|
||||
|
||||
async def test_weather_without_forecast(hass):
|
||||
"""Test states of the weather without forecast."""
|
||||
await init_integration(hass)
|
||||
registry = await hass.helpers.entity_registry.async_get_registry()
|
||||
|
||||
state = hass.states.get("weather.home")
|
||||
assert state
|
||||
assert state.state == "sunny"
|
||||
assert not state.attributes.get(ATTR_FORECAST)
|
||||
assert state.attributes.get(ATTR_WEATHER_HUMIDITY) == 67
|
||||
assert not state.attributes.get(ATTR_WEATHER_OZONE)
|
||||
assert state.attributes.get(ATTR_WEATHER_PRESSURE) == 1012.0
|
||||
assert state.attributes.get(ATTR_WEATHER_TEMPERATURE) == 22.6
|
||||
assert state.attributes.get(ATTR_WEATHER_VISIBILITY) == 16.1
|
||||
assert state.attributes.get(ATTR_WEATHER_WIND_BEARING) == 180
|
||||
assert state.attributes.get(ATTR_WEATHER_WIND_SPEED) == 14.5
|
||||
assert state.attributes.get(ATTR_ATTRIBUTION) == ATTRIBUTION
|
||||
|
||||
entry = registry.async_get("weather.home")
|
||||
assert entry
|
||||
assert entry.unique_id == "0123456"
|
||||
|
||||
|
||||
async def test_weather_with_forecast(hass):
|
||||
"""Test states of the weather with forecast."""
|
||||
await init_integration(hass, forecast=True)
|
||||
registry = await hass.helpers.entity_registry.async_get_registry()
|
||||
|
||||
state = hass.states.get("weather.home")
|
||||
assert state
|
||||
assert state.state == "sunny"
|
||||
assert state.attributes.get(ATTR_WEATHER_HUMIDITY) == 67
|
||||
assert state.attributes.get(ATTR_WEATHER_OZONE) == 32
|
||||
assert state.attributes.get(ATTR_WEATHER_PRESSURE) == 1012.0
|
||||
assert state.attributes.get(ATTR_WEATHER_TEMPERATURE) == 22.6
|
||||
assert state.attributes.get(ATTR_WEATHER_VISIBILITY) == 16.1
|
||||
assert state.attributes.get(ATTR_WEATHER_WIND_BEARING) == 180
|
||||
assert state.attributes.get(ATTR_WEATHER_WIND_SPEED) == 14.5
|
||||
assert state.attributes.get(ATTR_ATTRIBUTION) == ATTRIBUTION
|
||||
forecast = state.attributes.get(ATTR_FORECAST)[0]
|
||||
assert forecast.get(ATTR_FORECAST_CONDITION) == "lightning-rainy"
|
||||
assert forecast.get(ATTR_FORECAST_PRECIPITATION) == 4.8
|
||||
assert forecast.get(ATTR_FORECAST_PRECIPITATION_PROBABILITY) == 58
|
||||
assert forecast.get(ATTR_FORECAST_TEMP) == 29.5
|
||||
assert forecast.get(ATTR_FORECAST_TEMP_LOW) == 15.4
|
||||
assert forecast.get(ATTR_FORECAST_TIME) == "2020-07-26T05:00:00+00:00"
|
||||
assert forecast.get(ATTR_FORECAST_WIND_BEARING) == 166
|
||||
assert forecast.get(ATTR_FORECAST_WIND_SPEED) == 13.0
|
||||
|
||||
entry = registry.async_get("weather.home")
|
||||
assert entry
|
||||
assert entry.unique_id == "0123456"
|
||||
|
||||
|
||||
async def test_availability(hass):
|
||||
"""Ensure that we mark the entities unavailable correctly when service is offline."""
|
||||
await init_integration(hass)
|
||||
|
||||
state = hass.states.get("weather.home")
|
||||
assert state
|
||||
assert state.state != STATE_UNAVAILABLE
|
||||
assert state.state == "sunny"
|
||||
|
||||
future = utcnow() + timedelta(minutes=60)
|
||||
with patch(
|
||||
"homeassistant.components.accuweather.AccuWeather._async_get_data",
|
||||
side_effect=ConnectionError(),
|
||||
):
|
||||
async_fire_time_changed(hass, future)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get("weather.home")
|
||||
assert state
|
||||
assert state.state == STATE_UNAVAILABLE
|
||||
|
||||
future = utcnow() + timedelta(minutes=120)
|
||||
with patch(
|
||||
"homeassistant.components.accuweather.AccuWeather.async_get_current_conditions",
|
||||
return_value=json.loads(
|
||||
load_fixture("accuweather/current_conditions_data.json")
|
||||
),
|
||||
):
|
||||
async_fire_time_changed(hass, future)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get("weather.home")
|
||||
assert state
|
||||
assert state.state != STATE_UNAVAILABLE
|
||||
assert state.state == "sunny"
|
||||
|
||||
|
||||
async def test_manual_update_entity(hass):
|
||||
"""Test manual update entity via service homeasasistant/update_entity."""
|
||||
await init_integration(hass, forecast=True)
|
||||
|
||||
await async_setup_component(hass, "homeassistant", {})
|
||||
|
||||
current = json.loads(load_fixture("accuweather/current_conditions_data.json"))
|
||||
forecast = json.loads(load_fixture("accuweather/forecast_data.json"))
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.accuweather.AccuWeather.async_get_current_conditions",
|
||||
return_value=current,
|
||||
) as mock_current, patch(
|
||||
"homeassistant.components.accuweather.AccuWeather.async_get_forecast",
|
||||
return_value=forecast,
|
||||
) as mock_forecast:
|
||||
await hass.services.async_call(
|
||||
"homeassistant",
|
||||
"update_entity",
|
||||
{ATTR_ENTITY_ID: ["weather.home"]},
|
||||
blocking=True,
|
||||
)
|
||||
assert mock_current.call_count == 1
|
||||
assert mock_forecast.call_count == 1
|
||||
|
||||
|
||||
async def test_unsupported_condition_icon_data(hass):
|
||||
"""Test with unsupported condition icon data."""
|
||||
await init_integration(hass, forecast=True, unsupported_icon=True)
|
||||
|
||||
state = hass.states.get("weather.home")
|
||||
assert state.attributes.get(ATTR_FORECAST_CONDITION) is None
|
||||
Reference in new issue
Block a user