Skip to content

Commit

Permalink
Merge pull request #13 from userof/addeddevices
Browse files Browse the repository at this point in the history
added wall double button switch remote.b286acn01
  • Loading branch information
sergey-brutsky committed Aug 25, 2019
2 parents a7841c2 + 8ad5296 commit 474f5cd
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 1 deletion.
65 changes: 65 additions & 0 deletions MiHomeLib/Devices/WirelessDualWallSwitch.cs
@@ -0,0 +1,65 @@
using System;
using Newtonsoft.Json.Linq;

namespace MiHomeLib.Devices
{
public class WirelessDualWallSwitch : MiHomeDevice
{
private const string LeftChannel = "channel_0";
private const string RightChannel = "channel_1";

public event Action<EventArgs> OnRightClick;
public event Action<EventArgs> OnLeftClick;

public event Action<EventArgs> OnRightDoubleClick;
public event Action<EventArgs> OnLeftDoubleClick;

public event Action<EventArgs> OnRightLongClick;
public event Action<EventArgs> OnLeftLongClick;

public override void ParseData(string command)
{
var jObject = JObject.Parse(command);

if (jObject[LeftChannel] != null)
{

if (jObject[LeftChannel].Value<string>() == "click")
{
OnLeftClick?.Invoke(new EventArgs());
}
else if (jObject[LeftChannel].Value<string>() == "double_click")
{
OnLeftDoubleClick?.Invoke(new EventArgs());
}
else if (jObject[LeftChannel].Value<string>() == "long_click")
{
OnLeftLongClick?.Invoke(new EventArgs());
}

}

if (jObject[RightChannel] != null)
{
if (jObject[RightChannel].Value<string>() == "click")
{
OnRightClick?.Invoke(new EventArgs());
}
else if (jObject[RightChannel].Value<string>() == "double_click")
{
OnRightDoubleClick?.Invoke(new EventArgs());
}
else if (jObject[RightChannel].Value<string>() == "long_click")
{
OnRightLongClick?.Invoke(new EventArgs());
}
}

}

public WirelessDualWallSwitch(string sid) : base(sid, "remote.b286acn01")
{

}
}
}
3 changes: 2 additions & 1 deletion MiHomeLib/MiHome.cs
Expand Up @@ -33,7 +33,8 @@ public class MiHome : IDisposable
{"sensor_wleak.aq1", sid => new WaterLeakSensor(sid)},
{"smoke", sid => new SmokeSensor(sid)},
{"switch", sid => new Switch(sid)},
{"ctrl_neutral2", sid => new WiredDualWallSwitch(sid)}
{"ctrl_neutral2", sid => new WiredDualWallSwitch(sid)},
{"remote.b286acn01", sid => new WirelessDualWallSwitch(sid)},
};

private readonly Dictionary<string, Action<ResponseCommand>> _commandsToActions;
Expand Down

0 comments on commit 474f5cd

Please sign in to comment.