From c6113efe4274c4b46c90883c69b6c83fb134a5ac Mon Sep 17 00:00:00 2001 From: Jonas Hansen Date: Sat, 5 Feb 2022 19:54:28 +0100 Subject: [PATCH] Fix Device.Connections type --- src/ToMqttNet/MqttDiscoveryConfig.cs | 2 +- src/ToMqttNet/ToMqttNet.csproj | 4 ++- .../MqttDiscoveryConfigTests.cs | 32 +++++++++++++++++++ 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/src/ToMqttNet/MqttDiscoveryConfig.cs b/src/ToMqttNet/MqttDiscoveryConfig.cs index 240d1d1..20ff2b6 100644 --- a/src/ToMqttNet/MqttDiscoveryConfig.cs +++ b/src/ToMqttNet/MqttDiscoveryConfig.cs @@ -134,7 +134,7 @@ public class MqttDiscoveryDevice /// A list of connections of the device to the outside world as a list of tuples [connection_type, connection_identifier]. For example the MAC address of a network interface: "connections": [["mac", "02:5b:26:a8:dc:12"]]. /// [JsonProperty("connections")] - public List? Connections { get; set; } + public List>? Connections { get; set; } /// /// A list of IDs that uniquely identify the device. For example a serial number. diff --git a/src/ToMqttNet/ToMqttNet.csproj b/src/ToMqttNet/ToMqttNet.csproj index ac5d653..1259a18 100644 --- a/src/ToMqttNet/ToMqttNet.csproj +++ b/src/ToMqttNet/ToMqttNet.csproj @@ -5,10 +5,12 @@ enable enable - 0.1.0 + 0.1.1 JonasMH ASP.NET Hosted MQTT Connection and models to make it easier to work with Home Assistant MQTT Discovery https://github.com/JonasMH/ToMqttNet + true + $(NoWarn);1591 diff --git a/test/ToMqttNet.Test.Unit/MqttDiscoveryConfigTests.cs b/test/ToMqttNet.Test.Unit/MqttDiscoveryConfigTests.cs index 3b018d9..24aa47c 100644 --- a/test/ToMqttNet.Test.Unit/MqttDiscoveryConfigTests.cs +++ b/test/ToMqttNet.Test.Unit/MqttDiscoveryConfigTests.cs @@ -1,5 +1,6 @@ using Newtonsoft.Json; using Newtonsoft.Json.Linq; +using System.Collections.Generic; using Xunit; namespace ToMqttNet.Test.Unit; @@ -37,6 +38,37 @@ public void ToJson_Availability_IsStringBased() // Assert Assert.Equal("any", result["availability_mode"]!.ToString()); } + + [Fact] + public void ToJson_DeviceConnections_ShouldBeAListOfLists() + { + // Arrange + var sut = new MqttStubDiscoveryConfig() + { + Device = new MqttDiscoveryDevice + { + Connections = new List> + { + new List + { + "ip", + "192.168.0.1" + } + } + } + }; + + // Act + var result = (JObject)JsonConvert.DeserializeObject(sut.ToJson())!; + + // Assert + var connectionArray = result["device"]!["connections"]!; + Assert.IsType(connectionArray); + var con1Array = connectionArray[0]!; + Assert.IsType(con1Array); + Assert.Equal("ip", con1Array[0]); + Assert.Equal("192.168.0.1", con1Array[1]); + } }