internal static async Task SendCommandAsync(string host, AutomationCommand command) { if (_client == null) { _client = new HttpClient(); _client.BaseAddress = new Uri(host); _client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); } var request = new HttpRequestMessage(HttpMethod.Post, $"rest/items/{command.Item}"); string itemCommand = GetItemCommand(command); request.Content = new StringContent(itemCommand, Encoding.ASCII, "text/plain"); var response = await _client.SendAsync(request); ValidateResponse(response); }
private static string GetItemCommand(AutomationCommand command) { // Check if item is a reserved word and convert it accordingly string itemCommand = command.Command; if (!itemCommand.StartsWith("|") || !itemCommand.EndsWith("|")) { return(itemCommand); } if (itemCommand.Equals(_TimeStamp)) { return(DateTime.Now.ToString()); } Logger.Error($"[Automation:GetCommandItem] The following reserved automation command is not recognized: {itemCommand}"); return(string.Empty); }
internal static string GenerateKey(AutomationCommand command) { return($"{command.Device}_{command.Event}"); }