def test_track_state_change(self):
        # 2 lists to track how often our callbacks get called
        specific_runs = []
        wildcard_runs = []

        decor = track_state_change('light.Bowl', 'on', 'off')
        decor(lambda a, b, c, d: specific_runs.append(1))

        decor = track_state_change('light.Bowl', ha.MATCH_ALL, ha.MATCH_ALL)
        decor(lambda a, b, c, d: wildcard_runs.append(1))

        # Set same state should not trigger a state change/listener
        self.hass.states.set('light.Bowl', 'on')
        self.hass.pool.block_till_done()
        self.assertEqual(0, len(specific_runs))
        self.assertEqual(0, len(wildcard_runs))

        # State change off -> on
        self.hass.states.set('light.Bowl', 'off')
        self.hass.pool.block_till_done()
        self.assertEqual(1, len(specific_runs))
        self.assertEqual(1, len(wildcard_runs))

        # State change off -> off
        self.hass.states.set('light.Bowl', 'off', {"some_attr": 1})
        self.hass.pool.block_till_done()
        self.assertEqual(1, len(specific_runs))
        self.assertEqual(2, len(wildcard_runs))

        # State change off -> on
        self.hass.states.set('light.Bowl', 'on')
        self.hass.pool.block_till_done()
        self.assertEqual(1, len(specific_runs))
        self.assertEqual(3, len(wildcard_runs))
Test track_state_change.
dataset/ETHPy150Open home-assistant/home-assistant/tests/helpers/test_event_decorators.py/TestEventDecoratorHelpers.test_track_state_change