Nest::getWeather PHP Method

getWeather() public method

* Getters and setters
public getWeather ( $postal_code, $country_code = NULL )
    public function getWeather($postal_code, $country_code = NULL)
    {
        try {
            $url = "https://home.nest.com/api/0.1/weather/forecast/{$postal_code}";
            if (!empty($country_code)) {
                $url .= ",{$country_code}";
            }
            $weather = $this->doGET($url);
        } catch (RuntimeException $ex) {
            // NESTAPI_ERROR_NOT_JSON_RESPONSE is kinda normal. The forecast API will often return a '502 Bad Gateway' response... meh.
            if ($ex->getCode() != NESTAPI_ERROR_NOT_JSON_RESPONSE) {
                throw new RuntimeException("Unexpected issue fetching forecast.", $ex->getCode(), $ex);
            }
        }
        return (object) array('outside_temperature' => isset($weather->now) ? $this->temperatureInUserScale((double) $weather->now->current_temperature) : NULL, 'outside_humidity' => isset($weather->now) ? $weather->now->current_humidity : NULL);
    }

Usage Example

 	// Google maps api URL
 	// This is required to get the timezone offset from the current user's location
 	$google_json = "https://maps.googleapis.com/maps/api/timezone/json?location=" . $user_lat . "," . $user_long . "&timestamp=" . $timestamp;
 	$google_time = json_decode(file_get_contents($google_json));
 	$dst_offset = $google_time->dstOffset;
 	$raw_offset = $google_time->rawOffset;
 	$timestamp_offset = ( $dst_offset + $raw_offset ) / 60 / 60;
 	//$local_time = $timestamp + $dst_offset + $raw_offset;
 */
 $nest = new Nest($nest_username, $nest_password_decrypt);
 $nest_devices = $nest->getDevices();
 foreach ($nest_devices as $device) {
     // Gather information from the Nest class object for storage
     $infos = $nest->getDeviceInfo($device);
     $energy = $nest->getEnergyLatest($device);
     $weather_nest = $nest->getWeather($user_location);
     // Gather the device information for storage
     $device_serial_number = $infos->serial_number;
     $nest_location = $infos->where;
     $device_name = $infos->name;
     $battery_level = $infos->current_state->battery_level;
     // Outside weather pulled from the nest class
     $outside_humidity = $weather_nest->outside_humidity;
     $outside_temperature = $weather_nest->outside_temperature;
     // Inside weather pulled from the nest class
     $temperature = $infos->current_state->temperature;
     $humidity = $infos->current_state->humidity;
     // Current running statistics for the graph
     $ac = $infos->current_state->ac == "" ? 0 : $infos->current_state->ac;
     $heat = $infos->current_state->heat == "" ? 0 : $infos->current_state->heat;
     $scale = $infos->scale;