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
This commit is contained in:
milanvo 2017-10-21 21:59:05 +02:00 committed by Pascal Vizeli
parent 3ea4691fce
commit bf26b75d27
2 changed files with 10 additions and 5 deletions

View file

@ -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):

View file

@ -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):