Remove service helper (4) (#16892)
* Update media_player * Update lock * Update notify * Update remote * Update scene * Update vacuum * Remove timer helpers * Removed unused legacy helpers
This commit is contained in:
1 parent
d0ddc28f96
commit
dd45e99302
23 files changed
+499
-520
No files matched your search
@@ -0,0 +1,24 @@
|
||||
"""Collection of helper methods.
|
||||
|
||||
All containing methods are legacy helpers that should not be used by new
|
||||
components. Instead call the service directly.
|
||||
"""
|
||||
from homeassistant.components.notify import (
|
||||
ATTR_DATA, ATTR_MESSAGE, ATTR_TITLE, DOMAIN, SERVICE_NOTIFY)
|
||||
from homeassistant.loader import bind_hass
|
||||
|
||||
|
||||
@bind_hass
|
||||
def send_message(hass, message, title=None, data=None):
|
||||
"""Send a notification message."""
|
||||
info = {
|
||||
ATTR_MESSAGE: message
|
||||
}
|
||||
|
||||
if title is not None:
|
||||
info[ATTR_TITLE] = title
|
||||
|
||||
if data is not None:
|
||||
info[ATTR_DATA] = data
|
||||
|
||||
hass.services.call(DOMAIN, SERVICE_NOTIFY, info)
|
||||
@@ -7,7 +7,9 @@ from homeassistant.setup import setup_component
|
||||
from homeassistant.components.notify import demo
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.helpers import discovery, script
|
||||
|
||||
from tests.common import assert_setup_component, get_test_home_assistant
|
||||
from tests.components.notify import common
|
||||
|
||||
CONFIG = {
|
||||
notify.DOMAIN: {
|
||||
@@ -79,7 +81,7 @@ class TestNotifyDemo(unittest.TestCase):
|
||||
def test_sending_none_message(self):
|
||||
"""Test send with None as message."""
|
||||
self._setup_notify()
|
||||
notify.send_message(self.hass, None)
|
||||
common.send_message(self.hass, None)
|
||||
self.hass.block_till_done()
|
||||
self.assertTrue(len(self.events) == 0)
|
||||
|
||||
@@ -87,7 +89,7 @@ class TestNotifyDemo(unittest.TestCase):
|
||||
"""Send a templated message."""
|
||||
self._setup_notify()
|
||||
self.hass.states.set('sensor.temperature', 10)
|
||||
notify.send_message(self.hass, '{{ states.sensor.temperature.state }}',
|
||||
common.send_message(self.hass, '{{ states.sensor.temperature.state }}',
|
||||
'{{ states.sensor.temperature.name }}')
|
||||
self.hass.block_till_done()
|
||||
last_event = self.events[-1]
|
||||
@@ -97,7 +99,7 @@ class TestNotifyDemo(unittest.TestCase):
|
||||
def test_method_forwards_correct_data(self):
|
||||
"""Test that all data from the service gets forwarded to service."""
|
||||
self._setup_notify()
|
||||
notify.send_message(self.hass, 'my message', 'my title',
|
||||
common.send_message(self.hass, 'my message', 'my title',
|
||||
{'hello': 'world'})
|
||||
self.hass.block_till_done()
|
||||
self.assertTrue(len(self.events) == 1)
|
||||
|
||||
Reference in new issue
Block a user