Wait for MQTT entry on snips integration startup (#81733)

Wait for MQTT integration to load
This commit is contained in:
Jan Bouwhuis 2022-11-20 16:17:45 +01:00 committed by GitHub
parent 7801cd96de
commit 5c00b8b823
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 0 deletions

View file

@ -90,6 +90,14 @@ SERVICE_SCHEMA_FEEDBACK = vol.Schema(
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
"""Activate Snips component."""
# Make sure MQTT is available and the entry is loaded
if not hass.config_entries.async_entries(
mqtt.DOMAIN
) or not await hass.config_entries.async_wait_component(
hass.config_entries.async_entries(mqtt.DOMAIN)[0]
):
_LOGGER.error("MQTT integration is not available")
return False
async def async_set_feedback(site_ids, state):
"""Set Feedback sound state."""

View file

@ -28,6 +28,23 @@ async def test_snips_config(hass, mqtt_mock):
assert result
async def test_snips_no_mqtt(hass, caplog):
"""Test Snips Config."""
result = await async_setup_component(
hass,
"snips",
{
"snips": {
"feedback_sounds": True,
"probability_threshold": 0.5,
"site_ids": ["default", "remote"],
}
},
)
assert not result
assert "MQTT integration is not available" in caplog.text
async def test_snips_bad_config(hass, mqtt_mock):
"""Test Snips bad config."""
result = await async_setup_component(