mirror of
https://github.com/home-assistant/core.git
synced 2025-07-15 01:07:10 +00:00
Move legacy notify setup to use tracked tasks (#113716)
* Move legacy notify setup to a tracked task * fix test * fix test * comment
This commit is contained in:
parent
264e023ab4
commit
10f2d8b4b1
@ -2,8 +2,6 @@
|
|||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import asyncio
|
|
||||||
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
import homeassistant.components.persistent_notification as pn
|
import homeassistant.components.persistent_notification as pn
|
||||||
@ -43,19 +41,14 @@ PLATFORM_SCHEMA = vol.Schema(
|
|||||||
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||||
"""Set up the notify services."""
|
"""Set up the notify services."""
|
||||||
|
|
||||||
platform_setups = async_setup_legacy(hass, config)
|
for setup in async_setup_legacy(hass, config):
|
||||||
|
# Tasks are created as tracked tasks to ensure startup
|
||||||
# We need to add the component here break the deadlock
|
# waits for them to finish, but we explicitly do not
|
||||||
# when setting up integrations from config entries as
|
# want to wait for them to finish here because we want
|
||||||
# they would otherwise wait for notify to be
|
# any config entries that use notify as a base platform
|
||||||
# setup and thus the config entries would not be able to
|
# to be able to start with out having to wait for the
|
||||||
# setup their platforms, but we need to do it after
|
# legacy platforms to finish setting up.
|
||||||
# the dispatcher is connected so we don't miss integrations
|
hass.async_create_task(setup, eager_start=True)
|
||||||
# that are registered before the dispatcher is connected
|
|
||||||
hass.config.components.add(DOMAIN)
|
|
||||||
|
|
||||||
if platform_setups:
|
|
||||||
await asyncio.wait([asyncio.create_task(setup) for setup in platform_setups])
|
|
||||||
|
|
||||||
async def persistent_notification(service: ServiceCall) -> None:
|
async def persistent_notification(service: ServiceCall) -> None:
|
||||||
"""Send notification via the built-in persistent_notify integration."""
|
"""Send notification via the built-in persistent_notify integration."""
|
||||||
|
@ -20,6 +20,7 @@ async def test_bad_config(hass: HomeAssistant) -> None:
|
|||||||
config = {notify.DOMAIN: {"name": "test", "platform": "file"}}
|
config = {notify.DOMAIN: {"name": "test", "platform": "file"}}
|
||||||
with assert_setup_component(0) as handle_config:
|
with assert_setup_component(0) as handle_config:
|
||||||
assert await async_setup_component(hass, notify.DOMAIN, config)
|
assert await async_setup_component(hass, notify.DOMAIN, config)
|
||||||
|
await hass.async_block_till_done()
|
||||||
assert not handle_config[notify.DOMAIN]
|
assert not handle_config[notify.DOMAIN]
|
||||||
|
|
||||||
|
|
||||||
@ -49,6 +50,7 @@ async def test_notify_file(
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
await hass.async_block_till_done()
|
||||||
assert handle_config[notify.DOMAIN]
|
assert handle_config[notify.DOMAIN]
|
||||||
|
|
||||||
freezer.move_to(dt_util.utcnow())
|
freezer.move_to(dt_util.utcnow())
|
||||||
|
@ -49,6 +49,7 @@ async def test_setup_legacy_platform(hass: HomeAssistant) -> None:
|
|||||||
}
|
}
|
||||||
with assert_setup_component(1, notify.DOMAIN):
|
with assert_setup_component(1, notify.DOMAIN):
|
||||||
assert await async_setup_component(hass, notify.DOMAIN, config)
|
assert await async_setup_component(hass, notify.DOMAIN, config)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert hass.services.has_service(notify.DOMAIN, "tts_test")
|
assert hass.services.has_service(notify.DOMAIN, "tts_test")
|
||||||
|
|
||||||
@ -65,6 +66,7 @@ async def test_setup_platform(hass: HomeAssistant) -> None:
|
|||||||
}
|
}
|
||||||
with assert_setup_component(1, notify.DOMAIN):
|
with assert_setup_component(1, notify.DOMAIN):
|
||||||
assert await async_setup_component(hass, notify.DOMAIN, config)
|
assert await async_setup_component(hass, notify.DOMAIN, config)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert hass.services.has_service(notify.DOMAIN, "tts_test")
|
assert hass.services.has_service(notify.DOMAIN, "tts_test")
|
||||||
|
|
||||||
@ -80,6 +82,7 @@ async def test_setup_platform_missing_key(hass: HomeAssistant) -> None:
|
|||||||
}
|
}
|
||||||
with assert_setup_component(0, notify.DOMAIN):
|
with assert_setup_component(0, notify.DOMAIN):
|
||||||
assert await async_setup_component(hass, notify.DOMAIN, config)
|
assert await async_setup_component(hass, notify.DOMAIN, config)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert not hass.services.has_service(notify.DOMAIN, "tts_test")
|
assert not hass.services.has_service(notify.DOMAIN, "tts_test")
|
||||||
|
|
||||||
@ -107,6 +110,8 @@ async def test_setup_legacy_service(hass: HomeAssistant) -> None:
|
|||||||
with assert_setup_component(1, notify.DOMAIN):
|
with assert_setup_component(1, notify.DOMAIN):
|
||||||
assert await async_setup_component(hass, notify.DOMAIN, config)
|
assert await async_setup_component(hass, notify.DOMAIN, config)
|
||||||
|
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
notify.DOMAIN,
|
notify.DOMAIN,
|
||||||
"tts_test",
|
"tts_test",
|
||||||
@ -142,6 +147,8 @@ async def test_setup_service(
|
|||||||
with assert_setup_component(1, notify.DOMAIN):
|
with assert_setup_component(1, notify.DOMAIN):
|
||||||
assert await async_setup_component(hass, notify.DOMAIN, config)
|
assert await async_setup_component(hass, notify.DOMAIN, config)
|
||||||
|
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
notify.DOMAIN,
|
notify.DOMAIN,
|
||||||
"tts_test",
|
"tts_test",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user