diff --git a/homeassistant/components/notify/__init__.py b/homeassistant/components/notify/__init__.py index 9fb6ca1f842..424d84c0e91 100644 --- a/homeassistant/components/notify/__init__.py +++ b/homeassistant/components/notify/__init__.py @@ -112,8 +112,8 @@ def setup(hass, config): if hasattr(notify_service, 'targets'): platform_name = (p_config.get(CONF_NAME) or platform) - for target in notify_service.targets: - target_name = slugify("{}_{}".format(platform_name, target)) + for name, target in notify_service.targets.items(): + target_name = slugify("{}_{}".format(platform_name, name)) targets[target_name] = target hass.services.register(DOMAIN, target_name, service_call_handler, diff --git a/homeassistant/components/notify/demo.py b/homeassistant/components/notify/demo.py index 8ad74b1ac8e..65e9c3ef9a0 100644 --- a/homeassistant/components/notify/demo.py +++ b/homeassistant/components/notify/demo.py @@ -25,7 +25,7 @@ class DemoNotificationService(BaseNotificationService): @property def targets(self): """Return a dictionary of registered targets.""" - return ["test target"] + return {"test target name": "test target id"} def send_message(self, message="", **kwargs): """Send a message to a user.""" diff --git a/homeassistant/components/notify/html5.py b/homeassistant/components/notify/html5.py index 6ee60512631..0cf7028351b 100644 --- a/homeassistant/components/notify/html5.py +++ b/homeassistant/components/notify/html5.py @@ -314,7 +314,10 @@ class HTML5NotificationService(BaseNotificationService): @property def targets(self): """Return a dictionary of registered targets.""" - return self.registrations.keys() + targets = {} + for registration in self.registrations: + targets[registration] = registration + return targets # pylint: disable=too-many-locals def send_message(self, message="", **kwargs): diff --git a/tests/components/notify/test_demo.py b/tests/components/notify/test_demo.py index ddf5644c399..b996b479ef9 100644 --- a/tests/components/notify/test_demo.py +++ b/tests/components/notify/test_demo.py @@ -134,14 +134,14 @@ data_template: 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" + service = "demo_test_target_name" 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", + self.hass.services.call("notify", "demo_test_target_name", {'message': 'my message', 'title': 'my title', 'data': {'hello': 'world'}}) @@ -152,7 +152,7 @@ data_template: assert { 'message': 'my message', - 'target': 'test target', + 'target': 'test target id', 'title': 'my title', 'data': {'hello': 'world'} } == data