Script: new attribute if can cancel
parent
eabf9087f3
commit
e2c530b85d
|
@ -37,6 +37,7 @@ CONF_EVENT_DATA = "event_data"
|
|||
CONF_DELAY = "delay"
|
||||
|
||||
ATTR_LAST_ACTION = 'last_action'
|
||||
ATTR_CAN_CANCEL = 'can_cancel'
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
@ -113,6 +114,8 @@ class Script(ToggleEntity):
|
|||
self._cur = -1
|
||||
self._last_action = None
|
||||
self._listener = None
|
||||
self._can_cancel = not any(CONF_DELAY in action for action
|
||||
in self.sequence)
|
||||
|
||||
@property
|
||||
def should_poll(self):
|
||||
|
@ -126,7 +129,9 @@ class Script(ToggleEntity):
|
|||
@property
|
||||
def state_attributes(self):
|
||||
""" Returns the state attributes. """
|
||||
attrs = {}
|
||||
attrs = {
|
||||
ATTR_CAN_CANCEL: self._can_cancel
|
||||
}
|
||||
|
||||
if self._last_action:
|
||||
attrs[ATTR_LAST_ACTION] = self._last_action
|
||||
|
|
|
@ -88,6 +88,8 @@ class TestScript(unittest.TestCase):
|
|||
|
||||
self.assertEqual(1, len(calls))
|
||||
self.assertEqual('world', calls[0].data.get('hello'))
|
||||
self.assertEqual(
|
||||
True, self.hass.states.get(ENTITY_ID).attributes.get('can_cancel'))
|
||||
|
||||
def test_calling_service_old(self):
|
||||
calls = []
|
||||
|
@ -172,6 +174,9 @@ class TestScript(unittest.TestCase):
|
|||
self.hass.pool.block_till_done()
|
||||
|
||||
self.assertTrue(script.is_on(self.hass, ENTITY_ID))
|
||||
self.assertEqual(
|
||||
False,
|
||||
self.hass.states.get(ENTITY_ID).attributes.get('can_cancel'))
|
||||
|
||||
self.assertEqual(
|
||||
event,
|
||||
|
|
Loading…
Reference in New Issue