public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            Enums.DeviceTypes terminationType = (Enums.DeviceTypes)value;

            switch (terminationType)
            {
            case Enums.DeviceTypes.Heating:
                writer.WriteValue("HEATING");
                break;

            case Enums.DeviceTypes.HotWater:
                writer.WriteValue("HOT_WATER");
                break;
            }
        }
示例#2
0
文件: Session.cs 项目: ealse/TadoApi
        /// <summary>
        /// Sets the temperature in a zone in the home with the provided Id through the Tado API for the duration as specified
        /// </summary>
        /// <param name="homeId">Id of the home to set the temperature of</param>
        /// <param name="zoneId">Id of the zone to set the temperature of</param>
        /// <param name="temperatureCelcius">Temperature in Celcius to set the zone to. Provide NULL for both temperatureCelcius and temperatureFahrenheit to switch the device off.</param>
        /// <param name="temperatureFahrenheit">Temperature in Fahrenheit to set the zone to. Provide NULL for both temperatureCelcius and temperatureFahrenheit to switch the device off.</param>
        /// <param name="durationMode">Defines the duration for which the heating will be switched to the provided temperature</param>
        /// <param name="timer">Only applicapble if for durationMode Timer has been chosen. In that case it allows providing for how long the duration should be.</param>
        /// <param name="deviceType">Type of Tado device to switch on</param>
        /// <returns>The summarized new state of the zone</returns>
        public async Task <Entities.ZoneSummary> SetTemperature(int homeId, int zoneId, double?temperatureCelcius, double?temperatureFahrenheit, Enums.DeviceTypes deviceType, Enums.DurationModes durationMode, TimeSpan?timer = null)
        {
            // If using Timer mode but not providing a timer duration, switch it to manual
            if (durationMode == Enums.DurationModes.Timer && timer == null)
            {
                durationMode = Enums.DurationModes.UntilNextManualChange;
            }

            EnsureAuthenticatedSession();

            // Define the proper command for the provided duration mode
            var overlay = new Entities.Overlay
            {
                Setting = new Entities.Setting
                {
                    DeviceType = deviceType
                },
                Termination = new Entities.Termination
                {
                    CurrentType = durationMode
                }
            };

            // If no temperature in Celcius and Fahrenheit has been provided, instruct to switch the device off, otherwise instruct to switch it on
            overlay.Setting.Power = !temperatureCelcius.HasValue && !temperatureFahrenheit.HasValue ? Enums.PowerStates.Off : Enums.PowerStates.On;

            // If the device is about to be switched on, provide the temperature it should be switched to
            if (overlay.Setting.Power == Enums.PowerStates.On)
            {
                overlay.Setting.Temperature = new Entities.Temperature
                {
                    Celsius    = temperatureCelcius,
                    Fahrenheit = temperatureFahrenheit
                };
            }

            if (durationMode == Enums.DurationModes.Timer)
            {
                overlay.Termination.DurationInSeconds = (int)timer.Value.TotalSeconds;
            }

            var request = JsonConvert.SerializeObject(overlay);

            var response = await SendMessageReturnResponse <Entities.ZoneSummary>(request, HttpMethod.Put, new Uri(TadoApiBaseUrl, $"homes/{homeId}/zones/{zoneId}/overlay"), HttpStatusCode.OK);

            return(response);
        }