<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def call_fan(tstat):
 """ Toggles the fan """

    old_fan = tstat.fan

    tstat.write({
        'fan': not old_fan,
    })

    def restore():
        tstat.write({
            'fan': old_fan,
        })
    return restore