/// <summary> /// Activate the economy mode for the given amount of minutes. /// Possible Eventbus Notifications: HOME_CHANGED /// </summary> /// <param name="duration">The amount of minutes that the economy mode should be activated.</param> /// <param name="cancellationToken"></param> /// <returns></returns> public async Task <bool> ActivateAbsenceWithDuration(EcoDuration ecoDuration, CancellationToken cancellationToken = default) { HttpResponseMessage httpResponseMessage; if (ecoDuration != EcoDuration.PERMANENT) { var duration = ecoDuration switch { EcoDuration.ONE => 1 * 60, EcoDuration.TWO => 2 * 60, EcoDuration.FOUR => 4 * 60, EcoDuration.SIX => 6 * 60, _ => throw new NotImplementedException() }; var requestObject = new ActivateAbsenceWithDurationRequestObject(duration); var stringContent = GetStringContent(requestObject); httpResponseMessage = await HttpClient.PostAsync("hmip/home/heating/activateAbsenceWithDuration", stringContent, cancellationToken); } else { httpResponseMessage = await HttpClient.PostAsync("hmip/home/heating/activateAbsencePermanent", ClientCharacteristicsStringContent, cancellationToken); } if (httpResponseMessage.IsSuccessStatusCode) { return(true); } throw new ArgumentException($"Request failed: {httpResponseMessage.ReasonPhrase}"); }
/// <summary> /// Set the default duration of the economy mode if the eco push button is pressed. /// Possible event bus notifications HOME_CHANGED. /// Solution = INDOOR_CLIMATE /// </summary> /// <param name="ecoDuration">The duration of the economy mode for activation with the eco push button</param> /// <param name="cancellationToken"></param> /// <returns></returns> public async Task <bool> SetEcoDuration(EcoDuration ecoDuration, CancellationToken cancellationToken = default) { var requestObject = new SetEcoDurationRequestObject(ecoDuration); using var stringContent = GetStringContent(requestObject); using var httpResponseMessage = await HttpClient.PostAsync("hmip/home/heating/setEcoDuration", stringContent, cancellationToken); if (httpResponseMessage.IsSuccessStatusCode) { return(true); } throw new ArgumentException($"Request failed: {httpResponseMessage.ReasonPhrase}"); }
public SetEcoDurationRequestObject(EcoDuration ecoDuration) { EcoDuration = ecoDuration; }