Skip to content

Commit 98e717d

Browse files
committed
The code changes primarily involve updates to the .NET framework and C# version, renaming of classes, replacement of the JSON library, and updates to package versions.
1. The `openHAB.Core.Client.csproj` file has been updated to target the .NET Standard 2.0 framework and use C# version 11.0. It also includes additional project sources for package restoration and adds package references for `Azure.Core` and `Microsoft.Azure.AutoRest.CSharp`. 2. The `openHAB.Common.csproj` file has been updated to use newer versions of the `Microsoft.WindowsAppSDK` and `Microsoft.Windows.SDK.BuildTools` packages. 3. Several classes have been renamed, such as `OpenHABSitemap` to `Sitemap`, `OpenHABItem` to `Item`, and `OpenHABWidget` to `WidgetViewModel`. This suggests a simplification or standardization of class names. 4. The JSON library used for serialization and deserialization has been changed from `Newtonsoft.Json` to `System.Text.Json.Serialization`. 5. The versions of several package references, such as `Microsoft.WindowsAppSDK`, `Microsoft.Windows.SDK.BuildTools`, and `Microsoft.Extensions.Logging.Abstractions`, have been updated. 6. The namespace `openHAB.Core.Services` was changed to `openHAB.Windows.Services` in `WidgetNavigationService.cs`, `MainPage.xaml.cs`, and `SitemapPage.xaml.cs`. 7. The `Page` class was replaced with `Microsoft.UI.Xaml.Controls.Page` in `MainPage.xaml.cs` and `SitemapPage.xaml.cs`. 8. The `WigetNavigation` class was replaced with `WidgetNavigationMessage` in `MainViewModel.cs` and `SitemapViewModel.cs`. 9. The `ObservableCollection<OpenHABWidget>` was replaced with `ObservableCollection<WidgetViewModel>` in `MainViewModel.cs`. 10. The `ObservableCollection<OpenHABSitemap>` was replaced with `ObservableCollection<Sitemap>` in `MainViewModel.cs`. 11. The `List<OpenHABSitemap>` was replaced with `List<Sitemap>` in `MainViewModel.cs`. 12. The `ICollection<OpenHABWidget>` was replaced with `ICollection<Widget>` in `SitemapViewModel.cs`. 13. The `ICollection<OpenHABWidgetMapping>` was replaced with `ICollection<WidgetMapping>` in `SitemapViewModel.cs`. 14. The `OpenHABItem` class was replaced with `Item` in `WidgetViewModel.cs`. 15. The `ObservableCollection<WidgetViewModel>` was added to `WidgetViewModel.cs`. 16. The `Encoding` property was added to `WidgetViewModel.cs`. 17. The `Parent` property was added to `WidgetViewModel.cs`. 18. The `Visibility` property was added to `WidgetViewModel.cs`. 19. The `CreateAsync` method was added to `WidgetViewModel.cs`. 20. The `LoadData` method was added to `WidgetViewModel.cs`. 21. The `CacheAndRetrieveLocalIconPath` method was added to `WidgetViewModel.cs`. 22. The `ConvertColorCodeToColor` method was added to `WidgetViewModel.cs`. 23. The version of the `Mapsui` and `Mapsui.WinUI` packages in the `openHAB.Windows.csproj` file have been updated from `4.1.3` to `4.1.4`. 24. The version of the `Microsoft.WindowsAppSDK` package in the `openHAB.Windows.csproj` file has been updated from `1.4.231219000` to `1.5.240311000`.
1 parent fbb48d5 commit 98e717d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+10986
-569
lines changed

openHAB.Core.Client.csproj

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<TargetFramework>netstandard2.0</TargetFramework>
4+
<LangVersion>11.0</LangVersion>
5+
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
6+
<Nullable>annotations</Nullable>
7+
<IncludeGeneratorSharedCode>true</IncludeGeneratorSharedCode>
8+
<DefineConstants>$(DefineConstants);EXPERIMENTAL</DefineConstants>
9+
<RestoreAdditionalProjectSources>https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk-for-net/nuget/v3/index.json</RestoreAdditionalProjectSources>
10+
</PropertyGroup>
11+
12+
<ItemGroup>
13+
<PackageReference Include="Azure.Core" />
14+
</ItemGroup>
15+
16+
<ItemGroup>
17+
<PackageReference Include="Microsoft.Azure.AutoRest.CSharp" Version="3.0.0-beta.20240322.2" PrivateAssets="All" />
18+
</ItemGroup>
19+
</Project>

