2020-07-24 20:59:15 +00:00
|
|
|
"""Tests for AccuWeather."""
|
2024-03-08 19:38:34 +00:00
|
|
|
|
2021-05-19 08:37:16 +00:00
|
|
|
from unittest.mock import PropertyMock, patch
|
2020-08-09 14:21:36 +00:00
|
|
|
|
|
|
|
from homeassistant.components.accuweather.const import DOMAIN
|
|
|
|
|
2023-02-16 18:40:47 +00:00
|
|
|
from tests.common import (
|
|
|
|
MockConfigEntry,
|
|
|
|
load_json_array_fixture,
|
|
|
|
load_json_object_fixture,
|
|
|
|
)
|
2020-08-09 14:21:36 +00:00
|
|
|
|
|
|
|
|
2024-04-16 22:00:16 +00:00
|
|
|
async def init_integration(hass, unsupported_icon=False) -> MockConfigEntry:
|
2020-08-09 14:21:36 +00:00
|
|
|
"""Set up the AccuWeather integration in Home Assistant."""
|
|
|
|
entry = MockConfigEntry(
|
|
|
|
domain=DOMAIN,
|
|
|
|
title="Home",
|
|
|
|
unique_id="0123456",
|
|
|
|
data={
|
|
|
|
"api_key": "32-character-string-1234567890qw",
|
|
|
|
"latitude": 55.55,
|
|
|
|
"longitude": 122.12,
|
|
|
|
"name": "Home",
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
2023-02-16 18:40:47 +00:00
|
|
|
current = load_json_object_fixture("accuweather/current_conditions_data.json")
|
|
|
|
forecast = load_json_array_fixture("accuweather/forecast_data.json")
|
2020-08-09 14:21:36 +00:00
|
|
|
|
|
|
|
if unsupported_icon:
|
|
|
|
current["WeatherIcon"] = 999
|
|
|
|
|
2024-03-25 23:02:16 +00:00
|
|
|
with (
|
|
|
|
patch(
|
|
|
|
"homeassistant.components.accuweather.AccuWeather.async_get_current_conditions",
|
|
|
|
return_value=current,
|
|
|
|
),
|
|
|
|
patch(
|
|
|
|
"homeassistant.components.accuweather.AccuWeather.async_get_daily_forecast",
|
|
|
|
return_value=forecast,
|
|
|
|
),
|
|
|
|
patch(
|
|
|
|
"homeassistant.components.accuweather.AccuWeather.requests_remaining",
|
|
|
|
new_callable=PropertyMock,
|
|
|
|
return_value=10,
|
|
|
|
),
|
2020-08-09 14:21:36 +00:00
|
|
|
):
|
|
|
|
entry.add_to_hass(hass)
|
|
|
|
await hass.config_entries.async_setup(entry.entry_id)
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
|
|
|
return entry
|