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}]}}})
    turn_on(self.hass, ENTITY_ID)
    self.hass.block_till_done()
    assert script.is_on(self.hass, ENTITY_ID)
    assert (0 == len(events))
    turn_on(self.hass, ENTITY_ID)
    self.hass.block_till_done()
    assert (0 == len(events))
    turn_off(self.hass, ENTITY_ID)
    self.hass.block_till_done()
    assert (not script.is_on(self.hass, ENTITY_ID))
    assert (0 == len(events))
    state = self.hass.states.get('group.all_scripts')
    assert (state is not None)
    assert (state.attributes.get('entity_id') == (ENTITY_ID,))
Verify that the turn_on service.
def test_turn_on_service(self):
    
    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}]}}})
    turn_on(self.hass, ENTITY_ID)
    self.hass.block_till_done()
    assert script.is_on(self.hass, ENTITY_ID)
    assert (0 == len(events))
    turn_on(self.hass, ENTITY_ID)
    self.hass.block_till_done()
    assert (0 == len(events))
    turn_off(self.hass, ENTITY_ID)
    self.hass.block_till_done()
    assert (not script.is_on(self.hass, ENTITY_ID))
    assert (0 == len(events))
    state = self.hass.states.get('group.all_scripts')
    assert (state is not None)
    assert (state.attributes.get('entity_id') == (ENTITY_ID,))