src/openHAB.Common/openHAB.Common.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.4.231219000" />
12-
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.22621.2428" />
11+
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.5.240311000" />
12+
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.22621.3233" />
1313
</ItemGroup>
1414
</Project>
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Text.Json.Serialization;
6+
using System.Text.Json;
7+
using System.Threading.Tasks;
8+
9+
namespace openHAB.Core.Client
10+
{
11+
public class AutoNumberToStringConverter : JsonConverter<object>
12+
{
13+
public override bool CanConvert(Type typeToConvert)
14+
{
15+
return typeof(string) == typeToConvert;
16+
}
17+
18+
public override object Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
19+
{
20+
if (reader.TokenType == JsonTokenType.Number)
21+
{
22+
return reader.TryGetInt64(out long l) ?
23+
l.ToString() :
24+
reader.GetDouble().ToString();
25+
}
26+
27+
if (reader.TokenType == JsonTokenType.String)
28+
{
29+
return reader.GetString();
30+
}
31+
32+
using (JsonDocument document = JsonDocument.ParseValue(ref reader))
33+
{
34+
return document.RootElement.Clone().ToString();
35+
}
36+
}
37+
38+
public override void Write(Utf8JsonWriter writer, object value, JsonSerializerOptions options)
39+
{
40+
writer.WriteStringValue(value.ToString());
41+
}
42+
}
43+
}

src/openHAB.Core.Client/Connection/ConnectionService.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
using System;
22
using System.Net.Http;
3+
using System.Text.Json;
4+
using System.Text.Json.Serialization;
35
using System.Text.RegularExpressions;
46
using System.Threading.Tasks;
57
using CommunityToolkit.Mvvm.Messaging;
68
using CommunityToolkit.WinUI.Helpers;
79
using Microsoft.Extensions.Logging;
8-
using Newtonsoft.Json;
910
using openHAB.Common;
1011
using openHAB.Core.Client.Common;
1112
using openHAB.Core.Client.Connection.Contracts;
@@ -160,8 +161,9 @@ public async Task<HttpResponseResult<ServerInfo>> GetOpenHABServerInfo(Models.Co
160161

161162
string responseBody = await result.Content.ReadAsStringAsync();
162163

163-
APIInfo apiInfo = JsonConvert.DeserializeObject<APIInfo>(responseBody);
164-
if (apiInfo.Version < 4)
164+
APIInfo apiInfo = JsonSerializer.Deserialize<APIInfo>(responseBody);
165+
166+
if (int.TryParse(apiInfo.Version, out int apiVersion) && apiVersion < 4)
165167
{
166168
serverInfo.Version = OpenHABVersion.Two;
167169
return new HttpResponseResult<ServerInfo>(serverInfo, result.StatusCode);

src/openHAB.Core.Client/Contracts/IOpenHABClient.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,30 +23,30 @@ public interface IOpenHABClient
2323
/// </summary>
2424
/// <param name="itemName">Name of the item.</param>
2525
/// <returns>openHab item object. </returns>
26-
Task<OpenHABItem> GetItemByName(string itemName);
26+
Task<Item> GetItemByName(string itemName);
2727

2828
/// <summary>
2929
/// Loads all the sitemaps.
3030
/// </summary>
3131
/// <param name="version">The version of OpenHAB running on the server.</param>
3232
/// <param name="filters">Filters for sitemap list.</param>
3333
/// <returns>A list of sitemaps.</returns>
34-
Task<ICollection<OpenHABSitemap>> LoadSitemaps(OpenHABVersion version, List<Func<OpenHABSitemap, bool>> filters);
34+
Task<ICollection<Sitemap>> LoadSitemaps(OpenHABVersion version, List<Func<Sitemap, bool>> filters);
3535

3636

3737
/// <summary>Loads the items from sitemap.</summary>
3838
/// <param name="sitemapLink">The sitemap link.</param>
3939
/// <param name="version">The openHab server version.</param>
4040
/// <returns>Returns loaded sitemap</returns>
41-
Task<ICollection<OpenHABWidget>> LoadItemsFromSitemap(string sitemapLink, OpenHABVersion version);
41+
Task<ICollection<Widget>> LoadItemsFromSitemap(string sitemapLink, OpenHABVersion version);
4242

4343
/// <summary>
4444
/// Sends a command to an item.
4545
/// </summary>
4646
/// <param name="item">The item.</param>
4747
/// <param name="command">The Command.</param>
4848
/// <returns>Operation result if the command was successful or not.</returns>
49-
Task<HttpResponseResult<bool>> SendCommand(OpenHABItem item, string command);
49+
Task<HttpResponseResult<bool>> SendCommand(Item item, string command);
5050

5151
/// <summary>
5252
/// Reset the connection to the OpenHAB server after changing the settings in the App.
@@ -61,6 +61,6 @@ public interface IOpenHABClient
6161
/// Starts listening to server events.
6262
/// </summary>
6363
void StartItemUpdates(System.Threading.CancellationToken token);
64-
Task<OpenHABSitemap> GetSitemap(string sitemapLink, OpenHABVersion version);
64+
Task<Sitemap> GetSitemap(string sitemapLink, OpenHABVersion version);
6565
}
6666
}

