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:
1 parent
3b9fb6ccf5
commit
9db1aa7629
51 files changed
+395
-255
No files matched your search
@@ -9,7 +9,7 @@ from homeassistant.components.notify import (
|
||||
ATTR_TITLE_DEFAULT)
|
||||
import homeassistant.util.dt as dt_util
|
||||
|
||||
from tests.common import get_test_home_assistant, assert_setup_component
|
||||
from tests.common import assert_setup_component, get_test_home_assistant
|
||||
|
||||
|
||||
class TestNotifyFile(unittest.TestCase):
|
||||
@@ -25,36 +25,38 @@ class TestNotifyFile(unittest.TestCase):
|
||||
|
||||
def test_bad_config(self):
|
||||
"""Test set up the platform with bad/missing config."""
|
||||
with assert_setup_component(0):
|
||||
assert not setup_component(self.hass, notify.DOMAIN, {
|
||||
'notify': {
|
||||
'name': 'test',
|
||||
'platform': 'file',
|
||||
},
|
||||
})
|
||||
config = {
|
||||
notify.DOMAIN: {
|
||||
'name': 'test',
|
||||
'platform': 'file',
|
||||
},
|
||||
}
|
||||
with assert_setup_component(0) as handle_config:
|
||||
assert setup_component(self.hass, notify.DOMAIN, config)
|
||||
assert not handle_config[notify.DOMAIN]
|
||||
|
||||
@patch('homeassistant.components.notify.file.os.stat')
|
||||
@patch('homeassistant.util.dt.utcnow')
|
||||
def test_notify_file(self, mock_utcnow, mock_stat):
|
||||
def _test_notify_file(self, timestamp, mock_utcnow, mock_stat):
|
||||
"""Test the notify file output."""
|
||||
mock_utcnow.return_value = dt_util.as_utc(dt_util.now())
|
||||
mock_stat.return_value.st_size = 0
|
||||
|
||||
m_open = mock_open()
|
||||
with patch(
|
||||
'homeassistant.components.notify.file.open',
|
||||
m_open, create=True
|
||||
'homeassistant.components.notify.file.open',
|
||||
m_open, create=True
|
||||
):
|
||||
filename = 'mock_file'
|
||||
message = 'one, two, testing, testing'
|
||||
self.assertTrue(setup_component(self.hass, notify.DOMAIN, {
|
||||
'notify': {
|
||||
'name': 'test',
|
||||
'platform': 'file',
|
||||
'filename': filename,
|
||||
'timestamp': False,
|
||||
}
|
||||
}))
|
||||
with assert_setup_component(1) as handle_config:
|
||||
self.assertTrue(setup_component(self.hass, notify.DOMAIN, {
|
||||
'notify': {
|
||||
'name': 'test',
|
||||
'platform': 'file',
|
||||
'filename': filename,
|
||||
'timestamp': timestamp,
|
||||
}
|
||||
}))
|
||||
assert handle_config[notify.DOMAIN]
|
||||
title = '{} notifications (Log started: {})\n{}\n'.format(
|
||||
ATTR_TITLE_DEFAULT,
|
||||
dt_util.utcnow().isoformat(),
|
||||
@@ -68,7 +70,26 @@ class TestNotifyFile(unittest.TestCase):
|
||||
self.assertEqual(m_open.call_args, call(full_filename, 'a'))
|
||||
|
||||
self.assertEqual(m_open.return_value.write.call_count, 2)
|
||||
self.assertEqual(
|
||||
m_open.return_value.write.call_args_list,
|
||||
[call(title), call(message + '\n')]
|
||||
)
|
||||
if not timestamp:
|
||||
self.assertEqual(
|
||||
m_open.return_value.write.call_args_list,
|
||||
[call(title), call('{}\n'.format(message))]
|
||||
)
|
||||
else:
|
||||
self.assertEqual(
|
||||
m_open.return_value.write.call_args_list,
|
||||
[call(title), call('{} {}\n'.format(
|
||||
dt_util.utcnow().isoformat(), message))]
|
||||
)
|
||||
|
||||
@patch('homeassistant.components.notify.file.os.stat')
|
||||
@patch('homeassistant.util.dt.utcnow')
|
||||
def test_notify_file(self, mock_utcnow, mock_stat):
|
||||
"""Test the notify file output without timestamp."""
|
||||
self._test_notify_file(False, mock_utcnow, mock_stat)
|
||||
|
||||
@patch('homeassistant.components.notify.file.os.stat')
|
||||
@patch('homeassistant.util.dt.utcnow')
|
||||
def test_notify_file_timestamp(self, mock_utcnow, mock_stat):
|
||||
"""Test the notify file output with timestamp."""
|
||||
self._test_notify_file(True, mock_utcnow, mock_stat)
|
||||
Reference in new issue
Block a user