Wireless Switch
jurgen-kluft opened this issue · 3 comments
jurgen-kluft commented
Here is the code for the Wireless Switch, have one at home and are running your library with this added Switch, works nicely.
using System;
using Newtonsoft.Json.Linq;
namespace MiHomeLib.Devices
{
public class WirelessSwitch : MiHomeDevice
{
public event EventHandler OnClick;
public event EventHandler OnDoubleClick;
public event EventHandler OnLongClickRelease;
public event EventHandler OnLongClickPress;
public WirelessSwitch(string sid) : base(sid, "switch")
{
Status = "idle";
}
public float? Voltage { get; set; }
public string Status { get; private set; }
public override void ParseData(string command)
{
var jObject = JObject.Parse(command);
if (jObject["status"] != null)
{
Status = jObject["status"].ToString();
if (Status == "click")
{
OnClick?.Invoke(this, EventArgs.Empty);
}
else if (Status == "double_click")
{
OnDoubleClick?.Invoke(this, EventArgs.Empty);
}
else if (Status == "long_click_press")
{
OnLongClickPress?.Invoke(this, EventArgs.Empty);
}
else if (Status == "long_click_release")
{
OnLongClickRelease?.Invoke(this, EventArgs.Empty);
}
}
if (jObject["voltage"] != null && float.TryParse(jObject["voltage"].ToString(), out float v))
{
Voltage = v / 1000;
}
}
public override string ToString()
{
return $"Status: {Status}, Voltage: {Voltage}V";
}
}
}
sergey-brutsky commented
Hello,
Code for wireless switch was added in the latest relese, pleae check this link https://www.nuget.org/packages/MiHomeLib/
jurgen-kluft commented
👍 ha i just missed that, thanks !
sergey-brutsky commented
Closing because required functionality is already implemented