<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def current_sleep_stage(self):
 """Return sleep stage for in-progress session."""

        try:
            stages = self.intervals[0]['stages']
            num_stages = len(stages)

            if num_stages == 0:
                return None

            # API now always has an awake state last in the dict
            # so always pull the second to last stage while we are
            # in a processing state
            if self.current_session_processing:
                stage = stages[num_stages-2]['stage']
            else:
                stage = stages[num_stages-1]['stage']

            # UNRELIABLE... Removing for now.
            # Check sleep stage against last_seen time to make
            # sure we don't get stuck in a non-awake state.
            #delta_elap = datetime.fromtimestamp(time.time()) \
            #    - datetime.strptime(self.last_seen, '%Y-%m-%dT%H:%M:%S')
            #_LOGGER.debug('User elap: %s', delta_elap.total_seconds())
            #if stage != 'awake' and delta_elap.total_seconds() > 1800:
                # Bed hasn't seen us for 30min so set awake.
            #    stage = 'awake'
        except KeyError:
            stage = None
        return stage