mirror of
https://github.com/home-assistant/core.git
synced 2025-07-30 10:48:01 +02:00
fix import issue when there are no notifiers in configuration.yaml
This commit is contained in:
@ -14,6 +14,11 @@ CONFIG_SCHEMA = cv.config_entry_only_config_schema(DOMAIN)
|
||||
|
||||
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
"""Pass notify platform config from configuration.yaml to config flow for import."""
|
||||
|
||||
# Handle scenario where there's no notifiers in configuration.yaml
|
||||
if Platform.NOTIFY not in config:
|
||||
return True
|
||||
|
||||
for notify in config[Platform.NOTIFY]:
|
||||
if notify[CONF_PLATFORM] == DOMAIN: # Only import Telegram notifiers
|
||||
hass.async_create_task(
|
||||
|
@ -1 +1 @@
|
||||
"""Tests for telegram component."""
|
||||
"""Tests for Telegram integration."""
|
||||
|
27
tests/components/telegram/conftest.py
Normal file
27
tests/components/telegram/conftest.py
Normal file
@ -0,0 +1,27 @@
|
||||
"""Fixtures for Telegram integration tests."""
|
||||
|
||||
from unittest.mock import patch
|
||||
|
||||
from homeassistant.components import notify
|
||||
from homeassistant.components.telegram.const import DOMAIN
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
|
||||
async def setup_dependencies(hass: HomeAssistant) -> None:
|
||||
"""Set up the dependencies for the Telegram component."""
|
||||
with patch("homeassistant.components.telegram_bot.async_setup", return_value=True):
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
notify.DOMAIN,
|
||||
{
|
||||
notify.DOMAIN: [
|
||||
{
|
||||
"name": DOMAIN,
|
||||
"platform": DOMAIN,
|
||||
"chat_id": 1,
|
||||
},
|
||||
]
|
||||
},
|
||||
)
|
||||
await hass.async_block_till_done()
|
@ -1,33 +1,17 @@
|
||||
"""Test the Telegram config flow."""
|
||||
|
||||
from unittest.mock import patch
|
||||
|
||||
from homeassistant.components import notify
|
||||
from homeassistant.components.telegram.const import DOMAIN
|
||||
from homeassistant.components.telegram import DOMAIN
|
||||
from homeassistant.config_entries import SOURCE_USER
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.data_entry_flow import FlowResultType
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from .conftest import setup_dependencies
|
||||
|
||||
|
||||
async def test_async_step_user(hass: HomeAssistant) -> None:
|
||||
"""Test config flow."""
|
||||
"""Test config flow form display."""
|
||||
|
||||
with patch("homeassistant.components.telegram_bot.async_setup", return_value=True):
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
notify.DOMAIN,
|
||||
{
|
||||
notify.DOMAIN: [
|
||||
{
|
||||
"name": DOMAIN,
|
||||
"platform": DOMAIN,
|
||||
"chat_id": 1,
|
||||
},
|
||||
]
|
||||
},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
await setup_dependencies(hass)
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_USER}
|
||||
|
@ -7,7 +7,8 @@ from homeassistant.components import notify
|
||||
from homeassistant.components.telegram import DOMAIN
|
||||
from homeassistant.const import SERVICE_RELOAD
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from .conftest import setup_dependencies
|
||||
|
||||
from tests.common import get_fixture_path
|
||||
|
||||
@ -15,21 +16,7 @@ from tests.common import get_fixture_path
|
||||
async def test_reload_notify(hass: HomeAssistant) -> None:
|
||||
"""Verify we can reload the notify service."""
|
||||
|
||||
with patch("homeassistant.components.telegram_bot.async_setup", return_value=True):
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
notify.DOMAIN,
|
||||
{
|
||||
notify.DOMAIN: [
|
||||
{
|
||||
"name": DOMAIN,
|
||||
"platform": DOMAIN,
|
||||
"chat_id": 1,
|
||||
},
|
||||
]
|
||||
},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
await setup_dependencies(hass)
|
||||
|
||||
assert hass.services.has_service(notify.DOMAIN, DOMAIN)
|
||||
|
||||
|
Reference in New Issue
Block a user