You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
hass-workstation-service/Program.cs

55 lines
2.2 KiB

4 years ago
using System;
using System.Runtime.InteropServices;
4 years ago
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using hass_workstation_service.Communication;
using Microsoft.Extensions.Configuration;
using MQTTnet.Client.Options;
using hass_workstation_service.Data;
4 years ago
namespace hass_workstation_service
4 years ago
{
public class Program
{
public static void Main(string[] args)
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
CreateHostBuilder(args).Build().Run();
}
else
{
// we only support MS Windows for now
throw new NotImplementedException("Your platform is not yet supported");
}
4 years ago
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureServices((hostContext, services) =>
{
IConfiguration configuration = hostContext.Configuration;
IConfigurationSection mqttSection = configuration.GetSection("MqttBroker");
var mqttClientOptions = new MqttClientOptionsBuilder()
.WithTcpServer(mqttSection.GetValue<string>("Host"))
// .WithTls()
.WithCredentials(mqttSection.GetValue<string>("Username"), mqttSection.GetValue<string>("Password"))
.Build();
var deviceConfig = new DeviceConfigModel
{
Name = Environment.MachineName,
Identifiers = "hass-workstation-service",
Manufacturer = Environment.UserName,
Model = Environment.OSVersion.ToString(),
Sw_version = "0.0.5"
};
services.AddSingleton(configuration);
services.AddSingleton(deviceConfig);
services.AddSingleton(mqttClientOptions);
services.AddSingleton<ConfiguredSensorsService>();
services.AddSingleton<MqttPublisher>();
4 years ago
services.AddHostedService<Worker>();
});
}
}