src/openHAB.Core.Client/Messages/TriggerCommandMessage.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class TriggerCommandMessage
1313
/// </summary>
1414
/// <param name="item">The OpenHAB item that triggered the command.</param>
1515
/// <param name="command">The command that was triggered.</param>
16-
public TriggerCommandMessage(OpenHABItem item, string command)
16+
public TriggerCommandMessage(Item item, string command)
1717
{
1818
Id = Guid.NewGuid();
1919
Item = item;
@@ -40,7 +40,7 @@ public Guid Id
4040
/// <summary>
4141
/// Gets or sets the OpenHAB item that triggered the command.
4242
/// </summary>
43-
public OpenHABItem Item
43+
public Item Item
4444
{
4545
get;
4646
set;

src/openHAB.Core.Client/Models/APIInfo.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using System.Collections.Generic;
2-
using Newtonsoft.Json;
2+
using System.Text.Json.Serialization;
33

44
namespace openHAB.Core.Client.Models
55
{
@@ -10,39 +10,39 @@ public class APIInfo
1010
{
1111
/// <summary>Gets or sets the version.</summary>
1212
/// <value>The version.</value>
13-
[JsonProperty("version")]
14-
public int Version
13+
[JsonPropertyName("version")]
14+
public string Version
1515
{
1616
get; set;
1717
}
1818

1919
/// <summary>Gets or sets the locale.</summary>
2020
/// <value>The locale.</value>
21-
[JsonProperty("locale")]
21+
[JsonPropertyName("locale")]
2222
public string Locale
2323
{
2424
get; set;
2525
}
2626

2727
/// <summary>Gets or sets the measurement system.</summary>
2828
/// <value>The measurement system.</value>
29-
[JsonProperty("measurementSystem")]
29+
[JsonPropertyName("measurementSystem")]
3030
public string MeasurementSystem
3131
{
3232
get; set;
3333
}
3434

3535
/// <summary>Gets or sets the runtime information.</summary>
3636
/// <value>The runtime information.</value>
37-
[JsonProperty("runtimeInfo")]
37+
[JsonPropertyName("runtimeInfo")]
3838
public RuntimeInfo RuntimeInfo
3939
{
4040
get; set;
4141
}
4242

4343
/// <summary>Gets or sets the links.</summary>
4444
/// <value>The links.</value>
45-
[JsonProperty("links")]
45+
[JsonPropertyName("links")]
4646
public List<Link> Links
4747
{
4848
get; set;

src/openHAB.Core.Client/Models/OpenHABCommandDescription.cs renamed to src/openHAB.Core.Client/Models/CommandDescription.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@ namespace openHAB.Core.Client.Models
55
/// <summary>
66
/// A mapping for an OpenHAB Widget.
77
/// </summary>
8-
public class OpenHABCommandDescription
8+
public class CommandDescription
99
{
1010
/// <summary>
1111
/// Gets or sets the CommandOptions.
1212
/// </summary>
13-
public ICollection<OpenHABCommandOptions> CommandOptions { get; set; }
13+
public ICollection<CommandOptions> CommandOptions { get; set; }
1414

15-
/// <summary>Initializes a new instance of the <see cref="OpenHABCommandDescription" /> class.</summary>
15+
/// <summary>Initializes a new instance of the <see cref="CommandDescription" /> class.</summary>
1616
/// <param name="commandOptions">The command options.</param>
17-
public OpenHABCommandDescription(ICollection<OpenHABCommandOptions> commandOptions)
17+
public CommandDescription(ICollection<CommandOptions> commandOptions)
1818
{
1919
CommandOptions = commandOptions;
2020
}

src/openHAB.Core.Client/Models/OpenHABCommandOptions.cs renamed to src/openHAB.Core.Client/Models/CommandOptions.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ namespace openHAB.Core.Client.Models
33
/// <summary>
44
/// A CommandOptions for commandDescription.
55
/// </summary>
6-
public class OpenHABCommandOptions
6+
public class CommandOptions
77
{
88
/// <summary>
99
/// Gets or sets the Command of the mapping.
@@ -16,11 +16,11 @@ public class OpenHABCommandOptions
1616
public string Label { get; set; }
1717

1818
/// <summary>
19-
/// Initializes a new instance of the <see cref="OpenHABCommandOptions"/> class.
19+
/// Initializes a new instance of the <see cref="CommandOptions"/> class.
2020
/// </summary>
2121
/// <param name="command">A command.</param>
2222
/// <param name="label">A label.</param>
23-
public OpenHABCommandOptions(string command, string label)
23+
public CommandOptions(string command, string label)
2424
{
2525
Command = command;
2626
Label = label;

src/openHAB.Core.Client/Models/OpenHABItem.cs renamed to src/openHAB.Core.Client/Models/Item.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
using System;
22
using System.Globalization;
3+
using System.Text.Json;
34
using System.Text.RegularExpressions;
45
using System.Xml.Linq;
56
using CommunityToolkit.Mvvm.ComponentModel;
67
using CommunityToolkit.Mvvm.Messaging;
7-
using Newtonsoft.Json;
88
using openHAB.Core.Client.Messages;
99

1010
namespace openHAB.Core.Client.Models
1111
{
1212
/// <summary>
1313
/// A class that represents an OpenHAB item.
1414
/// </summary>
15-
public class OpenHABItem : ObservableObject
15+
public class Item : ObservableObject
1616
{
1717
private string _state;
1818
private string _type;
@@ -106,15 +106,15 @@ public string Link
106106
/// Gets or sets the CommandDescription of the OpenHAB item.
107107
/// </summary>
108108
///
109-
public OpenHABCommandDescription CommandDescription
109+
public CommandDescription CommandDescription
110110
{
111111
get; set;
112112
}
113113

114114
/// <summary>
115-
/// Initializes a new instance of the <see cref="OpenHABItem"/> class.
115+
/// Initializes a new instance of the <see cref="Item"/> class.
116116
/// </summary>
117-
public OpenHABItem()
117+
public Item()
118118
{
119119
StrongReferenceMessenger.Default.Register<UpdateItemMessage>(this, HandleUpdateItemMessage);
120120
}
@@ -130,21 +130,21 @@ private async void HandleUpdateItemMessage(object recipient, UpdateItemMessage m
130130
}
131131

132132
/// <summary>
133-
/// Initializes a new instance of the <see cref="OpenHABItem"/> class.
133+
/// Initializes a new instance of the <see cref="Item"/> class.
134134
/// </summary>
135135
/// <param name="startNode">The XML from the OpenHAB server that represents this OpenHAB item.</param>
136-
public OpenHABItem(XElement startNode)
136+
public Item(XElement startNode)
137137
{
138138
ParseNode(startNode);
139139
}
140140

141141
/// <summary>
142-
/// Initializes a new instance of the <see cref="OpenHABItem"/> class.
142+
/// Initializes a new instance of the <see cref="Item"/> class.
143143
/// </summary>
144144
/// <param name="jsonObject">The JSON from the OpenHAB server that represents this OpenHAB item.</param>
145-
public OpenHABItem(string jsonObject)
145+
public Item(string jsonObject)
146146
{
147-
var item = JsonConvert.DeserializeObject<OpenHABItem>(jsonObject);
147+
Item item = JsonSerializer.Deserialize<Item>(jsonObject);
148148
Name = item.Name;
149149
Type = item.Type;
150150
GroupType = item.GroupType;

0 commit comments

Comments
 (0)