Exemple #1
0
 /// <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);
 }
Exemple #2
0
 /// <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;
 }
Exemple #3
0
 /// <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);
 }