nest.class.php
public function getDeviceInfo($serial_number = NULL) {
        $this->prepareForGet();
        $serial_number = $this->getDefaultSerial($serial_number);
        $topaz = isset($this->last_status->topaz) ? $this->last_status->topaz : array();
        foreach ($topaz as $protect) {
            if ($serial_number == $protect->serial_number) {
                // The specified device is a Nest Protect
                $infos = (object) array(
                    'co_status' => $protect->co_status == 0 ? "OK" : $protect->co_status,
                    'co_previous_peak' => isset($protect->co_previous_peak) ? $protect->co_previous_peak : NULL,
                    'co_sequence_number' => $protect->co_sequence_number,
                    'smoke_status' => $protect->smoke_status == 0 ? "OK" : $protect->smoke_status,
                    'smoke_sequence_number' => $protect->smoke_sequence_number,
                    'model' => $protect->model,
                    'software_version' => $protect->software_version,
                    'line_power_present' => $protect->line_power_present,
                    'battery_level' => $protect->battery_level,
                    'battery_health_state' => $protect->battery_health_state == 0 ? "OK" : $protect->battery_health_state,
                    'wired_or_battery' => isset($protect->wired_or_battery) ? $protect->wired_or_battery : NULL,
                    'born_on_date' => isset($protect->device_born_on_date_utc_secs) ? date(DATE_FORMAT, $protect->device_born_on_date_utc_secs) : NULL,
                    'replace_by_date' => date(DATE_FORMAT, $protect->replace_by_date_utc_secs),
                    'last_update' => date(DATETIME_FORMAT, $protect->{'$timestamp'}/1000),
                    'last_manual_test' => $protect->latest_manual_test_start_utc_secs == 0 ? NULL : date(DATETIME_FORMAT, $protect->latest_manual_test_start_utc_secs),
                    'ntp_green_led_brightness' => isset($protect->ntp_green_led_brightness) ? $protect->ntp_green_led_brightness : NULL,
                    'tests_passed' => array(
                        'led'       => $protect->component_led_test_passed,
                        'pir'       => $protect->component_pir_test_passed,
                        'temp'      => $protect->component_temp_test_passed,
                        'smoke'     => $protect->component_smoke_test_passed,
                        'heat'      => $protect->component_heat_test_passed,
                        'wifi'      => $protect->component_wifi_test_passed,
                        'als'       => $protect->component_als_test_passed,
                        'co'        => $protect->component_co_test_passed,
                        'us'        => $protect->component_us_test_passed,
                        'hum'       => $protect->component_hum_test_passed,
                        'speaker'   => isset($protect->component_speaker_test_passed) ? $protect->component_speaker_test_passed : NULL,
                        'buzzer'    => isset($protect->component_buzzer_test_passed) ? $protect->component_buzzer_test_passed : NULL,
                    ),
                    'nest_features' => array(
                        'night_time_promise' => !empty($protect->ntp_green_led_enable) ? $protect->ntp_green_led_enable : 0,
                        'night_light'        => !empty($protect->night_light_enable) ? $protect->night_light_enable : 0,
                        'auto_away'          => !empty($protect->auto_away) ? $protect->auto_away : 0,
                        'heads_up'           => !empty($protect->heads_up_enable) ? $protect->heads_up_enable : 0,
                        'steam_detection'    => !empty($protect->steam_detection_enable) ? $protect->steam_detection_enable : 0,
                        'home_alarm_link'    => !empty($protect->home_alarm_link_capable) ? $protect->home_alarm_link_capable : 0,
                        'wired_led_enable'   => !empty($protect->wired_led_enable) ? $protect->wired_led_enable : 0,
                    ),
                    'serial_number' => $protect->serial_number,
                    'location' => $protect->structure_id,
                    'network' => (object) array(
                        'online' => $protect->component_wifi_test_passed,
                        'local_ip' => $protect->wifi_ip_address,
                        'mac_address' => $protect->wifi_mac_address
                    ),
                    'name' => !empty($protect->description) ? $protect->description : DEVICE_WITH_NO_NAME,
                    'where' => isset($this->where_map[$protect->spoken_where_id]) ? $this->where_map[$protect->spoken_where_id] : $protect->spoken_where_id,
                    'color' => isset($protect->device_external_color) ? $protect->device_external_color : NULL,
                );
                return $infos;
            }
        }

        list(, $structure) = explode('.', $this->last_status->link->{$serial_number}->structure);
        $structure_away = $this->last_status->structure->{$structure}->away;
        $mode = strtolower($this->last_status->device->{$serial_number}->current_schedule_mode);
        $target_mode = $this->last_status->shared->{$serial_number}->target_temperature_type;
        $eco_mode = $this->last_status->device->{$serial_number}->eco->mode; // manual-eco, auto-eco, schedule

        if ($target_mode == TARGET_TEMP_MODE_OFF) {
            $target_temperatures = FALSE; // No target due to it being off
            $mode = TARGET_TEMP_MODE_OFF;
        } elseif ($eco_mode !== "schedule") {
            // We are in eco, thus not actively using the schedule

            if ($this->last_status->device->{$serial_number}->away_temperature_low_enabled && $this->last_status->device->{$serial_number}->away_temperature_high_enabled) {
                // We have both low and high temp eco temperatures
                $mode = TARGET_TEMP_MODE_RANGE;
                $target_temperatures = array(
                    $this->temperatureInUserScale((float) $this->last_status->device->{$serial_number}->away_temperature_low),
                    $this->temperatureInUserScale((float) $this->last_status->device->{$serial_number}->away_temperature_high)
                );
            } elseif ($this->last_status->device->{$serial_number}->away_temperature_low_enabled) {
                // We have only an eco temp low, i.e. we're heating
                $mode = TARGET_TEMP_MODE_HEAT;
                $target_temperatures = $this->temperatureInUserScale((float) $this->last_status->device->{$serial_number}->away_temperature_low);
            } elseif ($this->last_status->device->{$serial_number}->away_temperature_high_enabled) {
                // We have only an eco temp high, i.e. we're cooling
                $mode = TARGET_TEMP_MODE_COOL;
                $target_temperatures = $this->temperatureInUserScale((float) $this->last_status->device->{$serial_number}->away_temperature_high);
            } else {
                // We're in eco with no away temperatures set, i.e. we're technically off (safety temps would still kick in)
                $mode = TARGET_TEMP_MODE_OFF;
                $target_temperatures = FALSE;
            }
        } elseif ($target_mode === 'range') {
            $target_temperatures = array(
                $this->temperatureInUserScale((float) $this->last_status->shared->{$serial_number}->target_temperature_low),
                $this->temperatureInUserScale((float) $this->last_status->shared->{$serial_number}->target_temperature_high)
            );
        } else {
            // It is either heat or cool mode
            $target_temperatures = $this->temperatureInUserScale((float) $this->last_status->shared->{$serial_number}->target_temperature);
        }

        $current_modes = array();
        $current_modes[] = $mode;
        if ($eco_mode !== "schedule") {
            $current_modes[] = $eco_mode;
        }
        if ($structure_away) {
            $current_modes[] = 'away';
        }

        $infos = (object) array(
            'current_state' => (object) array(
                'mode' => implode(',', $current_modes),
                'temperature' => $this->temperatureInUserScale((float) $this->last_status->shared->{$serial_number}->current_temperature),
                'humidity' => $this->last_status->device->{$serial_number}->current_humidity,
                'ac' => $this->last_status->shared->{$serial_number}->hvac_ac_state,
                'heat' => $this->last_status->shared->{$serial_number}->hvac_heater_state,
                'alt_heat' => $this->last_status->shared->{$serial_number}->hvac_alt_heat_state,
                'fan' => $this->last_status->shared->{$serial_number}->hvac_fan_state,
                'auto_away' => $this->last_status->shared->{$serial_number}->auto_away, // -1 when disabled, 0 when enabled (thermostat can set auto-away), >0 when enabled and active (thermostat is currently in auto-away mode)
                'manual_away' => $structure_away, //Leaving this for others - but manual away really doesn't exist anymore and should be removed eventually
                'structure_away' => $structure_away,
                'leaf' => $this->last_status->device->{$serial_number}->leaf,
                'battery_level' => $this->last_status->device->{$serial_number}->battery_level,
                'active_stages' => (object) array(
                    'heat' => (object) array(
                        'stage1' => $this->last_status->shared->{$serial_number}->hvac_heater_state,
                        'stage2' => $this->last_status->shared->{$serial_number}->hvac_heat_x2_state,
                        'stage3' => $this->last_status->shared->{$serial_number}->hvac_heat_x3_state,
                        'alt' => $this->last_status->shared->{$serial_number}->hvac_alt_heat_state,
                        'alt_stage2' => $this->last_status->shared->{$serial_number}->hvac_alt_heat_x2_state,
                        'aux' => $this->last_status->shared->{$serial_number}->hvac_aux_heater_state,
                        'emergency' => $this->last_status->shared->{$serial_number}->hvac_emer_heat_state,
                    ),
                    'cool' => (object) array(
                        'stage1' => $this->last_status->shared->{$serial_number}->hvac_ac_state,
                        'stage2' => $this->last_status->shared->{$serial_number}->hvac_cool_x2_state,
                        'stage3' => $this->last_status->shared->{$serial_number}->hvac_cool_x3_state,
                    ),
                ),
                'eco_mode' => $eco_mode,
                'eco_temperatures' => (object) array(
                    'low' => ($this->last_status->device->{$serial_number}->away_temperature_low_enabled) ? $this->temperatureInUserScale((float)$this->last_status->device->{$serial_number}->away_temperature_low) : FALSE,
                    'high' => ($this->last_status->device->{$serial_number}->away_temperature_high_enabled) ? $this->temperatureInUserScale((float)$this->last_status->device->{$serial_number}->away_temperature_high) : FALSE,
                ),
            ),
            'target' => (object) array(
                'mode' => $target_mode,
                'temperature' => $target_temperatures,
                'time_to_target' => $this->last_status->device->{$serial_number}->time_to_target
            ),
            'serial_number' => $this->last_status->device->{$serial_number}->serial_number,
            'scale' => $this->last_status->device->{$serial_number}->temperature_scale,
            'location' => $structure,
            'network' => $this->getDeviceNetworkInfo($serial_number),
            'name' => !empty($this->last_status->shared->{$serial_number}->name) ? $this->last_status->shared->{$serial_number}->name : DEVICE_WITH_NO_NAME,
            'auto_cool' => ((int) $this->last_status->device->{$serial_number}->leaf_threshold_cool === 0) ? FALSE : ceil($this->temperatureInUserScale((float) $this->last_status->device->{$serial_number}->leaf_threshold_cool)),
            'auto_heat' => ((int) $this->last_status->device->{$serial_number}->leaf_threshold_heat === 1000) ? FALSE : floor($this->temperatureInUserScale((float) $this->last_status->device->{$serial_number}->leaf_threshold_heat)),
            'where' => isset($this->last_status->device->{$serial_number}->where_id) ? isset($this->where_map[$this->last_status->device->{$serial_number}->where_id]) ? $this->where_map[$this->last_status->device->{$serial_number}->where_id] : $this->last_status->device->{$serial_number}->where_id : ""
        );
        if ($this->last_status->device->{$serial_number}->has_humidifier) {
            $infos->current_state->humidifier = $this->last_status->device->{$serial_number}->humidifier_state;
            $infos->target->humidity = $this->last_status->device->{$serial_number}->target_humidity;
            $infos->target->humidity_enabled = $this->last_status->device->{$serial_number}->target_humidity_enabled;
        }

        return $infos;
    }
