/// <summary> /// Sets the state of the switch. /// </summary> /// <param name="device">The device.</param> /// <param name="state">if set to <c>true</c> [state].</param> public static void SetSwitchState(this WemoSwitch device, bool state) { device.InvokeServiceAction("basicevent", "SetBinaryState", new Dictionary <string, string>() { ["BinaryState"] = state ? "1" : "0" }); device.State = state; }
/// <summary> /// Queries the state of the switch. /// </summary> /// <param name="device">The device.</param> public static void QuerySwitchState(this WemoSwitch device) { if (device.DeviceType == "urn:Belkin:device:insight:1") { device.QueryInsightState(); } else { device.State = device.InvokeServiceAction("basicevent", "GetBinaryState").InnerText == "1"; } device.Signal = int.Parse(device.InvokeServiceAction("basicevent", "GetSignalStrength").InnerText); }
/// <summary> /// Queries the state of the insight device. /// </summary> /// <param name="device">The device.</param> public static void QueryInsightState(this WemoSwitch device) { string[] data = device.InvokeServiceAction("insight", "GetInsightParams").InnerText.Split('|'); device.State = data[0] == "1"; device.LastChange = double.Parse(data[1]).UnixTimeStampToDateTime(); device.OnFor = TimeSpan.FromSeconds(double.Parse(data[2])); device.OnToday = TimeSpan.FromSeconds(double.Parse(data[3])); device.OnTotal = TimeSpan.FromSeconds(double.Parse(data[4])); device.TimePeriod = TimeSpan.FromSeconds(double.Parse(data[5])); device.Thresold = double.Parse(data[6]); device.CurrentMW = double.Parse(data[7], CultureInfo.InvariantCulture); device.TodayMW = double.Parse(data[8], CultureInfo.InvariantCulture); device.TotalMW = double.Parse(data[9], CultureInfo.InvariantCulture); }
private void Scanner_WemoDeviceFound(object sender, WemoScanner.WemoDeviceFoundEventArgs e) { // Wemo device found ! PackageHost.WriteInfo("Found {0} ({1}) on {2}", e.Device.FriendlyName, e.Device.ModelDescription, e.Device.Location.Host); // Just support Wemo Switch & Insight for now - Bridge, Motion, LightSwitch or Maker devices are not currently supported ! if (e.Device.DeviceType == "urn:Belkin:device:insight:1" || e.Device.DeviceType == "urn:Belkin:device:controllee:1") { WemoSwitch swDevice = e.Device.ChangeDeviceType <WemoSwitch>(); try { // Initial query state & icon swDevice.IconUrl = e.Device.InvokeServiceAction("basicevent", "GetIconURL").InnerText; swDevice.QuerySwitchState(); } catch { } lock (switchDevices) { switchDevices[e.Device.SerialNumber.ToUpper()] = swDevice; } } // Push any Wemo devices PackageHost.PushStateObject <WemoDevice>(e.Device.SerialNumber, e.Device); }