mirror of
https://github.com/home-assistant/core.git
synced 2025-12-26 22:18:40 +00:00
Add discovery notify support and mysensors notify (#5219)
* Add mysensors notify platform * Make add_devices optional in platform callback function. * Use new argument structure for all existing mysensors platforms. * Add notify platform. * Update mysensors gateway. * Refactor notify setup * Enable discovery of notify platforms. * Update and add tests for notify component and some platforms. * Continue setup of notify platforms if a platform fails setup. * Remove notify tests that check platform config. These tests are not needed when config validation is used. * Add config validation to APNS notify platform. * Use discovery to set up mysensors notify platform. * Add discovery_info to get_service and update tests * Add discovery_info as keyword argument to the get_service function signature and update all notify platforms. * Update existing notify tests to check config validation using test helper. * Add removed tests back in that checked config in apns, command_line and file platforms, but use config validation test helper to verify config. * Add a test for notify file to increase coverage. * Fix some PEP issues. * Fix comments and use more constants * Move apns notify service under notify domain
This commit is contained in:
@@ -6,7 +6,7 @@ from unittest.mock import patch
|
||||
|
||||
from homeassistant.bootstrap import setup_component
|
||||
import homeassistant.components.notify as notify
|
||||
from tests.common import get_test_home_assistant
|
||||
from tests.common import assert_setup_component, get_test_home_assistant
|
||||
|
||||
|
||||
class TestCommandLine(unittest.TestCase):
|
||||
@@ -22,34 +22,41 @@ class TestCommandLine(unittest.TestCase):
|
||||
|
||||
def test_setup(self):
|
||||
"""Test setup."""
|
||||
assert setup_component(self.hass, 'notify', {
|
||||
'notify': {
|
||||
'name': 'test',
|
||||
'platform': 'command_line',
|
||||
'command': 'echo $(cat); exit 1',
|
||||
}})
|
||||
with assert_setup_component(1) as handle_config:
|
||||
assert setup_component(self.hass, 'notify', {
|
||||
'notify': {
|
||||
'name': 'test',
|
||||
'platform': 'command_line',
|
||||
'command': 'echo $(cat); exit 1', }
|
||||
})
|
||||
assert handle_config[notify.DOMAIN]
|
||||
|
||||
def test_bad_config(self):
|
||||
"""Test set up the platform with bad/missing configuration."""
|
||||
self.assertFalse(setup_component(self.hass, notify.DOMAIN, {
|
||||
'notify': {
|
||||
config = {
|
||||
notify.DOMAIN: {
|
||||
'name': 'test',
|
||||
'platform': 'bad_platform',
|
||||
'platform': 'command_line',
|
||||
}
|
||||
}))
|
||||
}
|
||||
with assert_setup_component(0) as handle_config:
|
||||
assert setup_component(self.hass, notify.DOMAIN, config)
|
||||
assert not handle_config[notify.DOMAIN]
|
||||
|
||||
def test_command_line_output(self):
|
||||
"""Test the command line output."""
|
||||
with tempfile.TemporaryDirectory() as tempdirname:
|
||||
filename = os.path.join(tempdirname, 'message.txt')
|
||||
message = 'one, two, testing, testing'
|
||||
self.assertTrue(setup_component(self.hass, notify.DOMAIN, {
|
||||
'notify': {
|
||||
'name': 'test',
|
||||
'platform': 'command_line',
|
||||
'command': 'echo $(cat) > {}'.format(filename)
|
||||
}
|
||||
}))
|
||||
with assert_setup_component(1) as handle_config:
|
||||
self.assertTrue(setup_component(self.hass, notify.DOMAIN, {
|
||||
'notify': {
|
||||
'name': 'test',
|
||||
'platform': 'command_line',
|
||||
'command': 'echo $(cat) > {}'.format(filename)
|
||||
}
|
||||
}))
|
||||
assert handle_config[notify.DOMAIN]
|
||||
|
||||
self.assertTrue(
|
||||
self.hass.services.call('notify', 'test', {'message': message},
|
||||
@@ -63,13 +70,15 @@ class TestCommandLine(unittest.TestCase):
|
||||
@patch('homeassistant.components.notify.command_line._LOGGER.error')
|
||||
def test_error_for_none_zero_exit_code(self, mock_error):
|
||||
"""Test if an error is logged for non zero exit codes."""
|
||||
self.assertTrue(setup_component(self.hass, notify.DOMAIN, {
|
||||
'notify': {
|
||||
'name': 'test',
|
||||
'platform': 'command_line',
|
||||
'command': 'echo $(cat); exit 1'
|
||||
}
|
||||
}))
|
||||
with assert_setup_component(1) as handle_config:
|
||||
self.assertTrue(setup_component(self.hass, notify.DOMAIN, {
|
||||
'notify': {
|
||||
'name': 'test',
|
||||
'platform': 'command_line',
|
||||
'command': 'echo $(cat); exit 1'
|
||||
}
|
||||
}))
|
||||
assert handle_config[notify.DOMAIN]
|
||||
|
||||
self.assertTrue(
|
||||
self.hass.services.call('notify', 'test', {'message': 'error'},
|
||||
|
||||
Reference in New Issue
Block a user