-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added an option to convert a ST Community Installer Manifest
- Loading branch information
Showing
4 changed files
with
98 additions
and
1 deletion.
There are no files selected for viewing
74 changes: 74 additions & 0 deletions
74
HubitatPackageManagerTools/Executors/ManifestConvertExecutor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
using HubitatPackageManagerTools.Options; | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Linq; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Text; | ||
|
||
namespace HubitatPackageManagerTools.Executors | ||
{ | ||
internal class ManifestConvertExecutor : ManifestExecutorBase | ||
{ | ||
public int Execute(ManifestConvertOptions options) | ||
{ | ||
using var file = File.OpenText(options.SmartThingsFile); | ||
var stFile = (JObject)JToken.ReadFrom(new JsonTextReader(file)); | ||
|
||
var newManifestContents = new JObject | ||
{ | ||
["packageName"] = stFile["name"], | ||
["author"] = stFile["author"], | ||
["minimumHEVersion"] = "0.0", | ||
["dateReleased"] = DateTime.Now.ToString("yyyy-MM-dd"), | ||
["apps"] = new JArray(), | ||
["drivers"] = new JArray() | ||
}; | ||
|
||
var stParentApp = stFile["smartApps"]["parent"]; | ||
var parentApp = JObject.FromObject(new | ||
{ | ||
id = Guid.NewGuid(), | ||
name = stParentApp["name"], | ||
@namespace = stFile["namespace"], | ||
version = stParentApp["version"], | ||
location = $"https://raw.githubusercontent.com/{stFile["repoOwner"]}/{stFile["repoName"]}/{stFile["repoBranch"]}/{stParentApp["appUrl"]}", | ||
required = !((bool?)stParentApp["optional"] ?? true), | ||
oauth = (bool?)stParentApp["oAuth"] ?? false | ||
}); | ||
(newManifestContents["apps"] as JArray).Add(parentApp); | ||
foreach (var stApp in stFile["smartApps"]["children"]) | ||
{ | ||
var app = JObject.FromObject(new | ||
{ | ||
id = Guid.NewGuid(), | ||
name = stApp["name"], | ||
@namespace = stFile["namespace"], | ||
version = stApp["version"], | ||
location = $"https://raw.githubusercontent.com/{stFile["repoOwner"]}/{stFile["repoName"]}/{stFile["repoBranch"]}/{stApp["appUrl"]}", | ||
required = !((bool?)stApp["optional"] ?? true), | ||
oauth = (bool?)stApp["oAuth"] ?? false | ||
}); | ||
(newManifestContents["apps"] as JArray).Add(app); | ||
} | ||
|
||
foreach (var dth in stFile["deviceHandlers"]) | ||
{ | ||
var driver = JObject.FromObject(new | ||
{ | ||
id = Guid.NewGuid(), | ||
name = dth["name"], | ||
@namespace = stFile["namespace"], | ||
version = dth["version"], | ||
location = $"https://raw.githubusercontent.com/{stFile["repoOwner"]}/{stFile["repoName"]}/{stFile["repoBranch"]}/{dth["appUrl"]}", | ||
required = !((bool?)dth["optional"] ?? true) | ||
}); | ||
(newManifestContents["drivers"] as JArray).Add(driver); | ||
} | ||
|
||
SaveManifest(options, newManifestContents); | ||
|
||
return 0; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
HubitatPackageManagerTools/Options/ManifestConvertOptions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using CommandLine; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace HubitatPackageManagerTools.Options | ||
{ | ||
[Verb("manifest-convert", HelpText = "Convert a SmartThings Community Installer manifest to a Hubitat Package Manager manifest.")] | ||
internal class ManifestConvertOptions : ManifestOptionsBase | ||
{ | ||
[Value(0, HelpText = "The local path to the SmartThings installer manifest JSON.", MetaName = "stInstallerFile", Required = true)] | ||
public string SmartThingsFile { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters