'Return device state attributes.'

@property
def device_state_attributes(self):

    if (self._attr is None):
        return None
    state_attr = {ATTR_SESSION_START: self._attr['date']}
    state_attr[ATTR_TNT] = self._attr['tnt']
    state_attr[ATTR_PROCESSING] = self._attr['processing']
    sleep_time = (sum(self._attr['breakdown'].values()) - self._attr['breakdown']['awake'])
    state_attr[ATTR_SLEEP_DUR] = sleep_time
    try:
        state_attr[ATTR_LIGHT_PERC] = round(((self._attr['breakdown']['light'] / sleep_time) * 100), 2)
    except ZeroDivisionError:
        state_attr[ATTR_LIGHT_PERC] = 0
    try:
        state_attr[ATTR_DEEP_PERC] = round(((self._attr['breakdown']['deep'] / sleep_time) * 100), 2)
    except ZeroDivisionError:
        state_attr[ATTR_DEEP_PERC] = 0
    if (self._units == 'si'):
        room_temp = round(self._attr['room_temp'], 2)
        bed_temp = round(self._attr['bed_temp'], 2)
    else:
        room_temp = round(((self._attr['room_temp'] * 1.8) + 32), 2)
        bed_temp = round(((self._attr['bed_temp'] * 1.8) + 32), 2)
    if ('current' in self._sensor_root):
        state_attr[ATTR_RESP_RATE] = round(self._attr['resp_rate'], 2)
        state_attr[ATTR_HEART_RATE] = round(self._attr['heart_rate'], 2)
        state_attr[ATTR_SLEEP_STAGE] = self._attr['stage']
        state_attr[ATTR_ROOM_TEMP] = room_temp
        state_attr[ATTR_BED_TEMP] = bed_temp
    elif ('last' in self._sensor_root):
        state_attr[ATTR_AVG_RESP_RATE] = round(self._attr['resp_rate'], 2)
        state_attr[ATTR_AVG_HEART_RATE] = round(self._attr['heart_rate'], 2)
        state_attr[ATTR_AVG_ROOM_TEMP] = room_temp
        state_attr[ATTR_AVG_BED_TEMP] = bed_temp
    return state_attr
