public async Task <T> GetWemoResponseObjectAsync <T>(Soap.WemoGetCommands cmd, string ipAddress) { if (cmd == Soap.WemoGetCommands.GetPower || cmd == Soap.WemoGetCommands.GetInsightParams) { var plug = new WemoInsightPlug { WebRequest = this.WebRequest }; var response = await plug.GetResponseAsync(cmd, ipAddress); var objResponse = plug.GetResponseObject <T>(response); return((T)objResponse); } else { var plug = new WemoPlug { WebRequest = this.WebRequest }; var response = await plug.GetResponseAsync(cmd, ipAddress); var objResponse = plug.GetResponseObject <T>(response); return((T)objResponse); } }
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); }
/// <summary> /// Check to see if a given IP address is for a Wemo device. /// </summary> /// <param name="ipAddress">e.g. http://192.168.1.101</param> /// <returns>A KeyValuePair<string,string> populated with the ipaddress and friendly name if an existing Wemo device</string> object .</returns> public async Task <KeyValuePair <string, string> > IsLocalWemoDeviceAsync(string ipAddress) { var plug = new WemoPlug(PortNumber) { BinarySetRequest = _binarySetRequest }; return(await plug.IsLocalWemoDeviceAsync(ipAddress)); }
/// <summary> /// Call the command to construct a soap Http Request - returning a translated response object /// </summary> /// <param name="cmd"></param> /// <param name="ipAddress"></param> /// <returns></returns> public async Task <WemoResponse> GetWemoPlugResponseAsync(Soap.WemoGetCommands cmd, string ipAddress) { var plug = new WemoPlug { WebRequest = this.WebRequest }; var response = await plug.GetResponseAsync(cmd, ipAddress); return(response); }
/// <summary> /// Get a list of Wemo devices that exist within a local network. /// This process may take 2 or more minutes to complete! /// </summary> /// <param name="ipAddressSeed">The first 3 sections of an IP address, including 'http://'. Example: 'http://192.168.1'</param> /// <returns>A thread-safe ConcurrentDictionary collection of IpAddress/FriendlyName pairs.</returns> public ConcurrentDictionary <string, string> GetListOfLocalWemoDevices(string ipAddressSeed) { var plug = new WemoPlug { SetResponseWebRequest = SetResponseWebRequest }; var response = plug.GetListOfLocalWemoDevices(ipAddressSeed); return(response); }
/// <summary> /// Call the command to construct a soap Http Request - returning a translated response object /// </summary> /// <param name="cmd"></param> /// <param name="ipAddress"></param> /// <returns></returns> internal async Task <WemoResponse> GetWemoPlugResponseAsync(Soap.WemoGetCommands cmd, string ipAddress) { var plug = new WemoPlug(PortNumber) { Request = _request }; var response = await plug.GetResponseAsync(cmd, ipAddress); return(response); }
/// <summary> /// Get a list of Wemo devices that exist within a local network. /// This process may take 2 or more minutes to complete! /// </summary> /// <param name="octetOne">The first octet of an IP address, e.g. 192 - from an Ip adress of: http://192.168.86.1</param> /// <param name="octetTwo">The second octet of an IP address, e.g. 168 - from an Ip adress of: http://192.168.86.1</param> /// <param name="octetThree">The third octet of an IP address, e.g. 86 - from an Ip adress of: http://192.168.86.1</param> /// <returns>A thread-safe ConcurrentDictionary collection of IpAddress/FriendlyName pairs.</returns> public async Task <ConcurrentDictionary <string, string> > GetListOfLocalWemoDevicesAsync(int octetOne, int octetTwo, int octetThree) { var ipAddressSeed = $"http://{octetOne}.{octetTwo}.{octetThree}"; var plug = new WemoPlug(PortNumber) { BinarySetRequest = _binarySetRequest }; var response = await plug.GetListOfLocalWemoDevicesAsync(ipAddressSeed); return(response); }
internal async Task <string> GetWemoResponseValueAsync(Soap.WemoGetCommands cmd, string ipAddress) { var plug = new WemoPlug { GetResponseWebRequest = GetResponseWebRequest }; var response = await plug.GetResponseAsync(cmd, ipAddress); var value = plug.GetResponseValue(response); return(value); }
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); }
/// <summary> /// Acquire the existing state of the target Wemo plug. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="cmd"></param> /// <param name="ipAddress"></param> /// <returns></returns> internal async Task <T> GetWemoResponseObjectAsync <T>(string ipAddress) { var typeofObject = typeof(T); // Determine which command to use, per object type Soap.WemoGetCommands cmd = GenerateWemoCommand(typeofObject); if (cmd == Soap.WemoGetCommands.Null) { throw new System.Exception($"Object not supported: {typeofObject.ToString()}"); } var plug = new WemoPlug(PortNumber) { Request = _request }; var response = await plug.GetResponseAsync(cmd, ipAddress); var objResponse = plug.GetResponseObject <T>(response); return((T)objResponse); }
/// <summary> /// Acquire the existing state of the target Wemo plug. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="cmd"></param> /// <param name="ipAddress"></param> /// <returns></returns> internal async Task <T> GetWemoResponseObjectAsync <T>(string ipAddress) { Soap.WemoGetCommands cmd = Soap.WemoGetCommands.Null; var obj = typeof(T); // Determine which command to use, per object if (obj == typeof(GetBinaryStateResponse)) { cmd = Soap.WemoGetCommands.GetBinaryState; } if (obj == typeof(GetFriendlyNameResponse)) { cmd = Soap.WemoGetCommands.GetFriendlyName; } if (obj == typeof(GetHomeInfoResponse)) { cmd = Soap.WemoGetCommands.GetHomeInfo; } if (cmd == Soap.WemoGetCommands.Null) { throw new System.Exception($"Object not supported: {obj.ToString()}"); } var plug = new WemoPlug { GetResponseWebRequest = GetResponseWebRequest }; var response = await plug.GetResponseAsync(cmd, ipAddress); var objResponse = plug.GetResponseObject <T>(response); return((T)objResponse); }