mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 20:57:21 +00:00
Ensure mobile_app notifications get re-registered after adding,removing,adding (#39362)
This commit is contained in:
parent
a99efcb5c2
commit
92c06f0818
@ -66,7 +66,12 @@ async def async_reload(hass, integration_name):
|
||||
):
|
||||
return
|
||||
|
||||
data = hass.data[NOTIFY_SERVICES][integration_name]
|
||||
for data in hass.data[NOTIFY_SERVICES][integration_name]:
|
||||
await _async_setup_notify_services(hass, data)
|
||||
|
||||
|
||||
async def _async_setup_notify_services(hass, data):
|
||||
"""Create or remove the notify services."""
|
||||
notify_service = data[SERVICE]
|
||||
friendly_name = data[FRIENDLY_NAME]
|
||||
targets = data[TARGETS]
|
||||
@ -94,6 +99,7 @@ async def async_reload(hass, integration_name):
|
||||
)
|
||||
|
||||
for stale_target_name in stale_targets:
|
||||
del targets[stale_target_name]
|
||||
hass.services.async_remove(
|
||||
DOMAIN,
|
||||
stale_target_name,
|
||||
@ -187,12 +193,11 @@ async def async_setup(hass, config):
|
||||
target_friendly_name = (
|
||||
p_config.get(CONF_NAME) or discovery_info.get(CONF_NAME) or integration_name
|
||||
)
|
||||
|
||||
friendly_name = (
|
||||
p_config.get(CONF_NAME) or discovery_info.get(CONF_NAME) or SERVICE_NOTIFY
|
||||
)
|
||||
|
||||
hass.data[NOTIFY_SERVICES][integration_name] = {
|
||||
data = {
|
||||
FRIENDLY_NAME: friendly_name,
|
||||
# The targets use a slightly different friendly name
|
||||
# selection pattern than the base service
|
||||
@ -200,8 +205,10 @@ async def async_setup(hass, config):
|
||||
SERVICE: notify_service,
|
||||
TARGETS: {},
|
||||
}
|
||||
hass.data[NOTIFY_SERVICES].setdefault(integration_name, [])
|
||||
hass.data[NOTIFY_SERVICES][integration_name].append(data)
|
||||
|
||||
await async_reload(hass, integration_name)
|
||||
await _async_setup_notify_services(hass, data)
|
||||
|
||||
hass.config.components.add(f"{DOMAIN}.{integration_name}")
|
||||
|
||||
|
@ -96,6 +96,13 @@ async def setup_push_receiver(hass, aioclient_mock):
|
||||
assert hass.services.has_service("notify", "mobile_app_test")
|
||||
assert not hass.services.has_service("notify", "mobile_app_loaded_late")
|
||||
|
||||
loaded_late_entry.add_to_hass(hass)
|
||||
assert await hass.config_entries.async_setup(loaded_late_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert hass.services.has_service("notify", "mobile_app_test")
|
||||
assert hass.services.has_service("notify", "mobile_app_loaded_late")
|
||||
|
||||
|
||||
async def test_notify_works(hass, aioclient_mock, setup_push_receiver):
|
||||
"""Test notify works."""
|
||||
|
Loading…
x
Reference in New Issue
Block a user