From 60f381a83909b2aca3cb5b8c940580bd3cdc72b0 Mon Sep 17 00:00:00 2001 From: romain oddone Date: Mon, 22 Nov 2021 21:54:31 +0100 Subject: [PATCH 1/9] start work about music mode and automatic port choosing --- YeelightAPI/Core/MusicModeInformations.cs | 27 ++++++++ YeelightAPI/Core/NetworkHelper.cs | 70 ++++++++++++++++++++ YeelightAPI/Device.IDeviceController.cs | 19 ++++-- YeelightAPI/Device.cs | 25 ++++--- YeelightAPI/DeviceGroup.IDeviceController.cs | 39 +++++++++-- 5 files changed, 154 insertions(+), 26 deletions(-) create mode 100644 YeelightAPI/Core/MusicModeInformations.cs create mode 100644 YeelightAPI/Core/NetworkHelper.cs diff --git a/YeelightAPI/Core/MusicModeInformations.cs b/YeelightAPI/Core/MusicModeInformations.cs new file mode 100644 index 0000000..cd7fef4 --- /dev/null +++ b/YeelightAPI/Core/MusicModeInformations.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace YeelightAPI.Core +{ + /// + /// Informations about device music mode + /// + public class MusicModeInformations + { + /// + /// The host name + /// + public string HostName { get; internal set; } + + /// + /// The used port + /// + public int Port { get; internal set; } + + /// + /// Music mode enabled or not ? + /// + public bool Enabled { get; internal set; } + } +} diff --git a/YeelightAPI/Core/NetworkHelper.cs b/YeelightAPI/Core/NetworkHelper.cs new file mode 100644 index 0000000..c017169 --- /dev/null +++ b/YeelightAPI/Core/NetworkHelper.cs @@ -0,0 +1,70 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net; +using System.Net.NetworkInformation; +using System.Net.Sockets; +using System.Text; + +namespace YeelightAPI.Core +{ + public static class NetworkHelper + { + /// + /// Get the current IP adress + /// + /// + public static string GetLocalIpAddress() + { + using (Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, 0)) + { + socket.Connect("8.8.8.8", 65530); + IPEndPoint endPoint = socket.LocalEndPoint as IPEndPoint; + return endPoint.Address.ToString(); + } + } + + /// + /// Get the next available port + /// + /// the port number to start searching from + /// + public static int GetNextAvailablePort(int startingPort = 0) + { + IPEndPoint[] endPoints; + List portArray = new List(); + + IPGlobalProperties properties = IPGlobalProperties.GetIPGlobalProperties(); + + //getting active connections + TcpConnectionInformation[] connections = properties.GetActiveTcpConnections(); + if (connections.Any(c => c.LocalEndPoint.Port >= startingPort)) + { + portArray.Add(connections.First(c => c.LocalEndPoint.Port >= startingPort).LocalEndPoint.Port); + } + + //getting active tcp listners + endPoints = properties.GetActiveTcpListeners(); + if (endPoints.Any(c => c.Port >= startingPort)) + { + portArray.Add(endPoints.First(c => c.Port >= startingPort).Port); + } + + //getting active udp listeners + endPoints = properties.GetActiveUdpListeners(); + if (endPoints.Any(c => c.Port >= startingPort)) + { + portArray.Add(endPoints.First(c => c.Port >= startingPort).Port); + } + + if (portArray.Count != 0) + { + portArray.Sort(); + return portArray.First(); + } + + throw new Exception("No Available Port"); + + } + } +} diff --git a/YeelightAPI/Device.IDeviceController.cs b/YeelightAPI/Device.IDeviceController.cs index c3d6ea3..1b66875 100644 --- a/YeelightAPI/Device.IDeviceController.cs +++ b/YeelightAPI/Device.IDeviceController.cs @@ -340,15 +340,19 @@ public async Task StartColorFlow(ColorFlow flow) /// /// /// - public async Task StartMusicMode(string hostname = null, int port = 12345) + public async Task StartMusicMode(string hostname = null, int? port = null) { //init new TCP socket if (string.IsNullOrWhiteSpace(hostname)) { - hostname = GetLocalIpAddress(); + hostname = NetworkHelper.GetLocalIpAddress(); + } + if (!port.HasValue) + { + port = NetworkHelper.GetNextAvailablePort(port ?? 0); } - var listener = new TcpListener(System.Net.IPAddress.Parse(hostname), port); + var listener = new TcpListener(System.Net.IPAddress.Parse(hostname), port.Value); listener.Start(); List parameters = new List() { (int)MusicAction.On, hostname, port }; @@ -356,10 +360,12 @@ public async Task StartMusicMode(string hostname = null, int port = 12345) CommandResult> result = await ExecuteCommandWithResponse>( method: METHODS.SetMusicMode, parameters: parameters); - + if (result.IsOk()) { - this.IsMusicModeEnabled = true; + this.MusicMode.Enabled = true; + this.MusicMode.HostName = hostname; + this.MusicMode.Port = port.Value; this.Disconnect(); var musicTcpClient = await listener.AcceptTcpClientAsync(); _tcpClient = musicTcpClient; @@ -395,8 +401,7 @@ public async Task StopMusicMode() if (result.IsOk()) { //disables the music mode - this.IsMusicModeEnabled = false; - await DisableMusicModeAsync(); + this.MusicMode.Enabled = false; return true; } diff --git a/YeelightAPI/Device.cs b/YeelightAPI/Device.cs index 0ea2647..d6695bd 100644 --- a/YeelightAPI/Device.cs +++ b/YeelightAPI/Device.cs @@ -99,7 +99,16 @@ public bool IsConnected /// /// Indicate wether the music mode is enabled /// - public bool IsMusicModeEnabled { get; private set; } + [Obsolete("IsMusicModeEnabled will be removed in the next version, please use MusicMode property instead")] + public bool IsMusicModeEnabled + { + get => this.MusicMode.Enabled; + } + + /// + /// Give informations about the music mode + /// + public MusicModeInformations MusicMode { get; private set; } = new MusicModeInformations(); /// /// The model. @@ -247,7 +256,7 @@ public void ExecuteCommand(METHODS method, List parameters = null) /// public async Task> ExecuteCommandWithResponse(METHODS method, List parameters = null) { - if (IsMusicModeEnabled) + if (this.MusicMode.Enabled) { //music mode enabled, there will be no response, we should assume everything works int uniqueId = GetUniqueIdForCommand(); @@ -324,7 +333,7 @@ internal async Task> ExecuteCommandWithResponse(METHODS meth internal async Task DisableMusicModeAsync() { _ = await Connect(); - IsMusicModeEnabled = false; + MusicMode.Enabled = false; } @@ -332,16 +341,6 @@ internal async Task DisableMusicModeAsync() #region PRIVATE METHODS - private static string GetLocalIpAddress() - { - using (Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, 0)) - { - socket.Connect("8.8.8.8", 65530); - IPEndPoint endPoint = socket.LocalEndPoint as IPEndPoint; - return endPoint.Address.ToString(); - } - } - /// /// Generate valid parameters for percent values /// diff --git a/YeelightAPI/DeviceGroup.IDeviceController.cs b/YeelightAPI/DeviceGroup.IDeviceController.cs index ff1b6f3..faee038 100644 --- a/YeelightAPI/DeviceGroup.IDeviceController.cs +++ b/YeelightAPI/DeviceGroup.IDeviceController.cs @@ -1,4 +1,8 @@ -using System.Threading.Tasks; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Threading.Tasks; +using YeelightAPI.Core; using YeelightAPI.Models; using YeelightAPI.Models.Adjust; using YeelightAPI.Models.ColorFlow; @@ -245,14 +249,37 @@ public async Task StartColorFlow(ColorFlow flow) /// starts the music mode for all devices /// /// - /// + /// /// - public async Task StartMusicMode(string hostName, int port) + public async Task StartMusicMode(string hostName, int startingPort = 0) { - return await Process((Device device) => + bool result = true; + //this one can't be parallelized because of ports + foreach (var device in this) { - return device.StartMusicMode(hostName, port); - }); + int port = NetworkHelper.GetNextAvailablePort(); + result &= await device.StartMusicMode(hostName, port); + } + + return result; + } + + public async Task StartMusicMode(string hostName, IEnumerable ports) + { + if(this.Count != ports.Count()) + { + throw new InvalidDataException("Specified ports does not match with DeviceGroup length"); + } + + bool result = true; + //this one can't be parallelized because of ports + foreach (var device in this) + { + int port = ports.ElementAt(this.IndexOf(device)); + result &= await device.StartMusicMode(hostName, port); + } + + return result; } /// From 2702b6aac73a210b073feac41b9545d642d61edb Mon Sep 17 00:00:00 2001 From: Romain ODDONE Date: Mon, 21 Mar 2022 17:44:50 +0100 Subject: [PATCH 2/9] add missing targets + update nuget packages --- YeelightAPI.Console/YeelightAPI.Console.csproj | 2 +- YeelightAPI.UnitTests/YeelightAPI.UnitTests.csproj | 14 +++++++------- YeelightAPI/DeviceGroup.cs | 4 ++++ YeelightAPI/DeviceLocator.cs | 2 +- YeelightAPI/YeelightAPI.csproj | 10 +++++----- 5 files changed, 18 insertions(+), 14 deletions(-) diff --git a/YeelightAPI.Console/YeelightAPI.Console.csproj b/YeelightAPI.Console/YeelightAPI.Console.csproj index 60a952b..ebd5669 100644 --- a/YeelightAPI.Console/YeelightAPI.Console.csproj +++ b/YeelightAPI.Console/YeelightAPI.Console.csproj @@ -1,7 +1,7 @@  - netcoreapp3.1 + net6.0 false diff --git a/YeelightAPI.UnitTests/YeelightAPI.UnitTests.csproj b/YeelightAPI.UnitTests/YeelightAPI.UnitTests.csproj index 5851d68..3a9228e 100644 --- a/YeelightAPI.UnitTests/YeelightAPI.UnitTests.csproj +++ b/YeelightAPI.UnitTests/YeelightAPI.UnitTests.csproj @@ -1,21 +1,21 @@  - netcoreapp3.1 + net6.0 false - - - - - + + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/YeelightAPI/DeviceGroup.cs b/YeelightAPI/DeviceGroup.cs index a63e40b..26a2996 100644 --- a/YeelightAPI/DeviceGroup.cs +++ b/YeelightAPI/DeviceGroup.cs @@ -104,6 +104,10 @@ protected async Task Process(Func> f) return result; } + /// + /// To string + /// + /// public override string ToString() { return $"{this.Name} ({this.Count} devices)"; diff --git a/YeelightAPI/DeviceLocator.cs b/YeelightAPI/DeviceLocator.cs index ae00982..010b4f2 100644 --- a/YeelightAPI/DeviceLocator.cs +++ b/YeelightAPI/DeviceLocator.cs @@ -179,7 +179,7 @@ public static async Task> DiscoverAsync( CancellationToken cancellationToken) => (await DeviceLocator.SearchNetworkForDevicesAsync(networkInterface, deviceFoundReporter, cancellationToken)).Devices; -#if NETSTANDARD2_1 || NET5_0 +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER /// /// Enumerate devices asynchronously. /// diff --git a/YeelightAPI/YeelightAPI.csproj b/YeelightAPI/YeelightAPI.csproj index 620530d..c51d975 100644 --- a/YeelightAPI/YeelightAPI.csproj +++ b/YeelightAPI/YeelightAPI.csproj @@ -1,10 +1,10 @@  - netstandard2.0; netstandard2.1; net45; net46; net47; net48; net5.0 + netstandard2.0; netstandard2.1; net45; net451; net452; net46; net461; net462; net47; net471; net472; net48; netcoreapp3.1; net5.0; net6.0 Romain ODDONE Romain ODDONE - 1.10.2 + 1.11.0 true true https://github.com/roddone/YeelightAPI @@ -15,8 +15,8 @@ Xiaomi yeelight smart-devices manager Copyright © Romain ODDONE 2021 true - 1.10.2.0 - 1.10.2.0 + 1.11.0.0 + 1.11.0.0 LICENSE icon.png @@ -34,7 +34,7 @@ - + From d10652ef83bf0167cdbe3b76c4586e3c3de4fa83 Mon Sep 17 00:00:00 2001 From: Romain ODDONE Date: Mon, 21 Mar 2022 18:54:04 +0100 Subject: [PATCH 3/9] add more "StartMusicMode" overrides --- YeelightAPI/Core/Constants.cs | 5 ++ YeelightAPI/Core/NetworkHelper.cs | 3 ++ YeelightAPI/Device.IDeviceController.cs | 49 ++++++++++++++++---- YeelightAPI/DeviceGroup.IDeviceController.cs | 46 +++++++++++++++--- YeelightAPI/DeviceGroup.cs | 4 ++ YeelightAPI/Interfaces/IDeviceController.cs | 30 ++++++++++-- 6 files changed, 119 insertions(+), 18 deletions(-) diff --git a/YeelightAPI/Core/Constants.cs b/YeelightAPI/Core/Constants.cs index 2ca11e9..7a6a774 100644 --- a/YeelightAPI/Core/Constants.cs +++ b/YeelightAPI/Core/Constants.cs @@ -20,6 +20,11 @@ internal static class Constants /// public const int DefaultTimeout = 5000; + /// + /// Default starting port when searching available ports for music mode + /// + public const int DefaultMusicModeStartingPort = 5000; + /// /// Line separator /// diff --git a/YeelightAPI/Core/NetworkHelper.cs b/YeelightAPI/Core/NetworkHelper.cs index c017169..543335f 100644 --- a/YeelightAPI/Core/NetworkHelper.cs +++ b/YeelightAPI/Core/NetworkHelper.cs @@ -8,6 +8,9 @@ namespace YeelightAPI.Core { + /// + /// Helper for networking operations + /// public static class NetworkHelper { /// diff --git a/YeelightAPI/Device.IDeviceController.cs b/YeelightAPI/Device.IDeviceController.cs index 1b66875..2384149 100644 --- a/YeelightAPI/Device.IDeviceController.cs +++ b/YeelightAPI/Device.IDeviceController.cs @@ -1,5 +1,7 @@ using System; using System.Collections.Generic; +using System.IO; +using System.Linq; using System.Net.Sockets; using System.Threading.Tasks; using YeelightAPI.Core; @@ -335,27 +337,28 @@ public async Task StartColorFlow(ColorFlow flow) } /// - /// Starts the music mode + /// starts the music mode for all devices, with specified port (or automatic port chosing if is null) /// /// - /// + /// /// - public async Task StartMusicMode(string hostname = null, int? port = null) + public async Task StartMusicMode(string hostname, int? startingPort) { //init new TCP socket if (string.IsNullOrWhiteSpace(hostname)) { hostname = NetworkHelper.GetLocalIpAddress(); } - if (!port.HasValue) + + if (!startingPort.HasValue) { - port = NetworkHelper.GetNextAvailablePort(port ?? 0); + startingPort = NetworkHelper.GetNextAvailablePort(Constants.DefaultMusicModeStartingPort); } - var listener = new TcpListener(System.Net.IPAddress.Parse(hostname), port.Value); + var listener = new TcpListener(System.Net.IPAddress.Parse(hostname), startingPort.Value); listener.Start(); - List parameters = new List() { (int)MusicAction.On, hostname, port }; + List parameters = new List() { (int)MusicAction.On, hostname, startingPort.Value }; CommandResult> result = await ExecuteCommandWithResponse>( method: METHODS.SetMusicMode, @@ -365,7 +368,7 @@ public async Task StartMusicMode(string hostname = null, int? port = null) { this.MusicMode.Enabled = true; this.MusicMode.HostName = hostname; - this.MusicMode.Port = port.Value; + this.MusicMode.Port = startingPort.Value; this.Disconnect(); var musicTcpClient = await listener.AcceptTcpClientAsync(); _tcpClient = musicTcpClient; @@ -374,6 +377,36 @@ public async Task StartMusicMode(string hostname = null, int? port = null) return result.IsOk(); } + /// + /// starts the music mode for all device, with specified ports + /// + /// + /// + /// + /// + public Task StartMusicMode(string hostName, IEnumerable ports) + { + if (ports == null || ports.Count() != 1) + throw new InvalidDataException("ports collection must have exactly one element"); + + return StartMusicMode(hostName, ports.First()); + } + + /// + /// starts the music mode for all device, with possibility to specify a Func that will be called for reach device to determine its port + /// + /// + /// + /// + /// + public Task StartMusicMode(string hostName, Func portChooser) + { + if (portChooser == null) + throw new InvalidDataException("portChooser parameter cannot be null"); + + return StartMusicMode(hostName, portChooser.Invoke(this)); + } + /// /// Stops the color flow /// diff --git a/YeelightAPI/DeviceGroup.IDeviceController.cs b/YeelightAPI/DeviceGroup.IDeviceController.cs index faee038..a00749c 100644 --- a/YeelightAPI/DeviceGroup.IDeviceController.cs +++ b/YeelightAPI/DeviceGroup.IDeviceController.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.IO; using System.Linq; using System.Threading.Tasks; @@ -246,42 +247,75 @@ public async Task StartColorFlow(ColorFlow flow) } /// - /// starts the music mode for all devices + /// starts the music mode for all devices, with automatic port chosing starting at /// /// /// /// - public async Task StartMusicMode(string hostName, int startingPort = 0) + public async Task StartMusicMode(string hostName, int? startingPort) { + startingPort = startingPort ?? Constants.DefaultMusicModeStartingPort; bool result = true; //this one can't be parallelized because of ports foreach (var device in this) { - int port = NetworkHelper.GetNextAvailablePort(); + int port = NetworkHelper.GetNextAvailablePort(startingPort.Value); result &= await device.StartMusicMode(hostName, port); } return result; } + /// + /// starts the music mode for all device, with specified ports + /// + /// + /// + /// + /// public async Task StartMusicMode(string hostName, IEnumerable ports) { - if(this.Count != ports.Count()) + if(ports == null || ports.Count() != this.Count) { throw new InvalidDataException("Specified ports does not match with DeviceGroup length"); } bool result = true; + int idx = 0; //this one can't be parallelized because of ports foreach (var device in this) { - int port = ports.ElementAt(this.IndexOf(device)); + int port = ports.ElementAt(idx); result &= await device.StartMusicMode(hostName, port); } return result; } + /// + /// starts the music mode for all device, with possibility to specify a Func that will be called for reach device to determine its port + /// + /// + /// + /// + /// + public async Task StartMusicMode(string hostName, Func portChooser) + { + if (portChooser == null) + { + throw new InvalidDataException("portChooser parameter cannot be null"); + } + + bool result = true; + //this one can't be parallelized because of ports + foreach (var device in this) + { + result &= await device.StartMusicMode(hostName, portChooser); + } + + return result; + } + /// /// stops the color flow of all devices /// diff --git a/YeelightAPI/DeviceGroup.cs b/YeelightAPI/DeviceGroup.cs index a63e40b..5976f20 100644 --- a/YeelightAPI/DeviceGroup.cs +++ b/YeelightAPI/DeviceGroup.cs @@ -104,6 +104,10 @@ protected async Task Process(Func> f) return result; } + /// + /// To string + /// + /// public override string ToString() { return $"{this.Name} ({this.Count} devices)"; diff --git a/YeelightAPI/Interfaces/IDeviceController.cs b/YeelightAPI/Interfaces/IDeviceController.cs index ee40afd..dce1e28 100644 --- a/YeelightAPI/Interfaces/IDeviceController.cs +++ b/YeelightAPI/Interfaces/IDeviceController.cs @@ -1,4 +1,8 @@ -using System.Threading.Tasks; +using System; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using YeelightAPI.Core; using YeelightAPI.Models; using YeelightAPI.Models.Adjust; using YeelightAPI.Models.ColorFlow; @@ -143,12 +147,30 @@ public interface IDeviceController Task StartColorFlow(ColorFlow flow); /// - /// Start the music mode + /// starts the music mode for all devices, with automatic port chosing /// /// - /// + /// /// - Task StartMusicMode(string hostName, int port); + Task StartMusicMode(string hostName, int? startingPort); + + /// + /// starts the music mode for all device, with specified ports + /// + /// + /// + /// + /// + Task StartMusicMode(string hostName, IEnumerable ports); + + /// + /// starts the music mode for all device, with possibility to manually specify port for each device + /// + /// + /// + /// + /// + Task StartMusicMode(string hostName, Func portChooser); /// /// Stop the current color flow From 7cf044b50e90b62babf5249a34a0d42ce68fcd8b Mon Sep 17 00:00:00 2001 From: Romain ODDONE Date: Mon, 21 Mar 2022 19:02:23 +0100 Subject: [PATCH 4/9] add more official targets --- YeelightAPI/YeelightAPI.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/YeelightAPI/YeelightAPI.csproj b/YeelightAPI/YeelightAPI.csproj index c51d975..1499d09 100644 --- a/YeelightAPI/YeelightAPI.csproj +++ b/YeelightAPI/YeelightAPI.csproj @@ -1,7 +1,7 @@  - netstandard2.0; netstandard2.1; net45; net451; net452; net46; net461; net462; net47; net471; net472; net48; netcoreapp3.1; net5.0; net6.0 + netstandard2.0; netstandard2.1; net45; net451; net452; net46; net461; net462; net47; net471; net472; net48; netcoreapp2.0; netcoreapp2.1; netcoreapp2.2; netcoreapp3.0; netcoreapp3.1; net5.0; net6.0 Romain ODDONE Romain ODDONE 1.11.0 From 8870fb845057f8d681594f7473d3357680026bf7 Mon Sep 17 00:00:00 2001 From: Romain ODDONE Date: Mon, 21 Mar 2022 19:05:29 +0100 Subject: [PATCH 5/9] update release note --- YeelightAPI/YeelightAPI.csproj | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/YeelightAPI/YeelightAPI.csproj b/YeelightAPI/YeelightAPI.csproj index 1499d09..f1952fa 100644 --- a/YeelightAPI/YeelightAPI.csproj +++ b/YeelightAPI/YeelightAPI.csproj @@ -11,9 +11,10 @@ https://github.com/roddone/YeelightAPI Github xiaomi yeelight api bulb device iot .net c# - * [Device] fix an error that caused the device to be considered in music mode even if the SetMusicMode failed + * [Device and DeviceGroup] Add more ways to handle Music Mode on Device and DeviceGroup + * Add more official build targets Xiaomi yeelight smart-devices manager - Copyright © Romain ODDONE 2021 + Copyright © Romain ODDONE 2022 true 1.11.0.0 1.11.0.0 From 0c9380a361b1d73893f31ca6864ea7e13d175e0e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 22 Jun 2022 15:33:30 +0000 Subject: [PATCH 6/9] Bump Newtonsoft.Json from 12.0.3 to 13.0.1 in /YeelightAPI Bumps [Newtonsoft.Json](https://github.com/JamesNK/Newtonsoft.Json) from 12.0.3 to 13.0.1. - [Release notes](https://github.com/JamesNK/Newtonsoft.Json/releases) - [Commits](https://github.com/JamesNK/Newtonsoft.Json/compare/12.0.3...13.0.1) --- updated-dependencies: - dependency-name: Newtonsoft.Json dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- YeelightAPI/YeelightAPI.csproj | 2 +- YeelightAPI/packages.config | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/YeelightAPI/YeelightAPI.csproj b/YeelightAPI/YeelightAPI.csproj index 620530d..ebe51cc 100644 --- a/YeelightAPI/YeelightAPI.csproj +++ b/YeelightAPI/YeelightAPI.csproj @@ -34,7 +34,7 @@ - + diff --git a/YeelightAPI/packages.config b/YeelightAPI/packages.config index e4ac9c6..ce3dc38 100644 --- a/YeelightAPI/packages.config +++ b/YeelightAPI/packages.config @@ -1,4 +1,4 @@  - + \ No newline at end of file From c1858a1ec2a6dea7c13bc1d03b4ae928eae6f3af Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 22 Jun 2022 23:37:15 +0000 Subject: [PATCH 7/9] Bump Newtonsoft.Json from 12.0.3 to 13.0.1 in /YeelightAPI.Console Bumps [Newtonsoft.Json](https://github.com/JamesNK/Newtonsoft.Json) from 12.0.3 to 13.0.1. - [Release notes](https://github.com/JamesNK/Newtonsoft.Json/releases) - [Commits](https://github.com/JamesNK/Newtonsoft.Json/compare/12.0.3...13.0.1) --- updated-dependencies: - dependency-name: Newtonsoft.Json dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- YeelightAPI.Console/packages.config | 2 +- YeelightAPI/YeelightAPI.csproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/YeelightAPI.Console/packages.config b/YeelightAPI.Console/packages.config index 43cb3fa..102f159 100644 --- a/YeelightAPI.Console/packages.config +++ b/YeelightAPI.Console/packages.config @@ -1,4 +1,4 @@  - + \ No newline at end of file diff --git a/YeelightAPI/YeelightAPI.csproj b/YeelightAPI/YeelightAPI.csproj index 620530d..ebe51cc 100644 --- a/YeelightAPI/YeelightAPI.csproj +++ b/YeelightAPI/YeelightAPI.csproj @@ -34,7 +34,7 @@ - + From b66a4a3713bb605f0ec04f2590de074e42cdaac2 Mon Sep 17 00:00:00 2001 From: Cheerpipe Date: Fri, 22 Jul 2022 23:21:16 -0400 Subject: [PATCH 8/9] Fix low framerate when using Music Mode --- YeelightAPI/Device.IDeviceController.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/YeelightAPI/Device.IDeviceController.cs b/YeelightAPI/Device.IDeviceController.cs index 2384149..78077a8 100644 --- a/YeelightAPI/Device.IDeviceController.cs +++ b/YeelightAPI/Device.IDeviceController.cs @@ -363,7 +363,7 @@ public async Task StartMusicMode(string hostname, int? startingPort) CommandResult> result = await ExecuteCommandWithResponse>( method: METHODS.SetMusicMode, parameters: parameters); - + if (result.IsOk()) { this.MusicMode.Enabled = true; @@ -371,6 +371,7 @@ public async Task StartMusicMode(string hostname, int? startingPort) this.MusicMode.Port = startingPort.Value; this.Disconnect(); var musicTcpClient = await listener.AcceptTcpClientAsync(); + musicTcpClient.Client.NoDelay = true; _tcpClient = musicTcpClient; } From db5535638ee4f4725ce2a0d005f0ac483be20c12 Mon Sep 17 00:00:00 2001 From: romain oddone Date: Sun, 24 Jul 2022 18:46:19 +0200 Subject: [PATCH 9/9] add "HighRateEnabled" to allow using "NoDelay" property on TcpClient when using music mode --- YeelightAPI/Core/MusicModeInformations.cs | 5 +++++ YeelightAPI/Device.IDeviceController.cs | 1 - YeelightAPI/Device.cs | 1 + 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/YeelightAPI/Core/MusicModeInformations.cs b/YeelightAPI/Core/MusicModeInformations.cs index cd7fef4..c65ff2c 100644 --- a/YeelightAPI/Core/MusicModeInformations.cs +++ b/YeelightAPI/Core/MusicModeInformations.cs @@ -23,5 +23,10 @@ public class MusicModeInformations /// Music mode enabled or not ? /// public bool Enabled { get; internal set; } + + /// + /// High rate enabled or not ? + /// + public bool HighRateEnabled { get; set; } } } diff --git a/YeelightAPI/Device.IDeviceController.cs b/YeelightAPI/Device.IDeviceController.cs index 78077a8..16453e3 100644 --- a/YeelightAPI/Device.IDeviceController.cs +++ b/YeelightAPI/Device.IDeviceController.cs @@ -371,7 +371,6 @@ public async Task StartMusicMode(string hostname, int? startingPort) this.MusicMode.Port = startingPort.Value; this.Disconnect(); var musicTcpClient = await listener.AcceptTcpClientAsync(); - musicTcpClient.Client.NoDelay = true; _tcpClient = musicTcpClient; } diff --git a/YeelightAPI/Device.cs b/YeelightAPI/Device.cs index d6695bd..d9f167f 100644 --- a/YeelightAPI/Device.cs +++ b/YeelightAPI/Device.cs @@ -259,6 +259,7 @@ public async Task> ExecuteCommandWithResponse(METHODS method if (this.MusicMode.Enabled) { //music mode enabled, there will be no response, we should assume everything works + _tcpClient.Client.NoDelay = this.MusicMode.HighRateEnabled; //update here instead of "SetMusicMode" so it can be changed dynamically int uniqueId = GetUniqueIdForCommand(); ExecuteCommand(method, uniqueId, parameters); return new CommandResult() { Id = uniqueId, Error = null, IsMusicResponse = true };