public function getDeviceSchedule($serial_number = NULL) {
        $this->prepareForGet();
        $serial_number = $this->getDefaultSerial($serial_number);
        $schedule_days = $this->last_status->schedule->{$serial_number}->days;

        $schedule = array();
        foreach ((array)$schedule_days as $day => $scheduled_events) {
            $events = array();
            foreach ($scheduled_events as $scheduled_event) {
                if ($scheduled_event->entry_type == 'setpoint') {
                    $events[(int)$scheduled_event->time] = (object) array(
                       'time' => $scheduled_event->time/60, // in minutes
                       'target_temperature' => $scheduled_event->type == 'RANGE' ? array($this->temperatureInUserScale((float)$scheduled_event->{'temp-min'}), $this->temperatureInUserScale((float)$scheduled_event->{'temp-max'})) : $this->temperatureInUserScale((float) $scheduled_event->temp),
                       'mode' => $scheduled_event->type == 'HEAT' ? TARGET_TEMP_MODE_HEAT : ($scheduled_event->type == 'COOL' ? TARGET_TEMP_MODE_COOL : TARGET_TEMP_MODE_RANGE)
                    );
                }
            }
            if (!empty($events)) {
                ksort($events);
                $schedule[(int) $day] = array_values($events);
            }
        }

        ksort($schedule);
        $sorted_schedule = array();
        foreach ($schedule as $day => $events) {
            $sorted_schedule[$this->days_maps[(int) $day]] = $events;
        }

        return $sorted_schedule;
    }