Nest::getDeviceInfo PHP Method

getDeviceInfo() public method

public getDeviceInfo ( $serial_number = null )
    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);
        $manual_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;
        if ($manual_away || $mode == 'away' || $this->last_status->shared->{$serial_number}->auto_away > 0) {
            $mode = $mode . ',away';
            $target_mode = 'range';
            $target_temperatures = array($this->temperatureInUserScale((double) $this->last_status->device->{$serial_number}->away_temperature_low), $this->temperatureInUserScale((double) $this->last_status->device->{$serial_number}->away_temperature_high));
        } else {
            if ($mode == 'range') {
                $target_mode = 'range';
                $target_temperatures = array($this->temperatureInUserScale((double) $this->last_status->shared->{$serial_number}->target_temperature_low), $this->temperatureInUserScale((double) $this->last_status->shared->{$serial_number}->target_temperature_high));
            } else {
                $target_temperatures = $this->temperatureInUserScale((double) $this->last_status->shared->{$serial_number}->target_temperature);
            }
        }
        $infos = (object) array('current_state' => (object) array('mode' => $mode, 'temperature' => $this->temperatureInUserScale((double) $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, 'manual_away' => $manual_away, 'leaf' => $this->last_status->device->{$serial_number}->leaf, 'battery_level' => $this->last_status->device->{$serial_number}->battery_level), '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((double) $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((double) $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;
    }

Usage Example

Esempio n. 1
0
function get_nest_data()
{
    $nest = new Nest();
    $info = $nest->getDeviceInfo();
    $data = array('heating' => $info->current_state->heat == 1 ? 1 : 0, 'timestamp' => $info->network->last_connection, 'target_temp' => sprintf("%.02f", preg_match("/away/", $info->current_state->mode) ? $info->target->temperature[0] : $info->target->temperature), 'current_temp' => sprintf("%.02f", $info->current_state->temperature), 'humidity' => $info->current_state->humidity);
    return $data;
}
All Usage Examples Of Nest::getDeviceInfo