'Test for firing on entity change with for and attribute change.'

def test_if_fires_on_entity_change_with_for_attribute_change(self):

    assert setup_component(self.hass, automation.DOMAIN, {automation.DOMAIN: {'trigger': {'platform': 'state', 'entity_id': 'test.entity', 'to': 'world', 'for': {'seconds': 5}}, 'action': {'service': 'test.automation'}}})
    utcnow = dt_util.utcnow()
    with patch('homeassistant.core.dt_util.utcnow') as mock_utcnow:
        mock_utcnow.return_value = utcnow
        self.hass.states.set('test.entity', 'world')
        self.hass.block_till_done()
        mock_utcnow.return_value += timedelta(seconds=4)
        fire_time_changed(self.hass, mock_utcnow.return_value)
        self.hass.states.set('test.entity', 'world', attributes={'mock_attr': 'attr_change'})
        self.hass.block_till_done()
        self.assertEqual(0, len(self.calls))
        mock_utcnow.return_value += timedelta(seconds=4)
        fire_time_changed(self.hass, mock_utcnow.return_value)
        self.hass.block_till_done()
        self.assertEqual(1, len(self.calls))
