'Test tracking template.'

def test_track_template(self):

    specific_runs = []
    wildcard_runs = []
    wildercard_runs = []
    template_condition = Template("{{states.switch.test.state    ==    'on'}}", self.hass)
    template_condition_var = Template("{{states.switch.test.state    ==    'on'    and    test    ==    5}}", self.hass)
    self.hass.states.set('switch.test', 'off')
    def specific_run_callback(entity_id, old_state, new_state):
        specific_runs.append(1)
    track_template(self.hass, template_condition, specific_run_callback)
    @ha.callback
    def wildcard_run_callback(entity_id, old_state, new_state):
        wildcard_runs.append((old_state, new_state))
    track_template(self.hass, template_condition, wildcard_run_callback)
    @asyncio.coroutine
    def wildercard_run_callback(entity_id, old_state, new_state):
        wildercard_runs.append((old_state, new_state))
    track_template(self.hass, template_condition_var, wildercard_run_callback, {'test': 5})
    self.hass.states.set('switch.test', 'on')
    self.hass.block_till_done()
    self.assertEqual(1, len(specific_runs))
    self.assertEqual(1, len(wildcard_runs))
    self.assertEqual(1, len(wildercard_runs))
    self.hass.states.set('switch.test', 'on')
    self.hass.block_till_done()
    self.assertEqual(1, len(specific_runs))
    self.assertEqual(1, len(wildcard_runs))
    self.assertEqual(1, len(wildercard_runs))
    self.hass.states.set('switch.test', 'off')
    self.hass.block_till_done()
    self.assertEqual(1, len(specific_runs))
    self.assertEqual(1, len(wildcard_runs))
    self.assertEqual(1, len(wildercard_runs))
    self.hass.states.set('switch.test', 'off')
    self.hass.block_till_done()
    self.assertEqual(1, len(specific_runs))
    self.assertEqual(1, len(wildcard_runs))
    self.assertEqual(1, len(wildercard_runs))
    self.hass.states.set('switch.test', 'on')
    self.hass.block_till_done()
    self.assertEqual(2, len(specific_runs))
    self.assertEqual(2, len(wildcard_runs))
    self.assertEqual(2, len(wildercard_runs))
