• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

net-daemon / netdaemon / 13405937792

19 Feb 2025 05:17AM UTC coverage: 84.158% (+0.5%) from 83.694%
13405937792

Pull #1266

github

web-flow
Merge 3e6ca912f into d4a59cd5e
Pull Request #1266: Use MSBuild to load projects, instead of manual parsing

844 of 1125 branches covered (75.02%)

Branch coverage included in aggregate %.

5 of 6 new or added lines in 2 files covered. (83.33%)

3342 of 3849 relevant lines covered (86.83%)

204.82 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/HassModel/NetDaemon.HassModel.CodeGenerator/Program.cs
1
using System.Globalization;
2
using Microsoft.Build.Locator;
3
using Microsoft.Extensions.Configuration;
4
using NetDaemon.Client.Settings;
5

6
#pragma warning disable CA1303
7

8
var configurationRoot = GetConfigurationRoot();
×
9
var haSettings = configurationRoot.GetSection("HomeAssistant").Get<HomeAssistantSettings>() ?? new HomeAssistantSettings();
×
10
var generationSettings = configurationRoot.GetSection("CodeGeneration").Get<CodeGenerationSettings>() ?? new CodeGenerationSettings();
×
11

12
if (args.Any(arg => arg.ToLower(CultureInfo.InvariantCulture) == "-help"))
×
13
{
14
    ShowUsage();
×
15
    return 0;
×
16
}
17

18
//This is used as a command line switch rather than a configuration key. There is no key value following it to interpret.
19
generationSettings.GenerateOneFilePerEntity = args.Any(arg => arg.ToLower(CultureInfo.InvariantCulture) == "-fpe");
×
20

NEW
21
MSBuildLocator.RegisterDefaults();
×
22
VersionHelper.PrintVersion();
×
23
await VersionValidator.ValidateLatestVersion();
×
24
VersionValidator.ValidatePackageReferences();
×
25

26
var controller = new Controller(generationSettings, haSettings);
×
27
await controller.RunAsync().ConfigureAwait(false);
×
28

29
Console.WriteLine();
×
30
Console.WriteLine("Code Generated successfully!");
×
31

32
return 0;
×
33

34
IConfigurationRoot GetConfigurationRoot()
35
{
36
    var env = Environment.GetEnvironmentVariable("DOTNET_ENVIRONMENT");
×
37
    var builder = new ConfigurationBuilder()
×
38
        // default path is the folder of the currently executing root assembly
×
39
        .AddJsonFile("appsettings.json", true, true)
×
40
        .AddJsonFile($"appsettings.{env}.json", true, true)
×
41

×
42
        // Also look in the current directory which will typically be the project folder
×
43
        // of the users code and have a appsettings.development.json with the correct HA connection settings
×
44
        .SetBasePath(Environment.CurrentDirectory)
×
45
        .AddJsonFile("appsettings.json", true, true)
×
46
        .AddJsonFile("appsettings.development.json", true, true)
×
47
        .AddUserSecrets<Program>()
×
48

×
49
        // finally override with Environment vars or commandline
×
50
        .AddEnvironmentVariables()
×
51
        .AddCommandLine(args, new Dictionary<string, string>
×
52
        {
×
53
            ["-o"] = "CodeGeneration:OutputFile",
×
54
            ["-f"] = "CodeGeneration:OutputFolder",
×
55
            ["-ns"] = "CodeGeneration:Namespace",
×
56
            ["-host"] = "HomeAssistant:Host",
×
57
            ["-port"] = "HomeAssistant:Port",
×
58
            ["-ssl"] = "HomeAssistant:Ssl",
×
59
            ["-token"] = "HomeAssistant:Token",
×
60
            ["-bypass-cert"] = "HomeAssistant:InsecureBypassCertificateErrors",
×
61
        });
×
62

63
    return builder.Build();
×
64
}
65

66
void ShowUsage()
67
{
68
    Console.WriteLine(@"
×
69
    Usage: nd-codegen [options] -ns namespace -o outfile
×
70
    Options:
×
71
        -f           : Name of folder to output files (folder name only)
×
72
        -fpe         : Create separate file per entity (ignores -o option)
×
73
        -host        : Host of the netdaemon instance
×
74
        -port        : Port of the NetDaemon instance
×
75
        -ssl         : true if NetDaemon instance use ssl
×
76
        -token       : A long lived HomeAssistant token
×
77
        -bypass-cert : Ignore certificate errors (insecure)
×
78

×
79
    These settings is valid when installed codegen as global dotnet tool.
×
80
            ");
×
81
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc