def test_turn_on_service(self): """Verify that the turn_on service.""" event = "test_event" events = [] @callback def record_event(event): """Add recorded event to set.""" events.append(event) self.hass.bus.listen(event, record_event) assert setup_component( self.hass, "script", {"script": {"test": {"sequence": [{"delay": {"seconds": 5}}, {"event": event}]}}} ) script.turn_on(self.hass, ENTITY_ID) self.hass.block_till_done() self.assertTrue(script.is_on(self.hass, ENTITY_ID)) self.assertEqual(0, len(events)) # Calling turn_on a second time should not advance the script script.turn_on(self.hass, ENTITY_ID) self.hass.block_till_done() self.assertEqual(0, len(events)) script.turn_off(self.hass, ENTITY_ID) self.hass.block_till_done() self.assertFalse(script.is_on(self.hass, ENTITY_ID)) self.assertEqual(0, len(events)) state = self.hass.states.get("group.all_scripts") assert state is not None assert state.attributes.get("entity_id") == (ENTITY_ID,)
def test_cancel_while_delay(self): """Test the cancelling while the delay is present.""" event = 'test_event' calls = [] def record_event(event): """Add recorded event to set.""" calls.append(event) self.hass.bus.listen(event, record_event) self.assertTrue( script.setup( self.hass, { 'script': { 'test': { 'sequence': [{ 'delay': { 'seconds': 5 } }, { 'event': event, }] } } })) script.turn_on(self.hass, ENTITY_ID) self.hass.pool.block_till_done() self.assertTrue(script.is_on(self.hass, ENTITY_ID)) self.assertEqual(0, len(calls)) script.turn_off(self.hass, ENTITY_ID) self.hass.pool.block_till_done() self.assertFalse(script.is_on(self.hass, ENTITY_ID)) future = dt_util.utcnow() + timedelta(seconds=5) fire_time_changed(self.hass, future) self.hass.pool.block_till_done() self.assertFalse(script.is_on(self.hass, ENTITY_ID)) self.assertEqual(0, len(calls))
def test_turn_on_service(self): """Verify that the turn_on service.""" event = 'test_event' events = [] @callback def record_event(event): """Add recorded event to set.""" events.append(event) self.hass.bus.listen(event, record_event) assert setup_component( self.hass, 'script', { 'script': { 'test': { 'sequence': [{ 'delay': { 'seconds': 5 } }, { 'event': event, }] } } }) script.turn_on(self.hass, ENTITY_ID) self.hass.block_till_done() self.assertTrue(script.is_on(self.hass, ENTITY_ID)) self.assertEqual(0, len(events)) # Calling turn_on a second time should not advance the script script.turn_on(self.hass, ENTITY_ID) self.hass.block_till_done() self.assertEqual(0, len(events)) script.turn_off(self.hass, ENTITY_ID) self.hass.block_till_done() self.assertFalse(script.is_on(self.hass, ENTITY_ID)) self.assertEqual(0, len(events)) state = self.hass.states.get('group.all_scripts') assert state is not None assert state.attributes.get('entity_id') == (ENTITY_ID, )
def test_turn_on_service(self): """Verify that the turn_on service.""" event = 'test_event' events = [] @callback def record_event(event): """Add recorded event to set.""" events.append(event) self.hass.bus.listen(event, record_event) assert setup_component(self.hass, 'script', { 'script': { 'test': { 'sequence': [{ 'delay': { 'seconds': 5 } }, { 'event': event, }] } } }) script.turn_on(self.hass, ENTITY_ID) self.hass.block_till_done() self.assertTrue(script.is_on(self.hass, ENTITY_ID)) self.assertEqual(0, len(events)) # Calling turn_on a second time should not advance the script script.turn_on(self.hass, ENTITY_ID) self.hass.block_till_done() self.assertEqual(0, len(events)) script.turn_off(self.hass, ENTITY_ID) self.hass.block_till_done() self.assertFalse(script.is_on(self.hass, ENTITY_ID)) self.assertEqual(0, len(events)) state = self.hass.states.get('group.all_scripts') assert state is not None assert state.attributes.get('entity_id') == (ENTITY_ID,)
def test_cancel_while_delay(self): """Test the cancelling while the delay is present.""" event = 'test_event' calls = [] def record_event(event): """Add recorded event to set.""" calls.append(event) self.hass.bus.listen(event, record_event) assert _setup_component(self.hass, 'script', { 'script': { 'test': { 'sequence': [{ 'delay': { 'seconds': 5 } }, { 'event': event, }] } } }) script.turn_on(self.hass, ENTITY_ID) self.hass.pool.block_till_done() self.assertTrue(script.is_on(self.hass, ENTITY_ID)) self.assertEqual(0, len(calls)) script.turn_off(self.hass, ENTITY_ID) self.hass.pool.block_till_done() self.assertFalse(script.is_on(self.hass, ENTITY_ID)) future = dt_util.utcnow() + timedelta(seconds=5) fire_time_changed(self.hass, future) self.hass.pool.block_till_done() self.assertFalse(script.is_on(self.hass, ENTITY_ID)) self.assertEqual(0, len(calls))
def test_cancel_while_delay(self): event = 'test_event' calls = [] def record_event(event): calls.append(event) self.hass.bus.listen(event, record_event) self.assertTrue(script.setup(self.hass, { 'script': { 'test': { 'sequence': [{ 'delay': { 'seconds': 5 } }, { 'event': event, }] } } })) script.turn_on(self.hass, ENTITY_ID) self.hass.pool.block_till_done() self.assertTrue(script.is_on(self.hass, ENTITY_ID)) self.assertEqual(0, len(calls)) script.turn_off(self.hass, ENTITY_ID) self.hass.pool.block_till_done() self.assertFalse(script.is_on(self.hass, ENTITY_ID)) future = dt_util.utcnow() + timedelta(seconds=5) fire_time_changed(self.hass, future) self.hass.pool.block_till_done() self.assertFalse(script.is_on(self.hass, ENTITY_ID)) self.assertEqual(0, len(calls))