Merge pull request #1429 from balloob/fix-script-can_cancel
Fix incorrectly setting can_cancel on scripts
This commit is contained in:
commit
5acf995d71
2 changed files with 8 additions and 11 deletions
|
@ -131,8 +131,8 @@ class Script(ToggleEntity):
|
||||||
self._cur = -1
|
self._cur = -1
|
||||||
self._last_action = None
|
self._last_action = None
|
||||||
self._listener = None
|
self._listener = None
|
||||||
self._can_cancel = not any(CONF_DELAY in action for action
|
self._can_cancel = any(CONF_DELAY in action for action
|
||||||
in self.sequence)
|
in self.sequence)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def should_poll(self):
|
def should_poll(self):
|
||||||
|
@ -146,13 +146,11 @@ class Script(ToggleEntity):
|
||||||
@property
|
@property
|
||||||
def state_attributes(self):
|
def state_attributes(self):
|
||||||
""" Returns the state attributes. """
|
""" Returns the state attributes. """
|
||||||
attrs = {
|
attrs = {}
|
||||||
ATTR_CAN_CANCEL: self._can_cancel
|
if self._can_cancel:
|
||||||
}
|
attrs[ATTR_CAN_CANCEL] = self._can_cancel
|
||||||
|
|
||||||
if self._last_action:
|
if self._last_action:
|
||||||
attrs[ATTR_LAST_ACTION] = self._last_action
|
attrs[ATTR_LAST_ACTION] = self._last_action
|
||||||
|
|
||||||
return attrs
|
return attrs
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|
|
@ -88,8 +88,8 @@ class TestScript(unittest.TestCase):
|
||||||
|
|
||||||
self.assertEqual(1, len(calls))
|
self.assertEqual(1, len(calls))
|
||||||
self.assertEqual('world', calls[0].data.get('hello'))
|
self.assertEqual('world', calls[0].data.get('hello'))
|
||||||
self.assertEqual(
|
self.assertIsNone(
|
||||||
True, self.hass.states.get(ENTITY_ID).attributes.get('can_cancel'))
|
self.hass.states.get(ENTITY_ID).attributes.get('can_cancel'))
|
||||||
|
|
||||||
def test_calling_service_old(self):
|
def test_calling_service_old(self):
|
||||||
calls = []
|
calls = []
|
||||||
|
@ -174,8 +174,7 @@ class TestScript(unittest.TestCase):
|
||||||
self.hass.pool.block_till_done()
|
self.hass.pool.block_till_done()
|
||||||
|
|
||||||
self.assertTrue(script.is_on(self.hass, ENTITY_ID))
|
self.assertTrue(script.is_on(self.hass, ENTITY_ID))
|
||||||
self.assertEqual(
|
self.assertTrue(
|
||||||
False,
|
|
||||||
self.hass.states.get(ENTITY_ID).attributes.get('can_cancel'))
|
self.hass.states.get(ENTITY_ID).attributes.get('can_cancel'))
|
||||||
|
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
|
|
Loading…
Add table
Reference in a new issue