'Test state change during period.'

def test_state_changes_during_period(self):

    self.init_recorder()
    entity_id = 'media_player.test'
    def set_state(state):
        'Set    the    state.'
        self.hass.states.set(entity_id, state)
        self.wait_recording_done()
        return self.hass.states.get(entity_id)
    start = dt_util.utcnow()
    point = (start + timedelta(seconds=1))
    end = (point + timedelta(seconds=1))
    with patch('homeassistant.components.recorder.dt_util.utcnow', return_value=start):
        set_state('idle')
        set_state('YouTube')
    with patch('homeassistant.components.recorder.dt_util.utcnow', return_value=point):
        states = [set_state('idle'), set_state('Netflix'), set_state('Plex'), set_state('YouTube')]
    with patch('homeassistant.components.recorder.dt_util.utcnow', return_value=end):
        set_state('Netflix')
        set_state('Plex')
    hist = history.state_changes_during_period(self.hass, start, end, entity_id)
    self.assertEqual(states, hist[entity_id])
