1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-25 05:26:47 +00:00

Expose notify platform targets as individual services (#2837)

* First pass on providing individual services for all possible targets that a notification platform supports.

* Add a quite hacky first version of notification groups

* Add a docstring for get_targets

* Register group service under notifygroup/ and safely check for notifygroups in config

* Remove notifygroups, because it belongs in its own PR

* Make @balloob requested changes

* get_targets()->targets

* Add tests for notify targets exposed as individual services

* If we dont have a platform name set in configuration, lets use the name of the platform instead of notify

* Fix test docstring.

* Dont use a dictionary for just one value

* No need to double slugify

* targets is now just a list of strings instead of a dict
This commit is contained in:
Robbie Trencheny
2016-08-16 22:05:41 -07:00
committed by Paulus Schoutsen
parent 37561765ff
commit c1ce6855c5
4 changed files with 64 additions and 3 deletions

View File

@@ -22,6 +22,7 @@ class TestNotifyDemo(unittest.TestCase):
}
}))
self.events = []
self.calls = []
def record_event(event):
"""Record event to send notification."""
@@ -33,6 +34,10 @@ class TestNotifyDemo(unittest.TestCase):
""""Stop down everything that was started."""
self.hass.stop()
def record_calls(self, *args):
"""Helper for recording calls."""
self.calls.append(args)
def test_sending_none_message(self):
"""Test send with None as message."""
notify.send_message(self.hass, None)
@@ -93,3 +98,29 @@ data_template:
'sound':
'US-EN-Morgan-Freeman-Roommate-Is-Arriving.wav'}}
} == self.events[0].data
def test_targets_are_services(self):
"""Test that all targets are exposed as individual services."""
self.assertIsNotNone(self.hass.services.has_service("notify", "demo"))
service = "demo_test_target"
self.assertIsNotNone(self.hass.services.has_service("notify", service))
def test_messages_to_targets_route(self):
"""Test message routing to specific target services."""
self.hass.bus.listen_once("notify", self.record_calls)
self.hass.services.call("notify", "demo_test_target",
{'message': 'my message',
'title': 'my title',
'data': {'hello': 'world'}})
self.hass.pool.block_till_done()
data = self.calls[0][0].data
assert {
'message': 'my message',
'target': 'test target',
'title': 'my title',
'data': {'hello': 'world'}
} == data