diff --git a/MiHomeLib/Commands/GatewayLightCommand.cs b/MiHomeLib/Commands/GatewayLightCommand.cs index 1f3c4f1..f4d7ff3 100644 --- a/MiHomeLib/Commands/GatewayLightCommand.cs +++ b/MiHomeLib/Commands/GatewayLightCommand.cs @@ -1,19 +1,17 @@ namespace MiHomeLib.Commands { - internal class GatewayLightCommand: Command + internal class GatewayLightCommand : Command { private readonly long _rgb; - private readonly int _illumination; - public GatewayLightCommand(long rgb, int illumination) + public GatewayLightCommand(long rgb) { _rgb = rgb; - _illumination = illumination; } public override string ToString() { - return $"{{\"rgb\":{_rgb},\"illumination\":{_illumination}}}"; + return $"{{\"rgb\":{_rgb}}}"; } } } \ No newline at end of file diff --git a/MiHomeLib/Devices/Gateway.cs b/MiHomeLib/Devices/Gateway.cs index c945997..54f98f4 100644 --- a/MiHomeLib/Devices/Gateway.cs +++ b/MiHomeLib/Devices/Gateway.cs @@ -43,18 +43,18 @@ public override string ToString() return $"Rgb: {Rgb}, Illumination: {Illumination}, ProtoVersion: {ProtoVersion}"; } - public void EnableLight(byte r = 255, byte g = 255, byte b = 255, int illumination = 1000) + public void EnableLight(byte r = 255, byte g = 255, byte b = 255, int brightness = 100) { - var rgb = 0xFF000000 | r << 16 | g << 8 | b; // found this trick from chinise gateway docs + var rgb = (uint)brightness << 24 | r << 16 | g << 8 | b; - if (illumination < 300 || illumination > 1300) throw new ArgumentException("Illumination must be in range 300 - 1300"); + if (brightness < 1 || brightness > 100) throw new ArgumentException("Brightness must be in range 1 - 100"); - _transport.SendWriteCommand(Sid, Type, new GatewayLightCommand(rgb, illumination)); + _transport.SendWriteCommand(Sid, Type, new GatewayLightCommand(rgb)); } public void DisableLight() { - _transport.SendWriteCommand(Sid, Type, new GatewayLightCommand(0, 0)); + _transport.SendWriteCommand(Sid, Type, new GatewayLightCommand(0)); } public void StartPlayMusic(int midNo = 0) diff --git a/MiHomeLib/MiHome.cs b/MiHomeLib/MiHome.cs index 729e90e..dcaf948 100644 --- a/MiHomeLib/MiHome.cs +++ b/MiHomeLib/MiHome.cs @@ -136,7 +136,6 @@ private async Task StartReceivingMessages(CancellationToken ct) private void ProcessReport(ResponseCommand cmd) { - if (_gateway != null && cmd.Sid == _gateway.Sid) return; GetOrAddDeviceByCommand(cmd).ParseData(cmd.Data); } @@ -160,6 +159,8 @@ private void ProcessReadAck(ResponseCommand cmd) private MiHomeDevice GetOrAddDeviceByCommand(ResponseCommand cmd) { + if (_gateway != null && cmd.Sid == _gateway.Sid) return _gateway; + if (_devicesList.ContainsKey(cmd.Sid)) return _devicesList[cmd.Sid]; var device = _devicesMap[cmd.Model](cmd.Sid);