/// <summary> /// Handles commands for the Harmony published to MQTT. /// </summary> /// <param name="e">Event args.</param> protected override async void Mqtt_MqttMsgPublishReceived(MqttApplicationMessageReceivedEventArgs e) { var message = Encoding.UTF8.GetString(e.ApplicationMessage.Payload); _log.LogInformation("MQTT message received for topic " + e.ApplicationMessage.Topic + ": " + message); switch (e.ApplicationMessage.Topic.Substring(TopicRoot.Length)) { case "/dock/set": await _client.SendToBaseAsync() .ConfigureAwait(false); break; case "/findMe/set": await _client.FindMeAsync() .ConfigureAwait(false); break; case "/start/set": var cleaningSettings = !string.IsNullOrEmpty(message) && message.Contains("{") ? JsonConvert.DeserializeObject <StartCleaningParameters>(message) : new StartCleaningParameters { Category = Enum.Parse <CleaningCategory>(_topicMap[$"{TopicRoot}/cleaning/category"]), Mode = Enum.Parse <CleaningMode>(_topicMap[$"{TopicRoot}/cleaning/mode"]), Modifier = CleaningFrequency.Normal, NavigationMode = Enum.Parse <NavigationMode>(_topicMap[$"{TopicRoot}/cleaning/navigationMode"]) }; await _client.StartCleaningAsync(cleaningSettings) .ConfigureAwait(false); break; case "/stop/set": await _client.StopCleaningAsync() .ConfigureAwait(false); break; case "/pause/set": await _client.PauseCleaningAsync() .ConfigureAwait(false); break; case "/resume/set": await _client.ResumeCleaningAsync() .ConfigureAwait(false); break; case "/startPersistentMapExploration/set": await _client.StartPersistentMapExplorationAsync() .ConfigureAwait(false); break; case "/enableSchedule/set": if (message == "true") { await _client.EnableScheduleAsync() .ConfigureAwait(false); } else { await _client.DisableScheduleAsync() .ConfigureAwait(false); } break; case "/dismissCurrentAlert/set": await _client.DismissCurrentAlertAsync() .ConfigureAwait(false); break; } await RefreshStateAsync() .ConfigureAwait(false); }