Make notifiers of Alert optional (#80209)
parent
1e75c3829e
commit
ea6368775b
|
@ -68,7 +68,9 @@ ALERT_SCHEMA = vol.Schema(
|
|||
vol.Optional(CONF_DONE_MESSAGE): cv.template,
|
||||
vol.Optional(CONF_TITLE): cv.template,
|
||||
vol.Optional(CONF_DATA): dict,
|
||||
vol.Required(CONF_NOTIFIERS): vol.All(cv.ensure_list, [cv.string]),
|
||||
vol.Optional(CONF_NOTIFIERS, default=list): vol.All(
|
||||
cv.ensure_list, [cv.string]
|
||||
),
|
||||
}
|
||||
)
|
||||
|
||||
|
@ -269,6 +271,9 @@ class Alert(Entity):
|
|||
|
||||
async def _send_notification_message(self, message: Any) -> None:
|
||||
|
||||
if not self._notifiers:
|
||||
return
|
||||
|
||||
msg_payload = {ATTR_MESSAGE: message}
|
||||
|
||||
if self._title_template is not None:
|
||||
|
|
|
@ -28,7 +28,7 @@ from homeassistant.const import (
|
|||
STATE_OFF,
|
||||
STATE_ON,
|
||||
)
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
NAME = "alert_test"
|
||||
|
@ -223,6 +223,42 @@ async def test_notification(hass):
|
|||
assert len(events) == 2
|
||||
|
||||
|
||||
async def test_no_notifiers(hass: HomeAssistant) -> None:
|
||||
"""Test we send no notifications when there are not no."""
|
||||
events = []
|
||||
|
||||
@callback
|
||||
def record_event(event):
|
||||
"""Add recorded event to set."""
|
||||
events.append(event)
|
||||
|
||||
hass.services.async_register(notify.DOMAIN, NOTIFIER, record_event)
|
||||
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
DOMAIN,
|
||||
{
|
||||
DOMAIN: {
|
||||
NAME: {
|
||||
CONF_NAME: NAME,
|
||||
CONF_ENTITY_ID: TEST_ENTITY,
|
||||
CONF_STATE: STATE_ON,
|
||||
CONF_REPEAT: 30,
|
||||
}
|
||||
}
|
||||
},
|
||||
)
|
||||
assert len(events) == 0
|
||||
|
||||
hass.states.async_set("sensor.test", STATE_ON)
|
||||
await hass.async_block_till_done()
|
||||
assert len(events) == 0
|
||||
|
||||
hass.states.async_set("sensor.test", STATE_OFF)
|
||||
await hass.async_block_till_done()
|
||||
assert len(events) == 0
|
||||
|
||||
|
||||
async def test_sending_non_templated_notification(hass, mock_notifier):
|
||||
"""Test notifications."""
|
||||
assert await async_setup_component(hass, DOMAIN, TEST_CONFIG)
|
||||
|
|
Loading…
Reference in New Issue