public static HttpWebRequest CreateSetBinaryStateCommandHttpWebRequest(string ipAddress, string contentType, string soapAction, Soap.WemoSetBinaryStateCommands cmd, string requestMethod) { var req = CreateHttpWebRequest(ipAddress, contentType, soapAction, cmd.ToString(), requestMethod); return(req); }
public async Task <bool> ToggleWemoPlugAsync(Soap.WemoSetBinaryStateCommands cmd, string ipAddress) { var plug = new WemoPlug { WebRequest = this.WebRequest }; var existingState = await GetWemoResponseObjectAsync <GetBinaryStateResponse>(Soap.WemoGetCommands.GetBinaryState, ipAddress); var binaryStateValue = false; switch (existingState.BinaryState) { case "0": binaryStateValue = true; break; case "1": binaryStateValue = false; break; } var response = await plug.SetBinaryStateAsync(cmd, ipAddress, binaryStateValue); return(response); }
public async Task <bool> SetBinaryStateAsync(Soap.WemoSetBinaryStateCommands cmd, string ipAddress, bool targetStatus) { bool success = false; var target = Convert.ToInt32(targetStatus); var request = CreateBinaryStateHttpWebRequest(Soap.WemoGetCommands.SetBinaryState, ipAddress); var response = await GetBinaryStateResponseAsync(cmd.ToString(), request, target.ToString()); var responsObj = GetResponseObject <SetBinaryStateResponse>(response); if (responsObj.BinaryState == "0" || responsObj.BinaryState == "1") { success = true; } return(success); }
public async Task <bool> SetBinaryStateAsync(Soap.WemoSetBinaryStateCommands cmd, string ipAddress, bool targetStatus) { bool success = false; var target = Convert.ToInt32(targetStatus); // Construct the HttpWebRequest - if not null we will use the supplied HttpWebRequest object, else create var request = WebRequest ?? HttpRequest.CreateHttpWebRequest($"{ipAddress}:{Port}{Event}", ContentType, SoapAction, "SetBinaryState", RequestMethod); var response = await GetBinaryStateResponseAsync(cmd.ToString(), request, target.ToString()); var responsObj = GetResponseObject <SetBinaryStateResponse>(response); if (responsObj.BinaryState == "0" || responsObj.BinaryState == "1") { success = true; } return(success); }