Skip to content

Commit

Permalink
Merge pull request #1 from JonasMH/develop
Browse files Browse the repository at this point in the history
Fix Device.Connections type
  • Loading branch information
JonasMH authored Feb 5, 2022
2 parents 0eb7d4a + c6113ef commit 4ed6be9
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/ToMqttNet/MqttDiscoveryConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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"]].
/// </summary>
[JsonProperty("connections")]
public List<string>? Connections { get; set; }
public List<List<string>>? Connections { get; set; }

/// <summary>
/// A list of IDs that uniquely identify the device. For example a serial number.
Expand Down
4 changes: 3 additions & 1 deletion src/ToMqttNet/ToMqttNet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<Version>0.1.0</Version>
<Version>0.1.1</Version>
<Authors>JonasMH</Authors>
<PackageDescription>ASP.NET Hosted MQTT Connection and models to make it easier to work with Home Assistant MQTT Discovery</PackageDescription>
<RepositoryUrl>https://github.com/JonasMH/ToMqttNet</RepositoryUrl>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<NoWarn>$(NoWarn);1591</NoWarn>
</PropertyGroup>

<ItemGroup>
Expand Down
32 changes: 32 additions & 0 deletions test/ToMqttNet.Test.Unit/MqttDiscoveryConfigTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Collections.Generic;
using Xunit;

namespace ToMqttNet.Test.Unit;
Expand Down Expand Up @@ -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<List<string>>
{
new List<string>
{
"ip",
"192.168.0.1"
}
}
}
};

// Act
var result = (JObject)JsonConvert.DeserializeObject(sut.ToJson())!;

// Assert
var connectionArray = result["device"]!["connections"]!;
Assert.IsType<JArray>(connectionArray);
var con1Array = connectionArray[0]!;
Assert.IsType<JArray>(con1Array);
Assert.Equal("ip", con1Array[0]);
Assert.Equal("192.168.0.1", con1Array[1]);
}
}


Expand Down

0 comments on commit 4ed6be9

Please sign in to comment.