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); }
private async Task <bool> SetWemoPlugAsync(string ipAddress, bool on) { bool success = true; var plug = new WemoPlug { WebRequest = this.WebRequest }; var existingState = await GetWemoResponseObjectAsync <GetBinaryStateResponse>(Soap.WemoGetCommands.GetBinaryState, ipAddress); if (on && existingState.BinaryState == "0") { success = await plug.SetBinaryStateAsync(Soap.WemoSetBinaryStateCommands.BinaryState, ipAddress, true); } if (!on && existingState.BinaryState == "1") { success = await plug.SetBinaryStateAsync(Soap.WemoSetBinaryStateCommands.BinaryState, ipAddress, false); } return(success); }