Skip to content

Commit

Permalink
The code changes primarily involve updates to the .NET framework and …
Browse files Browse the repository at this point in the history
…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`.
  • Loading branch information
hoffe86 committed Mar 23, 2024
1 parent fbb48d5 commit 98e717d
Show file tree
Hide file tree
Showing 47 changed files with 10,986 additions and 569 deletions.
19 changes: 19 additions & 0 deletions openHAB.Core.Client.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>11.0</LangVersion>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<Nullable>annotations</Nullable>
<IncludeGeneratorSharedCode>true</IncludeGeneratorSharedCode>
<DefineConstants>$(DefineConstants);EXPERIMENTAL</DefineConstants>
<RestoreAdditionalProjectSources>https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk-for-net/nuget/v3/index.json</RestoreAdditionalProjectSources>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Azure.Core" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Azure.AutoRest.CSharp" Version="3.0.0-beta.20240322.2" PrivateAssets="All" />
</ItemGroup>
</Project>
4 changes: 2 additions & 2 deletions src/openHAB.Common/openHAB.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.4.231219000" />
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.22621.2428" />
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.5.240311000" />
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.22621.3233" />
</ItemGroup>
</Project>
43 changes: 43 additions & 0 deletions src/openHAB.Core.Client/AutoNumberToStringConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.Json.Serialization;
using System.Text.Json;
using System.Threading.Tasks;

namespace openHAB.Core.Client
{
public class AutoNumberToStringConverter : JsonConverter<object>
{
public override bool CanConvert(Type typeToConvert)
{
return typeof(string) == typeToConvert;
}

public override object Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
if (reader.TokenType == JsonTokenType.Number)
{
return reader.TryGetInt64(out long l) ?
l.ToString() :
reader.GetDouble().ToString();
}

if (reader.TokenType == JsonTokenType.String)
{
return reader.GetString();
}

using (JsonDocument document = JsonDocument.ParseValue(ref reader))
{
return document.RootElement.Clone().ToString();
}
}

public override void Write(Utf8JsonWriter writer, object value, JsonSerializerOptions options)
{
writer.WriteStringValue(value.ToString());
}
}
}
8 changes: 5 additions & 3 deletions src/openHAB.Core.Client/Connection/ConnectionService.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
using System;
using System.Net.Http;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using CommunityToolkit.Mvvm.Messaging;
using CommunityToolkit.WinUI.Helpers;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using openHAB.Common;
using openHAB.Core.Client.Common;
using openHAB.Core.Client.Connection.Contracts;
Expand Down Expand Up @@ -160,8 +161,9 @@ public async Task<HttpResponseResult<ServerInfo>> GetOpenHABServerInfo(Models.Co

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

APIInfo apiInfo = JsonConvert.DeserializeObject<APIInfo>(responseBody);
if (apiInfo.Version < 4)
APIInfo apiInfo = JsonSerializer.Deserialize<APIInfo>(responseBody);

if (int.TryParse(apiInfo.Version, out int apiVersion) && apiVersion < 4)
{
serverInfo.Version = OpenHABVersion.Two;
return new HttpResponseResult<ServerInfo>(serverInfo, result.StatusCode);
Expand Down
10 changes: 5 additions & 5 deletions src/openHAB.Core.Client/Contracts/IOpenHABClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,30 +23,30 @@ public interface IOpenHABClient
/// </summary>
/// <param name="itemName">Name of the item.</param>
/// <returns>openHab item object. </returns>
Task<OpenHABItem> GetItemByName(string itemName);
Task<Item> GetItemByName(string itemName);

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


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

/// <summary>
/// Sends a command to an item.
/// </summary>
/// <param name="item">The item.</param>
/// <param name="command">The Command.</param>
/// <returns>Operation result if the command was successful or not.</returns>
Task<HttpResponseResult<bool>> SendCommand(OpenHABItem item, string command);
Task<HttpResponseResult<bool>> SendCommand(Item item, string command);

/// <summary>
/// Reset the connection to the OpenHAB server after changing the settings in the App.
Expand All @@ -61,6 +61,6 @@ public interface IOpenHABClient
/// Starts listening to server events.
/// </summary>
void StartItemUpdates(System.Threading.CancellationToken token);
Task<OpenHABSitemap> GetSitemap(string sitemapLink, OpenHABVersion version);
Task<Sitemap> GetSitemap(string sitemapLink, OpenHABVersion version);
}
}
4 changes: 2 additions & 2 deletions src/openHAB.Core.Client/Messages/TriggerCommandMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class TriggerCommandMessage
/// </summary>
/// <param name="item">The OpenHAB item that triggered the command.</param>
/// <param name="command">The command that was triggered.</param>
public TriggerCommandMessage(OpenHABItem item, string command)
public TriggerCommandMessage(Item item, string command)
{
Id = Guid.NewGuid();
Item = item;
Expand All @@ -40,7 +40,7 @@ public Guid Id
/// <summary>
/// Gets or sets the OpenHAB item that triggered the command.
/// </summary>
public OpenHABItem Item
public Item Item
{
get;
set;
Expand Down
14 changes: 7 additions & 7 deletions src/openHAB.Core.Client/Models/APIInfo.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System.Collections.Generic;
using Newtonsoft.Json;
using System.Text.Json.Serialization;

namespace openHAB.Core.Client.Models
{
Expand All @@ -10,39 +10,39 @@ public class APIInfo
{
/// <summary>Gets or sets the version.</summary>
/// <value>The version.</value>
[JsonProperty("version")]
public int Version
[JsonPropertyName("version")]
public string Version
{
get; set;
}

/// <summary>Gets or sets the locale.</summary>
/// <value>The locale.</value>
[JsonProperty("locale")]
[JsonPropertyName("locale")]
public string Locale
{
get; set;
}

/// <summary>Gets or sets the measurement system.</summary>
/// <value>The measurement system.</value>
[JsonProperty("measurementSystem")]
[JsonPropertyName("measurementSystem")]
public string MeasurementSystem
{
get; set;
}

/// <summary>Gets or sets the runtime information.</summary>
/// <value>The runtime information.</value>
[JsonProperty("runtimeInfo")]
[JsonPropertyName("runtimeInfo")]
public RuntimeInfo RuntimeInfo
{
get; set;
}

/// <summary>Gets or sets the links.</summary>
/// <value>The links.</value>
[JsonProperty("links")]
[JsonPropertyName("links")]
public List<Link> Links
{
get; set;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ namespace openHAB.Core.Client.Models
/// <summary>
/// A mapping for an OpenHAB Widget.
/// </summary>
public class OpenHABCommandDescription
public class CommandDescription
{
/// <summary>
/// Gets or sets the CommandOptions.
/// </summary>
public ICollection<OpenHABCommandOptions> CommandOptions { get; set; }
public ICollection<CommandOptions> CommandOptions { get; set; }

/// <summary>Initializes a new instance of the <see cref="OpenHABCommandDescription" /> class.</summary>
/// <summary>Initializes a new instance of the <see cref="CommandDescription" /> class.</summary>
/// <param name="commandOptions">The command options.</param>
public OpenHABCommandDescription(ICollection<OpenHABCommandOptions> commandOptions)
public CommandDescription(ICollection<CommandOptions> commandOptions)
{
CommandOptions = commandOptions;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ namespace openHAB.Core.Client.Models
/// <summary>
/// A CommandOptions for commandDescription.
/// </summary>
public class OpenHABCommandOptions
public class CommandOptions
{
/// <summary>
/// Gets or sets the Command of the mapping.
Expand All @@ -16,11 +16,11 @@ public class OpenHABCommandOptions
public string Label { get; set; }

/// <summary>
/// Initializes a new instance of the <see cref="OpenHABCommandOptions"/> class.
/// Initializes a new instance of the <see cref="CommandOptions"/> class.
/// </summary>
/// <param name="command">A command.</param>
/// <param name="label">A label.</param>
public OpenHABCommandOptions(string command, string label)
public CommandOptions(string command, string label)
{
Command = command;
Label = label;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
using System;
using System.Globalization;
using System.Text.Json;
using System.Text.RegularExpressions;
using System.Xml.Linq;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Messaging;
using Newtonsoft.Json;
using openHAB.Core.Client.Messages;

namespace openHAB.Core.Client.Models
{
/// <summary>
/// A class that represents an OpenHAB item.
/// </summary>
public class OpenHABItem : ObservableObject
public class Item : ObservableObject
{
private string _state;
private string _type;
Expand Down Expand Up @@ -106,15 +106,15 @@ public string Link
/// Gets or sets the CommandDescription of the OpenHAB item.
/// </summary>
///
public OpenHABCommandDescription CommandDescription
public CommandDescription CommandDescription
{
get; set;
}

/// <summary>
/// Initializes a new instance of the <see cref="OpenHABItem"/> class.
/// Initializes a new instance of the <see cref="Item"/> class.
/// </summary>
public OpenHABItem()
public Item()
{
StrongReferenceMessenger.Default.Register<UpdateItemMessage>(this, HandleUpdateItemMessage);
}
Expand All @@ -130,21 +130,21 @@ private async void HandleUpdateItemMessage(object recipient, UpdateItemMessage m
}

/// <summary>
/// Initializes a new instance of the <see cref="OpenHABItem"/> class.
/// Initializes a new instance of the <see cref="Item"/> class.
/// </summary>
/// <param name="startNode">The XML from the OpenHAB server that represents this OpenHAB item.</param>
public OpenHABItem(XElement startNode)
public Item(XElement startNode)
{
ParseNode(startNode);
}

/// <summary>
/// Initializes a new instance of the <see cref="OpenHABItem"/> class.
/// Initializes a new instance of the <see cref="Item"/> class.
/// </summary>
/// <param name="jsonObject">The JSON from the OpenHAB server that represents this OpenHAB item.</param>
public OpenHABItem(string jsonObject)
public Item(string jsonObject)
{
var item = JsonConvert.DeserializeObject<OpenHABItem>(jsonObject);
Item item = JsonSerializer.Deserialize<Item>(jsonObject);
Name = item.Name;
Type = item.Type;
GroupType = item.GroupType;
Expand Down
6 changes: 3 additions & 3 deletions src/openHAB.Core.Client/Models/Link.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System;
using Newtonsoft.Json;
using System.Text.Json.Serialization;

namespace openHAB.Core.Client.Models
{
Expand All @@ -8,15 +8,15 @@ public partial class Link
{
/// <summary>Gets or sets the type.</summary>
/// <value>The type.</value>
[JsonProperty("type")]
[JsonPropertyName("type")]
public string Type
{
get; set;
}

/// <summary>Gets or sets the URL.</summary>
/// <value>The URL.</value>
[JsonProperty("url")]
[JsonPropertyName("url")]
public Uri Url
{
get; set;
Expand Down
Loading

0 comments on commit 98e717d

Please sign in to comment.