def record_states(hass):
    'Record some test states.\n\n    We inject a bunch of state updates from media player, zone and\n    thermostat.\n    '
    mp = 'media_player.test'
    mp2 = 'media_player.test2'
    mp3 = 'media_player.test3'
    therm = 'thermostat.test'
    therm2 = 'thermostat.test2'
    zone = 'zone.home'
    script_c = 'script.can_cancel_this_one'

    def set_state(entity_id, state, **kwargs):
        'Set the state.'
        hass.states.set(entity_id, state, **kwargs)
        wait_recording_done(hass)
        return hass.states.get(entity_id)
    zero = dt_util.utcnow()
    one = (zero + timedelta(seconds=1))
    two = (one + timedelta(seconds=1))
    three = (two + timedelta(seconds=1))
    four = (three + timedelta(seconds=1))
    states = {therm: [], therm2: [], mp: [], mp2: [], mp3: [], script_c: []}
    with patch('homeassistant.components.recorder.dt_util.utcnow', return_value=one):
        states[mp].append(set_state(mp, 'idle', attributes={'media_title': str(sentinel.mt1)}))
        states[mp].append(set_state(mp, 'YouTube', attributes={'media_title': str(sentinel.mt2)}))
        states[mp2].append(set_state(mp2, 'YouTube', attributes={'media_title': str(sentinel.mt2)}))
        states[mp3].append(set_state(mp3, 'idle', attributes={'media_title': str(sentinel.mt1)}))
        states[therm].append(set_state(therm, 20, attributes={'current_temperature': 19.5}))
    with patch('homeassistant.components.recorder.dt_util.utcnow', return_value=two):
        set_state(mp, 'YouTube', attributes={'media_title': str(sentinel.mt3)})
        set_state(zone, 'zoning')
        states[script_c].append(set_state(script_c, 'off', attributes={'can_cancel': True}))
        states[therm].append(set_state(therm, 21, attributes={'current_temperature': 19.8}))
        states[therm2].append(set_state(therm2, 20, attributes={'current_temperature': 19}))
    with patch('homeassistant.components.recorder.dt_util.utcnow', return_value=three):
        states[mp].append(set_state(mp, 'Netflix', attributes={'media_title': str(sentinel.mt4)}))
        states[mp3].append(set_state(mp3, 'Netflix', attributes={'media_title': str(sentinel.mt3)}))
        states[therm].append(set_state(therm, 21, attributes={'current_temperature': 20}))
    return (zero, four, states)
Record some test states.

We inject a bunch of state updates from media player, zone and
thermostat.
def record_states(hass):
    'Record some test states.\n\n    We inject a bunch of state updates from media player, zone and\n    thermostat.\n    '
    mp = 'media_player.test'
    mp2 = 'media_player.test2'
    mp3 = 'media_player.test3'
    therm = 'thermostat.test'
    therm2 = 'thermostat.test2'
    zone = 'zone.home'
    script_c = 'script.can_cancel_this_one'

    def set_state(entity_id, state, **kwargs):
        'Set the state.'
        hass.states.set(entity_id, state, **kwargs)
        wait_recording_done(hass)
        return hass.states.get(entity_id)
    zero = dt_util.utcnow()
    one = (zero + timedelta(seconds=1))
    two = (one + timedelta(seconds=1))
    three = (two + timedelta(seconds=1))
    four = (three + timedelta(seconds=1))
    states = {therm: [], therm2: [], mp: [], mp2: [], mp3: [], script_c: []}
    with patch('homeassistant.components.recorder.dt_util.utcnow', return_value=one):
        states[mp].append(set_state(mp, 'idle', attributes={'media_title': str(sentinel.mt1)}))
        states[mp].append(set_state(mp, 'YouTube', attributes={'media_title': str(sentinel.mt2)}))
        states[mp2].append(set_state(mp2, 'YouTube', attributes={'media_title': str(sentinel.mt2)}))
        states[mp3].append(set_state(mp3, 'idle', attributes={'media_title': str(sentinel.mt1)}))
        states[therm].append(set_state(therm, 20, attributes={'current_temperature': 19.5}))
    with patch('homeassistant.components.recorder.dt_util.utcnow', return_value=two):
        set_state(mp, 'YouTube', attributes={'media_title': str(sentinel.mt3)})
        set_state(zone, 'zoning')
        states[script_c].append(set_state(script_c, 'off', attributes={'can_cancel': True}))
        states[therm].append(set_state(therm, 21, attributes={'current_temperature': 19.8}))
        states[therm2].append(set_state(therm2, 20, attributes={'current_temperature': 19}))
    with patch('homeassistant.components.recorder.dt_util.utcnow', return_value=three):
        states[mp].append(set_state(mp, 'Netflix', attributes={'media_title': str(sentinel.mt4)}))
        states[mp3].append(set_state(mp3, 'Netflix', attributes={'media_title': str(sentinel.mt3)}))
        states[therm].append(set_state(therm, 21, attributes={'current_temperature': 20}))
    return (zero, four, states)