def test_toggle_service(self):
    'Test the toggling of a 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}]}}})
    toggle(self.hass, ENTITY_ID)
    self.hass.block_till_done()
    assert script.is_on(self.hass, ENTITY_ID)
    assert (0 == len(events))
    toggle(self.hass, ENTITY_ID)
    self.hass.block_till_done()
    assert (not script.is_on(self.hass, ENTITY_ID))
    assert (0 == len(events))
Test the toggling of a service.
def test_toggle_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}]}}})
    toggle(self.hass, ENTITY_ID)
    self.hass.block_till_done()
    assert script.is_on(self.hass, ENTITY_ID)
    assert (0 == len(events))
    toggle(self.hass, ENTITY_ID)
    self.hass.block_till_done()
    assert (not script.is_on(self.hass, ENTITY_ID))
    assert (0 == len(events))