diff --git a/homeassistant/components/notify/file.py b/homeassistant/components/notify/file.py index 3d04bf13334..3e2f20707ad 100644 --- a/homeassistant/components/notify/file.py +++ b/homeassistant/components/notify/file.py @@ -7,24 +7,28 @@ https://home-assistant.io/components/notify.file/ import logging import os +import voluptuous as vol + import homeassistant.util.dt as dt_util from homeassistant.components.notify import ( - ATTR_TITLE, DOMAIN, BaseNotificationService) -from homeassistant.helpers import validate_config + ATTR_TITLE, PLATFORM_SCHEMA, BaseNotificationService) +from homeassistant.const import CONF_FILENAME +import homeassistant.helpers.config_validation as cv + +CONF_TIMESTAMP = 'timestamp' + +PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ + vol.Required(CONF_FILENAME): cv.string, + vol.Optional(CONF_TIMESTAMP, default=False): cv.boolean, +}) _LOGGER = logging.getLogger(__name__) def get_service(hass, config): """Get the file notification service.""" - if not validate_config({DOMAIN: config}, - {DOMAIN: ['filename', - 'timestamp']}, - _LOGGER): - return None - - filename = config['filename'] - timestamp = config['timestamp'] + filename = config[CONF_FILENAME] + timestamp = config[CONF_TIMESTAMP] return FileNotificationService(hass, filename, timestamp) @@ -48,7 +52,7 @@ class FileNotificationService(BaseNotificationService): '-' * 80) file.write(title) - if self.add_timestamp == 1: + if self.add_timestamp: text = '{} {}\n'.format(dt_util.utcnow().isoformat(), message) file.write(text) else: diff --git a/tests/components/notify/test_file.py b/tests/components/notify/test_file.py index 87d275b05f9..2564b0bd65a 100644 --- a/tests/components/notify/test_file.py +++ b/tests/components/notify/test_file.py @@ -8,6 +8,7 @@ import homeassistant.components.notify as notify from homeassistant.components.notify import ( ATTR_TITLE_DEFAULT) import homeassistant.util.dt as dt_util +from homeassistant.bootstrap import _setup_component from tests.common import get_test_home_assistant @@ -25,11 +26,11 @@ class TestNotifyFile(unittest.TestCase): def test_bad_config(self): """Test set up the platform with bad/missing config.""" - self.assertFalse(notify.setup(self.hass, { + self.assertFalse(_setup_component(self.hass, notify.DOMAIN, { 'notify': { 'name': 'test', 'platform': 'file', - } + }, })) @patch('homeassistant.util.dt.utcnow') @@ -45,7 +46,7 @@ class TestNotifyFile(unittest.TestCase): 'name': 'test', 'platform': 'file', 'filename': filename, - 'timestamp': 0 + 'timestamp': False, } })) title = '{} notifications (Log started: {})\n{}\n'.format(