mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Change notify target property to be a dictionary (#3501)
* Change notify target property to be a dictionary * Make demo target properties unique and fix test to match behavior
This commit is contained in:
parent
986873834a
commit
b3d67a7ed9
@ -112,8 +112,8 @@ def setup(hass, config):
|
|||||||
|
|
||||||
if hasattr(notify_service, 'targets'):
|
if hasattr(notify_service, 'targets'):
|
||||||
platform_name = (p_config.get(CONF_NAME) or platform)
|
platform_name = (p_config.get(CONF_NAME) or platform)
|
||||||
for target in notify_service.targets:
|
for name, target in notify_service.targets.items():
|
||||||
target_name = slugify("{}_{}".format(platform_name, target))
|
target_name = slugify("{}_{}".format(platform_name, name))
|
||||||
targets[target_name] = target
|
targets[target_name] = target
|
||||||
hass.services.register(DOMAIN, target_name,
|
hass.services.register(DOMAIN, target_name,
|
||||||
service_call_handler,
|
service_call_handler,
|
||||||
|
@ -25,7 +25,7 @@ class DemoNotificationService(BaseNotificationService):
|
|||||||
@property
|
@property
|
||||||
def targets(self):
|
def targets(self):
|
||||||
"""Return a dictionary of registered targets."""
|
"""Return a dictionary of registered targets."""
|
||||||
return ["test target"]
|
return {"test target name": "test target id"}
|
||||||
|
|
||||||
def send_message(self, message="", **kwargs):
|
def send_message(self, message="", **kwargs):
|
||||||
"""Send a message to a user."""
|
"""Send a message to a user."""
|
||||||
|
@ -314,7 +314,10 @@ class HTML5NotificationService(BaseNotificationService):
|
|||||||
@property
|
@property
|
||||||
def targets(self):
|
def targets(self):
|
||||||
"""Return a dictionary of registered targets."""
|
"""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
|
# pylint: disable=too-many-locals
|
||||||
def send_message(self, message="", **kwargs):
|
def send_message(self, message="", **kwargs):
|
||||||
|
@ -134,14 +134,14 @@ data_template:
|
|||||||
def test_targets_are_services(self):
|
def test_targets_are_services(self):
|
||||||
"""Test that all targets are exposed as individual services."""
|
"""Test that all targets are exposed as individual services."""
|
||||||
self.assertIsNotNone(self.hass.services.has_service("notify", "demo"))
|
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))
|
self.assertIsNotNone(self.hass.services.has_service("notify", service))
|
||||||
|
|
||||||
def test_messages_to_targets_route(self):
|
def test_messages_to_targets_route(self):
|
||||||
"""Test message routing to specific target services."""
|
"""Test message routing to specific target services."""
|
||||||
self.hass.bus.listen_once("notify", self.record_calls)
|
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',
|
{'message': 'my message',
|
||||||
'title': 'my title',
|
'title': 'my title',
|
||||||
'data': {'hello': 'world'}})
|
'data': {'hello': 'world'}})
|
||||||
@ -152,7 +152,7 @@ data_template:
|
|||||||
|
|
||||||
assert {
|
assert {
|
||||||
'message': 'my message',
|
'message': 'my message',
|
||||||
'target': 'test target',
|
'target': 'test target id',
|
||||||
'title': 'my title',
|
'title': 'my title',
|
||||||
'data': {'hello': 'world'}
|
'data': {'hello': 'world'}
|
||||||
} == data
|
} == data
|
||||||
|
Loading…
x
Reference in New Issue
Block a user