Skip to content

Commit

Permalink
Removed OH 1 support form REST client #178
Browse files Browse the repository at this point in the history
Signed-off-by: Christoph Hofmann <[email protected]>
  • Loading branch information
hoffe86 committed Jul 14, 2021
1 parent 6b31632 commit 6c0b698
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 139 deletions.
101 changes: 0 additions & 101 deletions src/openHAB.Core/Model/OpenHABWidgetFactory.cs

This file was deleted.

1 change: 0 additions & 1 deletion src/openHAB.Core/Openhab.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@
<Compile Include="Model\OpenHABItem.cs" />
<Compile Include="Model\OpenHABSitemap.cs" />
<Compile Include="Model\OpenHABUrlState.cs" />
<Compile Include="Model\OpenHABWidgetFactory.cs" />
<Compile Include="Model\OpenHABWidget.cs" />
<Compile Include="Model\OpenHABCommandDescription.cs" />
<Compile Include="Model\OpenHABWidgetMapping.cs" />
Expand Down
46 changes: 9 additions & 37 deletions src/openHAB.Core/SDK/OpenHABClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public async Task<OpenHABVersion> GetOpenHABVersion()
OpenHABAPIInfo apiInfo = JsonConvert.DeserializeObject<OpenHABAPIInfo>(responseBody);
if (apiInfo.Version < 4)
{
return OpenHABVersion.Three;
return OpenHABVersion.Two;
}

string runtimeversion = Regex.Replace(apiInfo?.RuntimeInfo.Version, "[^.0-9]", string.Empty);
Expand Down Expand Up @@ -165,16 +165,16 @@ public async Task<ICollection<OpenHABWidget>> LoadItemsFromSitemap(OpenHABSitema
string resultString = await result.Content.ReadAsStringAsync().ConfigureAwait(false);

ICollection<OpenHABWidget> items = null;
if (version == OpenHABVersion.One)
if (version == OpenHABVersion.Two || version == OpenHABVersion.Three)
{
// V1 = xml
items = ParseWidgets(resultString);
var jsonObject = JObject.Parse(resultString);
items = JsonConvert.DeserializeObject<List<OpenHABWidget>>(jsonObject["homepage"]["widgets"].ToString());
}
else
{
// V2 = JSON
var jsonObject = JObject.Parse(resultString);
items = JsonConvert.DeserializeObject<List<OpenHABWidget>>(jsonObject["homepage"]["widgets"].ToString());
string message = "openHAB version is not supported.";
_logger.LogError(message);
throw new OpenHABException(message);
}

_logger.LogInformation($"Loaded '{items.Count}' sitemaps items from server");
Expand Down Expand Up @@ -247,22 +247,6 @@ public async Task<ICollection<OpenHABSitemap>> LoadSiteMaps(OpenHABVersion versi
string resultString = await result.Content.ReadAsStringAsync().ConfigureAwait(false);

var sitemaps = new List<OpenHABSitemap>();

// V1 = xml
if (version == OpenHABVersion.One)
{
XDocument xml = XDocument.Parse(resultString);

foreach (XElement xElement in xml.Element("sitemaps").Elements())
{
var sitemap = new OpenHABSitemap(xElement);
sitemaps.Add(sitemap);
}

return sitemaps;
}

// V2 = JSON
sitemaps = JsonConvert.DeserializeObject<List<OpenHABSitemap>>(resultString);

_logger.LogInformation($"Loaded '{sitemaps.Count}' sitemaps from server");
Expand Down Expand Up @@ -408,18 +392,6 @@ await Task.Run((Func<Task>)(async () =>
})).ConfigureAwait(false);
}

private ICollection<OpenHABWidget> ParseWidgets(string resultString)
{
var xml = XDocument.Parse(resultString);

return
xml.Element("sitemap")
.Element("homepage")
.Elements("widget")
.Select(xElement => OpenHABWidgetFactory.Parse(xElement))
.ToList();
}

private async Task<bool> SetValidUrl(Settings settings)
{
_logger.LogInformation("Validate Url");
Expand Down Expand Up @@ -467,8 +439,8 @@ private async Task<bool> SetValidUrl(Settings settings)

if (!result.Content)
{
Messenger.Default.Send<FireErrorMessage>(new FireErrorMessage(AppResources.Errors.GetString("ConnectionTestFailed")));
return false;
Messenger.Default.Send<FireErrorMessage>(new FireErrorMessage(AppResources.Errors.GetString("ConnectionTestFailed")));
return false;
}

if (result.Content)
Expand Down

0 comments on commit 6c0b698

Please sign in to comment.