From bf26b75d27e28ac2e04d7f36e1ac762d964b7513 Mon Sep 17 00:00:00 2001 From: milanvo Date: Sat, 21 Oct 2017 21:59:05 +0200 Subject: [PATCH] Change persistent notification to avoid long text in entity state (#9967) * Change persistent notification to avoid long text in entity state * Tests for changed persistent notification * Persistent notification state * Test for component state --- .../components/persistent_notification/__init__.py | 6 +++++- tests/components/persistent_notification/test_init.py | 9 +++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/homeassistant/components/persistent_notification/__init__.py b/homeassistant/components/persistent_notification/__init__.py index 0c4674f89cc..aaba6e42de3 100644 --- a/homeassistant/components/persistent_notification/__init__.py +++ b/homeassistant/components/persistent_notification/__init__.py @@ -43,6 +43,8 @@ SCHEMA_SERVICE_DISMISS = vol.Schema({ DEFAULT_OBJECT_ID = 'notification' _LOGGER = logging.getLogger(__name__) +STATE = 'notifying' + @bind_hass def create(hass, message, title=None, notification_id=None): @@ -113,7 +115,9 @@ def async_setup(hass, config): _LOGGER.error('Error rendering message %s: %s', message, ex) message = message.template - hass.states.async_set(entity_id, message, attr) + attr[ATTR_MESSAGE] = message + + hass.states.async_set(entity_id, STATE, attr) @callback def dismiss_service(call): diff --git a/tests/components/persistent_notification/test_init.py b/tests/components/persistent_notification/test_init.py index 75caae0015c..df780675a18 100644 --- a/tests/components/persistent_notification/test_init.py +++ b/tests/components/persistent_notification/test_init.py @@ -29,7 +29,8 @@ class TestPersistentNotification: assert len(entity_ids) == 1 state = self.hass.states.get(entity_ids[0]) - assert state.state == 'Hello World 2' + assert state.state == pn.STATE + assert state.attributes.get('message') == 'Hello World 2' assert state.attributes.get('title') == '2 beers' def test_create_notification_id(self): @@ -41,7 +42,7 @@ class TestPersistentNotification: assert len(self.hass.states.entity_ids()) == 1 state = self.hass.states.get('persistent_notification.beer_2') - assert state.state == 'test' + assert state.attributes.get('message') == 'test' pn.create(self.hass, 'test 2', notification_id='Beer 2') self.hass.block_till_done() @@ -49,7 +50,7 @@ class TestPersistentNotification: # We should have overwritten old one assert len(self.hass.states.entity_ids()) == 1 state = self.hass.states.get('persistent_notification.beer_2') - assert state.state == 'test 2' + assert state.attributes.get('message') == 'test 2' def test_create_template_error(self): """Ensure we output templates if contain error.""" @@ -62,7 +63,7 @@ class TestPersistentNotification: assert len(entity_ids) == 1 state = self.hass.states.get(entity_ids[0]) - assert state.state == '{{ message + 1 }}' + assert state.attributes.get('message') == '{{ message + 1 }}' assert state.attributes.get('title') == '{{ title + 1 }}' def test_dismiss_notification(self):