2018-02-09 07:11:47 +00:00
|
|
|
"""Tests for the cloud component."""
|
2024-03-08 19:38:34 +00:00
|
|
|
|
2021-01-01 21:31:56 +00:00
|
|
|
from unittest.mock import AsyncMock, patch
|
|
|
|
|
2023-12-21 12:39:02 +00:00
|
|
|
from hass_nabucasa import Cloud
|
|
|
|
|
2018-09-20 21:46:51 +00:00
|
|
|
from homeassistant.components import cloud
|
2023-04-06 17:09:45 +00:00
|
|
|
from homeassistant.components.cloud import const, prefs as cloud_prefs
|
2019-12-08 17:01:12 +00:00
|
|
|
from homeassistant.setup import async_setup_component
|
2018-09-20 21:46:51 +00:00
|
|
|
|
2024-01-22 16:24:15 +00:00
|
|
|
PIPELINE_DATA = {
|
|
|
|
"items": [
|
|
|
|
{
|
|
|
|
"conversation_engine": "conversation_engine_1",
|
|
|
|
"conversation_language": "language_1",
|
|
|
|
"id": "01GX8ZWBAQYWNB1XV3EXEZ75DY",
|
|
|
|
"language": "language_1",
|
|
|
|
"name": "Home Assistant Cloud",
|
|
|
|
"stt_engine": "cloud",
|
|
|
|
"stt_language": "language_1",
|
|
|
|
"tts_engine": "cloud",
|
|
|
|
"tts_language": "language_1",
|
|
|
|
"tts_voice": "Arnold Schwarzenegger",
|
|
|
|
"wake_word_entity": None,
|
|
|
|
"wake_word_id": None,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"conversation_engine": "conversation_engine_2",
|
|
|
|
"conversation_language": "language_2",
|
|
|
|
"id": "01GX8ZWBAQTKFQNK4W7Q4CTRCX",
|
|
|
|
"language": "language_2",
|
|
|
|
"name": "name_2",
|
|
|
|
"stt_engine": "stt_engine_2",
|
|
|
|
"stt_language": "language_2",
|
|
|
|
"tts_engine": "tts_engine_2",
|
|
|
|
"tts_language": "language_2",
|
|
|
|
"tts_voice": "The Voice",
|
|
|
|
"wake_word_entity": None,
|
|
|
|
"wake_word_id": None,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"conversation_engine": "conversation_engine_3",
|
|
|
|
"conversation_language": "language_3",
|
|
|
|
"id": "01GX8ZWBAQSV1HP3WGJPFWEJ8J",
|
|
|
|
"language": "language_3",
|
|
|
|
"name": "name_3",
|
|
|
|
"stt_engine": None,
|
|
|
|
"stt_language": None,
|
|
|
|
"tts_engine": None,
|
|
|
|
"tts_language": None,
|
|
|
|
"tts_voice": None,
|
|
|
|
"wake_word_entity": None,
|
|
|
|
"wake_word_id": None,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
"preferred_item": "01GX8ZWBAQYWNB1XV3EXEZ75DY",
|
|
|
|
}
|
|
|
|
|
2018-09-20 21:46:51 +00:00
|
|
|
|
2019-06-21 09:17:21 +00:00
|
|
|
async def mock_cloud(hass, config=None):
|
2018-09-20 21:46:51 +00:00
|
|
|
"""Mock cloud."""
|
2023-04-28 12:27:06 +00:00
|
|
|
# The homeassistant integration is needed by cloud. It's not in it's requirements
|
|
|
|
# because it's always setup by bootstrap. Set it up manually in tests.
|
|
|
|
assert await async_setup_component(hass, "homeassistant", {})
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
assert await async_setup_component(hass, cloud.DOMAIN, {"cloud": config or {}})
|
2023-12-21 12:39:02 +00:00
|
|
|
cloud_inst: Cloud = hass.data["cloud"]
|
2020-04-30 23:31:00 +00:00
|
|
|
with patch("hass_nabucasa.Cloud.run_executor", AsyncMock(return_value=None)):
|
2021-09-01 16:54:54 +00:00
|
|
|
await cloud_inst.initialize()
|
2018-09-20 21:46:51 +00:00
|
|
|
|
|
|
|
|
2024-06-13 08:30:44 +00:00
|
|
|
def mock_cloud_prefs(hass, prefs):
|
2018-09-20 21:46:51 +00:00
|
|
|
"""Fixture for cloud component."""
|
|
|
|
prefs_to_set = {
|
2023-04-06 17:09:45 +00:00
|
|
|
const.PREF_ALEXA_SETTINGS_VERSION: cloud_prefs.ALEXA_SETTINGS_VERSION,
|
2018-11-20 22:23:07 +00:00
|
|
|
const.PREF_ENABLE_ALEXA: True,
|
|
|
|
const.PREF_ENABLE_GOOGLE: True,
|
2019-04-19 21:50:21 +00:00
|
|
|
const.PREF_GOOGLE_SECURE_DEVICES_PIN: None,
|
2023-04-06 17:09:45 +00:00
|
|
|
const.PREF_GOOGLE_SETTINGS_VERSION: cloud_prefs.GOOGLE_SETTINGS_VERSION,
|
2018-09-20 21:46:51 +00:00
|
|
|
}
|
|
|
|
prefs_to_set.update(prefs)
|
2019-03-11 19:21:20 +00:00
|
|
|
hass.data[cloud.DOMAIN].client._prefs._prefs = prefs_to_set
|
2019-10-13 21:16:27 +00:00
|
|
|
return hass.data[cloud.DOMAIN].client._prefs
|