'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}]}}})
    script.toggle(self.hass, ENTITY_ID)
    self.hass.block_till_done()
    self.assertTrue(script.is_on(self.hass, ENTITY_ID))
    self.assertEqual(0, len(events))
    script.toggle(self.hass, ENTITY_ID)
    self.hass.block_till_done()
    self.assertFalse(script.is_on(self.hass, ENTITY_ID))
    self.assertEqual(0, len(events))
