public void SetAwayState(AwayState state)
        {
            WebClient http = new WebClient();
            string response = http.UploadString(this.Url + "/settings", String.Format("away={0}", (int)state));

            if (response.Contains(SUCCESS_KEYWORD))
            {
                this.AwayState = state;
            }
            else
            {
                this.logger.Error(String.Format("Error setting away state. {0}.", response));
            }
        }
        /// <summary>
        /// Gets the current heating state of the thermostat, based on an educated guess (verified by experimentation).
        /// </summary>
        public static ThermostatHeatingState GetHeatingState(this ThermostatModel model, AwayState awayState)
        {
            var state = ThermostatHeatingState.NotHeatingOrCooling;

            if (model.IsOnline)
            {
                switch (model.HvacMode)
                {
                    case HvacMode.SystemIsOff:
                        state = ThermostatHeatingState.Off;
                        break;

                    case HvacMode.HeatAndCool:
                        var targetTemperatureHigh = awayState == AwayState.Home ? model.TargetTemperatureHighF : model.AwayTemperatureHighF;
                        var targetTemperatureLow = awayState == AwayState.Home ? model.TargetTemperatureLowF : model.AwayTemperatureLowF;

                        if (targetTemperatureHigh > model.AmbientTemperatureF)
                        {
                            state = ThermostatHeatingState.Heating; // sort of a guess
                        }
                        else if (targetTemperatureLow < model.AmbientTemperatureF)
                        {
                            state = ThermostatHeatingState.Cooling; // sort of a guess
                        }
                        break;

                    default:
                        var targetTemperature = awayState == AwayState.Home ? model.TargetTemperatureF : model.AwayTemperatureLowF;

                        if (model.CanHeat && targetTemperature > model.AmbientTemperatureF)
                        {
                            state = ThermostatHeatingState.Heating; // sort of a guess
                        }
                        else if (model.CanCool && targetTemperature < model.AmbientTemperatureF)
                        {
                            state = ThermostatHeatingState.Cooling; // sort of a guess
                        }
                        break;
                }
            }
            else
            {
                state = ThermostatHeatingState.Offline;
            }

            return state;
        }
예제 #3
0
 /// <summary>
 /// Sets the state of the structure. In order for a structure to be in the Auto-Away state, all
 /// devices must also be in Auto-Away state. When any device leaves the Auto-Away state, then the
 /// structure also leaves the Auto-Away state.
 /// </summary>
 /// <param name="structureId">The unique identifier for the <see cref="Structure"/>.</param>
 /// <param name="awayState">The state of the structure. Values can be "home", "away", or "auto-away".</param>
 /// <param name="callback">A <see cref="Callback"/> to receive whether the change was successful.</param>
 public void SetAway(string structureId, AwayState awayState, Callback callback = null)
 {
     restClient.WriteString(GetPath(structureId), Structure.KEY_AWAY, awayState.GetValueString(), callback);
 }
예제 #4
0
        private void FireHeatingStateChangedEvents(Dictionary<string, ThermostatModel> thermostats, AwayState awayState)
        {
            if (ThermostatStateChanged == null) return;

            foreach (var thermostat in thermostats)
            {
                if (_session.PreviousThermostats.ContainsKey(thermostat.Value.DeviceId))
                {
                    var previousThermostat = _session.PreviousThermostats[thermostat.Value.DeviceId];
                    var currentHeatingState = thermostat.Value.GetHeatingState(awayState);

                    if (previousThermostat.GetHeatingState(awayState) != currentHeatingState ||
                        previousThermostat.HasLeaf != thermostat.Value.HasLeaf)
                    {
                        ThermostatStateChanged(this, new ThermostatStateEventArgs
                                                     {
                                                         DeviceId = thermostat.Value.DeviceId,
                                                         Previous = new ThermostatState
                                                                    {
                                                                        Heating = previousThermostat.GetHeatingState(awayState),
                                                                        HasLeaf = previousThermostat.HasLeaf
                                                                    },
                                                         Current = new ThermostatState
                                                               {
                                                                   Heating = currentHeatingState,
                                                                   HasLeaf = thermostat.Value.HasLeaf
                                                               }
                                                     });
                    }
                }
            }
        }
예제 #5
0
        public void SetAway(string accessToken, string structureId, AwayState awayState)
        {
            if (_log.IsInfoEnabled)
            {
                _log.InfoFormat("Setting away state of structure '{0}' to {1}.", structureId, awayState);
            }

            var setAwayUrl = string.IsNullOrEmpty(_session.AwaySetSubsequentUrl[structureId]) ?
                string.Format("https://developer-api.nest.com/devices/structures/{0}/away?auth={1}", structureId, accessToken) :
                _session.AwaySetSubsequentUrl[structureId];

            string subsequentAwaySetUrl;

            SetNewValue(setAwayUrl, "\"" + Utils.ToEnumString(awayState) + "\"", out subsequentAwaySetUrl);

            _session.AwaySetSubsequentUrl[structureId] = subsequentAwaySetUrl;
        }