public function getDeviceInfo($serial_number = NULL) {
        $this->prepareForGet();
        $serial_number = $this->getDefaultSerial($serial_number);
        $topaz = isset($this->last_status->topaz) ? $this->last_status->topaz : array();
        foreach ($topaz as $protect) {
            if ($serial_number == $protect->serial_number) {
                // The specified device is a Nest Protect
                $infos = (object) array(
                    'co_status' => $protect->co_status == 0 ? "OK" : $protect->co_status,
                    'co_previous_peak' => isset($protect->co_previous_peak) ? $protect->co_previous_peak : NULL,
                    'co_sequence_number' => $protect->co_sequence_number,
                    'smoke_status' => $protect->smoke_status == 0 ? "OK" : $protect->smoke_status,
                    'smoke_sequence_number' => $protect->smoke_sequence_number,
                    'model' => $protect->model,
                    'software_version' => $protect->software_version,
                    'line_power_present' => $protect->line_power_present,
                    'battery_level' => $protect->battery_level,
                    'battery_health_state' => $protect->battery_health_state == 0 ? "OK" : $protect->battery_health_state,
                    'wired_or_battery' => isset($protect->wired_or_battery) ? $protect->wired_or_battery : NULL,
                    'born_on_date' => isset($protect->device_born_on_date_utc_secs) ? date(DATE_FORMAT, $protect->device_born_on_date_utc_secs) : NULL,
                    'replace_by_date' => date(DATE_FORMAT, $protect->replace_by_date_utc_secs),
                    'last_update' => date(DATETIME_FORMAT, $protect->{'$timestamp'}/1000),
                    'last_manual_test' => $protect->latest_manual_test_start_utc_secs == 0 ? NULL : date(DATETIME_FORMAT, $protect->latest_manual_test_start_utc_secs),
                    'ntp_green_led_brightness' => isset($protect->ntp_green_led_brightness) ? $protect->ntp_green_led_brightness : NULL,
                    'tests_passed' => array(
                        'led'       => $protect->component_led_test_passed,
                        'pir'       => $protect->component_pir_test_passed,
                        'temp'      => $protect->component_temp_test_passed,
                        'smoke'     => $protect->component_smoke_test_passed,
                        'heat'      => $protect->component_heat_test_passed,
                        'wifi'      => $protect->component_wifi_test_passed,
                        'als'       => $protect->component_als_test_passed,
                        'co'        => $protect->component_co_test_passed,
                        'us'        => $protect->component_us_test_passed,
                        'hum'       => $protect->component_hum_test_passed,
                        'speaker'   => isset($protect->component_speaker_test_passed) ? $protect->component_speaker_test_passed : NULL,
                        'buzzer'    => isset($protect->component_buzzer_test_passed) ? $protect->component_buzzer_test_passed : NULL,
                    ),
                    'nest_features' => array(
                        'night_time_promise' => !empty($protect->ntp_green_led_enable) ? $protect->ntp_green_led_enable : 0,
                        'night_light'        => !empty($protect->night_light_enable) ? $protect->night_light_enable : 0,
                        'auto_away'          => !empty($protect->auto_away) ? $protect->auto_away : 0,
                        'heads_up'           => !empty($protect->heads_up_enable) ? $protect->heads_up_enable : 0,
                        'steam_detection'    => !empty($protect->steam_detection_enable) ? $protect->steam_detection_enable : 0,
                        'home_alarm_link'    => !empty($protect->home_alarm_link_capable) ? $protect->home_alarm_link_capable : 0,
                        'wired_led_enable'   => !empty($protect->wired_led_enable) ? $protect->wired_led_enable : 0,
                    ),
                    'serial_number' => $protect->serial_number,
                    'location' => $protect->structure_id,
                    'network' => (object) array(
                        'online' => $protect->component_wifi_test_passed,
                        'local_ip' => $protect->wifi_ip_address,
                        'mac_address' => $protect->wifi_mac_address
                    ),
                    'name' => !empty($protect->description) ? $protect->description : DEVICE_WITH_NO_NAME,
                    'where' => isset($this->where_map[$protect->spoken_where_id]) ? $this->where_map[$protect->spoken_where_id] : $protect->spoken_where_id,
                    'color' => isset($protect->device_external_color) ? $protect->device_external_color : NULL,
                );
                return $infos;
            }
        }

        list(, $structure) = explode('.', $this->last_status->link->{$serial_number}->structure);
        $structure_away = $this->last_status->structure->{$structure}->away;
        $mode = strtolower($this->last_status->device->{$serial_number}->current_schedule_mode);
        $target_mode = $this->last_status->shared->{$serial_number}->target_temperature_type;
        $eco_mode = $this->last_status->device->{$serial_number}->eco->mode; // manual-eco, auto-eco, schedule

        if ($target_mode == TARGET_TEMP_MODE_OFF) {
            $target_temperatures = FALSE; // No target due to it being off
            $mode = TARGET_TEMP_MODE_OFF;
        } elseif ($eco_mode !== "schedule") {
            // We are in eco, thus not actively using the schedule

            if ($this->last_status->device->{$serial_number}->away_temperature_low_enabled && $this->last_status->device->{$serial_number}->away_temperature_high_enabled) {
                // We have both low and high temp eco temperatures
                $mode = TARGET_TEMP_MODE_RANGE;
                $target_temperatures = array(
                    $this->temperatureInUserScale((float) $this->last_status->device->{$serial_number}->away_temperature_low),
                    $this->temperatureInUserScale((float) $this->last_status->device->{$serial_number}->away_temperature_high)
                );
            } elseif ($this->last_status->device->{$serial_number}->away_temperature_low_enabled) {
                // We have only an eco temp low, i.e. we're heating
                $mode = TARGET_TEMP_MODE_HEAT;
                $target_temperatures = $this->temperatureInUserScale((float) $this->last_status->device->{$serial_number}->away_temperature_low);
            } elseif ($this->last_status->device->{$serial_number}->away_temperature_high_enabled) {
                // We have only an eco temp high, i.e. we're cooling
                $mode = TARGET_TEMP_MODE_COOL;
                $target_temperatures = $this->temperatureInUserScale((float) $this->last_status->device->{$serial_number}->away_temperature_high);
            } else {
                // We're in eco with no away temperatures set, i.e. we're technically off (safety temps would still kick in)
                $mode = TARGET_TEMP_MODE_OFF;
                $target_temperatures = FALSE;
            }
        } elseif ($target_mode === 'range') {
            $target_temperatures = array(
                $this->temperatureInUserScale((float) $this->last_status->shared->{$serial_number}->target_temperature_low),
                $this->temperatureInUserScale((float) $this->last_status->shared->{$serial_number}->target_temperature_high)
            );
        } else {
            // It is either heat or cool mode
            $target_temperatures = $this->temperatureInUserScale((float) $this->last_status->shared->{$serial_number}->target_temperature);
        }

        $current_modes = array();
        $current_modes[] = $mode;
        if ($eco_mode !== "schedule") {
            $current_modes[] = $eco_mode;
        }
        if ($structure_away) {
            $current_modes[] = 'away';
        }

        $infos = (object) array(
            'current_state' => (object) array(
                'mode' => implode(',', $current_modes),
                'temperature' => $this->temperatureInUserScale((float) $this->last_status->shared->{$serial_number}->current_temperature),
                'humidity' => $this->last_status->device->{$serial_number}->current_humidity,
                'ac' => $this->last_status->shared->{$serial_number}->hvac_ac_state,
                'heat' => $this->last_status->shared->{$serial_number}->hvac_heater_state,
                'alt_heat' => $this->last_status->shared->{$serial_number}->hvac_alt_heat_state,
                'fan' => $this->last_status->shared->{$serial_number}->hvac_fan_state,
                'auto_away' => $this->last_status->shared->{$serial_number}->auto_away, // -1 when disabled, 0 when enabled (thermostat can set auto-away), >0 when enabled and active (thermostat is currently in auto-away mode)
                'manual_away' => $structure_away, //Leaving this for others - but manual away really doesn't exist anymore and should be removed eventually
                'structure_away' => $structure_away,
                'leaf' => $this->last_status->device->{$serial_number}->leaf,
                'battery_level' => $this->last_status->device->{$serial_number}->battery_level,
                'active_stages' => (object) array(
                    'heat' => (object) array(
                        'stage1' => $this->last_status->shared->{$serial_number}->hvac_heater_state,
                        'stage2' => $this->last_status->shared->{$serial_number}->hvac_heat_x2_state,
                        'stage3' => $this->last_status->shared->{$serial_number}->hvac_heat_x3_state,
                        'alt' => $this->last_status->shared->{$serial_number}->hvac_alt_heat_state,
                        'alt_stage2' => $this->last_status->shared->{$serial_number}->hvac_alt_heat_x2_state,
                        'aux' => $this->last_status->shared->{$serial_number}->hvac_aux_heater_state,
                        'emergency' => $this->last_status->shared->{$serial_number}->hvac_emer_heat_state,
                    ),
                    'cool' => (object) array(
                        'stage1' => $this->last_status->shared->{$serial_number}->hvac_ac_state,
                        'stage2' => $this->last_status->shared->{$serial_number}->hvac_cool_x2_state,
                        'stage3' => $this->last_status->shared->{$serial_number}->hvac_cool_x3_state,
                    ),
                ),
                'eco_mode' => $eco_mode,
                'eco_temperatures' => (object) array(
                    'low' => ($this->last_status->device->{$serial_number}->away_temperature_low_enabled) ? $this->temperatureInUserScale((float)$this->last_status->device->{$serial_number}->away_temperature_low) : FALSE,
                    'high' => ($this->last_status->device->{$serial_number}->away_temperature_high_enabled) ? $this->temperatureInUserScale((float)$this->last_status->device->{$serial_number}->away_temperature_high) : FALSE,
                ),
            ),
            'target' => (object) array(
                'mode' => $target_mode,
                'temperature' => $target_temperatures,
                'time_to_target' => $this->last_status->device->{$serial_number}->time_to_target
            ),
            'serial_number' => $this->last_status->device->{$serial_number}->serial_number,
            'scale' => $this->last_status->device->{$serial_number}->temperature_scale,
            'location' => $structure,
            'network' => $this->getDeviceNetworkInfo($serial_number),
            'name' => !empty($this->last_status->shared->{$serial_number}->name) ? $this->last_status->shared->{$serial_number}->name : DEVICE_WITH_NO_NAME,
            'auto_cool' => ((int) $this->last_status->device->{$serial_number}->leaf_threshold_cool === 0) ? FALSE : ceil($this->temperatureInUserScale((float) $this->last_status->device->{$serial_number}->leaf_threshold_cool)),
            'auto_heat' => ((int) $this->last_status->device->{$serial_number}->leaf_threshold_heat === 1000) ? FALSE : floor($this->temperatureInUserScale((float) $this->last_status->device->{$serial_number}->leaf_threshold_heat)),
            'where' => isset($this->last_status->device->{$serial_number}->where_id) ? isset($this->where_map[$this->last_status->device->{$serial_number}->where_id]) ? $this->where_map[$this->last_status->device->{$serial_number}->where_id] : $this->last_status->device->{$serial_number}->where_id : ""
        );
        if ($this->last_status->device->{$serial_number}->has_humidifier) {
            $infos->current_state->humidifier = $this->last_status->device->{$serial_number}->humidifier_state;
            $infos->target->humidity = $this->last_status->device->{$serial_number}->target_humidity;
            $infos->target->humidity_enabled = $this->last_status->device->{$serial_number}->target_humidity_enabled;
        }

        return $infos;
    }
Get the specified device (thermostat or protect) information.

@param string $serial_number The device (thermostat or protect) serial number. Defaults to the first device of the account.

@return stdClass