Esempio n. 1
0
 public static void registerThermostat(AlexaThermostat device)
 {
     lock (devices)
     {
         devices.Add(device.applianceId, device);
     }
 }
Esempio n. 2
0
        public static AlexaThermostat GetThermostat(string applianceId)
        {
            AlexaThermostat device = DeviceList.GetDevice(applianceId) as AlexaThermostat;

            if (device == null)
            {
                throw new Exception(String.Format(
                                        "Device {0} is not a thermostat",
                                        applianceId
                                        ));
            }
            return(device);
        }
Esempio n. 3
0
        private Object HandleDecrementTargetTemperatureRequest(JObject request)
        {
            DeltaTargetTemperatureRequestPayload payload =
                JsonConvert.DeserializeObject <DeltaTargetTemperatureRequestPayload>(
                    request["payload"].ToString()
                    );

            AlexaThermostat device      = DeviceList.GetThermostat(payload.Appliance.ApplianceId);
            double          targetTempC = device.targetTemperatureC - payload.DeltaTemperature.Value;

            return(HandleTemperatureChangeRequest(
                       DirectiveName.DecrementTargetTemperatureConfirmation,
                       device,
                       targetTempC
                       ));
        }
Esempio n. 4
0
        private Object HandleGetTargetTemperatureRequest(
            DirectiveName responseName,
            AlexaThermostat device
            )
        {
            TemperatureMode mode = new TemperatureMode()
            {
                Value = device.mode.ToString(),
            };
            GetTargetTemperatureResponsePayload payload;

            if (device.mode == ThermostatMode.OFF)
            {
                payload = new GetTargetTemperatureResponsePayload()
                {
                    TemperatureMode = mode
                };
            }
            else
            {
                payload = new GetTargetTemperatureResponsePayload()
                {
                    TargetTemperature = new TargetTemperature()
                    {
                        Value = device.targetTemperatureC,
                    },
                    TemperatureMode = mode
                };
            }
            return(new Response()
            {
                Header = new Header()
                {
                    Namespace = "Alexa.ConnectedHome.Query",
                    Name = responseName,
                    PayloadVersion = "2",
                    MessageID = Guid.NewGuid(),
                },
                Payload = payload,
            });
        }
Esempio n. 5
0
 private Object HandleGetTemperatureReadingRequest(
     DirectiveName responseName,
     AlexaThermostat device
     )
 {
     return(new Response()
     {
         Header = new Header()
         {
             Namespace = "Alexa.ConnectedHome.Query",
             Name = responseName,
             PayloadVersion = "2",
             MessageID = Guid.NewGuid(),
         },
         Payload = new GetTemperatureReadingResponsePayload()
         {
             TemperatureReading = new TargetTemperature()
             {
                 Value = device.currentTemperatureC,
             }
         },
     });
 }
Esempio n. 6
0
        private Object HandleTemperatureChangeRequest(
            DirectiveName responseName,
            AlexaThermostat device,
            double setTempC
            )
        {
            if (device.mode == ThermostatMode.OFF)
            {
                return(new Response()
                {
                    Header = new Header()
                    {
                        Namespace = "Alexa.ConnectedHome.Control",
                        Name = DirectiveName.UnwillingToSetValueError,
                        PayloadVersion = "2",
                        MessageID = Guid.NewGuid(),
                    },
                    Payload = new UnwillingToSetValueErrorPayload()
                    {
                        ErrorInfo = new ErrorInfo()
                        {
                            Code = "THERMOSTAT_IS_OFF",
                            Description = "Can't complete requested operation because the thermostat is off",
                        }
                    },
                });
            }

            double setTempF      = setTempC * 1.8 + 32.0;
            ushort convertedTemp = Convert.ToUInt16(Math.Round(setTempF * 10.0, 0));

            device.SetTemp(convertedTemp);

            return(new Response()
            {
                Header = new Header()
                {
                    Namespace = "Alexa.ConnectedHome.Control",
                    Name = responseName,
                    PayloadVersion = "2",
                    MessageID = Guid.NewGuid(),
                },
                Payload = new SetTargetTemperatureConfirmationPayload()
                {
                    TargetTemperature = new TargetTemperature()
                    {
                        Value = setTempC,
                    },
                    TemperatureMode = new TemperatureMode()
                    {
                        Value = device.mode.ToString(),
                    },
                    PreviousState = new TargetTemperaturePreviousState()
                    {
                        TargetTemperature = new TargetTemperature()
                        {
                            Value = device.targetTemperatureC,
                        },
                        TemperatureMode = new TemperatureMode()
                        {
                            Value = device.mode.ToString(),
                        }
                    },
                },
            });
        }