Exemple #1
0
        protected virtual void OnThermostatCoolSetpointChanged(ThermostatCoolSetpointChangedEventArgs e)
        {
            ThermostatCoolSetpointChangedHandler handler = ThermostatCoolSetpointChanged;

            if (handler != null)
            {
                handler(this, e);
            }
        }
Exemple #2
0
        private static void DomoShare_ThermostatCoolSetpointChanged(object sender, ThermostatCoolSetpointChangedEventArgs e)
        {
            var tenantId = Guid.Parse(Configuration.GetSection("AppSettings").GetSection("ControllerId").Value);
            CoolSetpointChangeCommand cmd = new CoolSetpointChangeCommand(e.TenantId, e.ThermostatId, e.ThermostatGuid, e.NewCoolSetpoint);
            ChangeCoolSetpoint        changeCoolSetpointCommand = new ChangeCoolSetpoint(EventStore, e.ThermostatId, e.ThermostatGuid,
                                                                                         e.TenantId, (double)e.NewCoolSetpoint);
            var handler = new ThermostatCommandHandlers();

            handler.Handle(changeCoolSetpointCommand);
        }
Exemple #3
0
        public void SubscribeToNestDeviceDataUpdates(Guid tenantId, Dictionary <string, Guid> thermostats)
        {
            var    accessToken = string.Empty;
            string file;

            file = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "accesstoken.txt");
            if (File.Exists(file))
            {
                accessToken = File.ReadAllText(file);
            }

            var firebaseClient = new Firebase("https://developer-api.nest.com/", accessToken);

            try
            {
                var response = firebaseClient.GetStreaming("devices",
                                                           changed: (s, e) =>
                {
                    try
                    {
                        if (e.Path.Contains("ambient_temperature_f"))
                        {
                            Trace.TraceInformation("Current temperature of Nest Thermostat has been updated to: {0}.", e.Data);
                            double newValue;
                            double.TryParse(e.Data, out newValue);
                            var thermostatId = e.Path.Replace($"/devices/thermostats/",
                                                              string.Empty).Replace($"/ambient_temperature_f", string.Empty);
                            Guid thermostatGuid;
                            thermostats.TryGetValue(thermostatId, out thermostatGuid);
                            ThermostatAmbientTemperatureChangedEventArgs ambientTemperatureChangedArgs =
                                new ThermostatAmbientTemperatureChangedEventArgs(tenantId, thermostatId, thermostatGuid, newValue);
                            OnThermostatAmbientTemperatureChanged(ambientTemperatureChangedArgs);
                        }
                        else if (e.Path.Contains("humidity"))
                        {
                            Trace.TraceInformation("Current humidity of Nest Thermostat has been updated to: {0}%.", e.Data);
                            double newValue;
                            double.TryParse(e.Data, out newValue);
                            var thermostatId = e.Path.Replace($"/devices/thermostats/",
                                                              string.Empty).Replace($"/humidity", string.Empty);
                            Guid thermostatGuid;
                            thermostats.TryGetValue(thermostatId, out thermostatGuid);
                            ThermostatHumidityChangedEventArgs humidityChangedArgs =
                                new ThermostatHumidityChangedEventArgs(tenantId, thermostatId, thermostatGuid, newValue);
                            OnThermostatHumidityChanged(humidityChangedArgs);
                        }
                        else if (e.Path.Contains("hvac_state"))
                        {
                            Trace.TraceInformation("Current state of Nest Thermostat has been updated to: {0}.", e.Data);
                            var thermostatId = e.Path.Replace($"/devices/thermostats/",
                                                              string.Empty).Replace($"/hvac_state", string.Empty);
                            Guid thermostatGuid;
                            thermostats.TryGetValue(thermostatId, out thermostatGuid);
                            ThermostatSystemStatusChangedEventArgs systemStatusChangedArgs =
                                new ThermostatSystemStatusChangedEventArgs(tenantId, thermostatId, thermostatGuid, e.Data);
                            OnThermostatSystemStatusChanged(systemStatusChangedArgs);
                        }
                        else if (e.Path.Contains("hvac_mode"))
                        {
                            Trace.TraceInformation("Current mode of Nest Thermostat has been updated to: {0}.", e.Data);
                            var thermostatId = e.Path.Replace($"/devices/thermostats/",
                                                              string.Empty).Replace($"/hvac_mode", string.Empty);
                            Guid thermostatGuid;
                            thermostats.TryGetValue(thermostatId, out thermostatGuid);
                            ThermostatSystemModeChangedEventArgs systemModeChangedArgs =
                                new ThermostatSystemModeChangedEventArgs(tenantId, thermostatId, thermostatGuid, e.Data);
                            OnThermostatSystemModeChanged(systemModeChangedArgs);
                        }
                        else if (e.Path.Contains("target_temperature_low_f"))
                        {
                            Trace.TraceInformation("Heat Setpoint of Nest Thermostat has been updated to: {0}.", e.Data);
                            double newValue;
                            double.TryParse(e.Data, out newValue);
                            var thermostatId = e.Path.Replace($"/devices/thermostats/", string.Empty).Replace($"/target_temperature_low_f", string.Empty);
                            Guid thermostatGuid;
                            thermostats.TryGetValue(thermostatId, out thermostatGuid);
                            ThermostatHeatSetpointChangedEventArgs heatSetpointChangedArgs =
                                new ThermostatHeatSetpointChangedEventArgs(tenantId, thermostatId, thermostatGuid, newValue);
                            OnThermostatHeatSetpointChanged(heatSetpointChangedArgs);
                        }
                        else if (e.Path.Contains("target_temperature_high_f"))
                        {
                            Trace.TraceInformation("Cool Setpoint of Nest Thermostat has been updated to: {0}.", e.Data);
                            double newValue;
                            double.TryParse(e.Data, out newValue);
                            var thermostatId = e.Path.Replace($"/devices/thermostats/", string.Empty).Replace($"/target_temperature_high_f", string.Empty);
                            Guid thermostatGuid;
                            thermostats.TryGetValue(thermostatId, out thermostatGuid);
                            ThermostatCoolSetpointChangedEventArgs coolSetpointChangedArgs =
                                new ThermostatCoolSetpointChangedEventArgs(tenantId, thermostatId, thermostatGuid, newValue);
                            OnThermostatCoolSetpointChanged(coolSetpointChangedArgs);
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine($"Exception while processing data from Nest: {ex}");
                        Trace.TraceError($"Exception while processing data from Nest: {ex}");
                    }
                });

                //Console.WriteLine("Change the current temperature of the Nest Thermostat in the Nest Developer Chrome Extension to see the real-time updates.");
                Trace.TraceInformation("Change the current temperature of the Nest Thermostat in the Nest Developer Chrome Extension to see the real-time updates.");
            }
            catch (Exception ex)
            {
                Trace.TraceError($"Error connectiong to REST Streaming: {ex}");
            }
        }