'Test track_state_change.'

def test_track_state_change(self):

    specific_runs = []
    wildcard_runs = []
    wildercard_runs = []
    def specific_run_callback(entity_id, old_state, new_state):
        specific_runs.append(1)
    track_state_change(self.hass, 'light.Bowl', specific_run_callback, 'on', 'off')
    @ha.callback
    def wildcard_run_callback(entity_id, old_state, new_state):
        wildcard_runs.append((old_state, new_state))
    track_state_change(self.hass, 'light.Bowl', wildcard_run_callback)
    @asyncio.coroutine
    def wildercard_run_callback(entity_id, old_state, new_state):
        wildercard_runs.append((old_state, new_state))
    track_state_change(self.hass, MATCH_ALL, wildercard_run_callback)
    self.hass.states.set('light.Bowl', 'on')
    self.hass.block_till_done()
    self.assertEqual(0, len(specific_runs))
    self.assertEqual(1, len(wildcard_runs))
    self.assertEqual(1, len(wildercard_runs))
    self.assertIsNone(wildcard_runs[(-1)][0])
    self.assertIsNotNone(wildcard_runs[(-1)][1])
    self.hass.states.set('light.Bowl', 'on')
    self.hass.block_till_done()
    self.assertEqual(0, len(specific_runs))
    self.assertEqual(1, len(wildcard_runs))
    self.assertEqual(1, len(wildercard_runs))
    self.hass.states.set('light.Bowl', 'off')
    self.hass.block_till_done()
    self.assertEqual(1, len(specific_runs))
    self.assertEqual(2, len(wildcard_runs))
    self.assertEqual(2, len(wildercard_runs))
    self.hass.states.set('light.Bowl', 'off', {'some_attr': 1})
    self.hass.block_till_done()
    self.assertEqual(1, len(specific_runs))
    self.assertEqual(3, len(wildcard_runs))
    self.assertEqual(3, len(wildercard_runs))
    self.hass.states.set('light.Bowl', 'on')
    self.hass.block_till_done()
    self.assertEqual(1, len(specific_runs))
    self.assertEqual(4, len(wildcard_runs))
    self.assertEqual(4, len(wildercard_runs))
    self.hass.states.remove('light.bowl')
    self.hass.block_till_done()
    self.assertEqual(1, len(specific_runs))
    self.assertEqual(5, len(wildcard_runs))
    self.assertEqual(5, len(wildercard_runs))
    self.assertIsNotNone(wildcard_runs[(-1)][0])
    self.assertIsNone(wildcard_runs[(-1)][1])
    self.assertIsNotNone(wildercard_runs[(-1)][0])
    self.assertIsNone(wildercard_runs[(-1)][1])
    self.hass.states.set('switch.kitchen', 'on')
    self.hass.block_till_done()
    self.assertEqual(1, len(specific_runs))
    self.assertEqual(5, len(wildcard_runs))
    self.assertEqual(6, len(wildercard_runs))
