Esempio n. 1
0
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            Enums.DurationModes durationMode = (Enums.DurationModes)value;

            switch (durationMode)
            {
            case Enums.DurationModes.UntilNextManualChange:
                writer.WriteValue("MANUAL");
                break;

            case Enums.DurationModes.UntilNextTimedEvent:
                writer.WriteValue("TADO_MODE");
                break;

            case Enums.DurationModes.Timer:
                writer.WriteValue("TIMER");
                break;
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Switches the hot water off 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 switch the heating off in</param>
 /// <param name="durationMode">Defines the duration for which the temperature will remain switched off</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>
 /// <returns>The summarized new state of the zone</returns>
 public async Task <Entities.ZoneSummary> SwitchHotWaterOff(int homeId, Enums.DurationModes durationMode, TimeSpan?timer = null)
 {
     return(await SetTemperature(homeId, 0, null, null, Enums.DeviceTypes.HotWater, durationMode, timer));
 }
Esempio n. 3
0
 /// <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="temperature">Temperature to set the zone to</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>
 /// <returns>The summarized new state of the zone</returns>
 public async Task <Entities.ZoneSummary> SetHeatingTemperatureFahrenheit(int homeId, int zoneId, double temperature, Enums.DurationModes durationMode, TimeSpan?timer = null)
 {
     return(await SetTemperature(homeId, zoneId, null, temperature, Enums.DeviceTypes.Heating, durationMode, timer));
 }
Esempio n. 4
0
        /// <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);
        }
Esempio n. 5
0
 /// <summary>
 /// Sets the hot water temperature 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="temperatureFahrenheit">Temperature in Fahrenheit to set the zone to</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>
 /// <returns>The summarized new state of the zone</returns>
 public async Task <Entities.ZoneSummary> SetHotWaterTemperatureFahrenheit(int homeId, double temperatureFahrenheit, Enums.DurationModes durationMode, TimeSpan?timer = null)
 {
     // Tado Hot Water is zone 0
     return(await SetTemperature(homeId, 0, null, temperatureFahrenheit, Enums.DeviceTypes.HotWater, durationMode, timer));
 }
Esempio n. 6
0
 public async Task <Entities.ZoneSummary> SetTemperatureCelcius(int homeId, int zoneId, double temperature, Enums.DurationModes durationMode, TimeSpan?timer = null)
 {
     return(await SetHeatingTemperatureCelcius(homeId, zoneId, temperature, durationMode, timer));
 }