public WebSocketClientFactory( IOptions <HomeAssistantSettings> settings ) { ArgumentNullException.ThrowIfNull(settings); _settings = settings.Value; }
public async Task TestWrongHostShouldThrowCorrectException() { var mock = HaFixture.HaMock ?? throw new ApplicationException("Unexpected for the mock server to be null"); var settings = new HomeAssistantSettings { Host = "127.0.0.2", Port = mock.ServerPort, Ssl = false, Token = "token does not matter" }; await Assert.ThrowsAsync <WebSocketException>(async() => await GetConnectedClientContext(settings).ConfigureAwait(false)); }
public RunnerService( ILoggerFactory loggerFactory, IOptions <NetDaemonSettings> netDaemonSettings, IOptions <HomeAssistantSettings> homeAssistantSettings, IServiceProvider serviceProvider, IYamlConfig yamlConfig, IDaemonAppCompiler daemonAppCompiler ) { _logger = loggerFactory.CreateLogger <RunnerService>(); _homeAssistantSettings = homeAssistantSettings.Value; _netDaemonSettings = netDaemonSettings.Value; _serviceProvider = serviceProvider; _yamlConfig = yamlConfig; _daemonAppCompiler = daemonAppCompiler; }
public DebugService( IHostApplicationLifetime hostLifetime, IHomeAssistantRunner homeAssistantRunner, IOptions <HomeAssistantSettings> settings, ILogger <DebugService> logger) { _haSettings = settings.Value; _hostLifetime = hostLifetime; _homeAssistantRunner = homeAssistantRunner; _logger = logger; homeAssistantRunner.OnConnect .Select(async s => await OnHomeAssistantClientConnected(s).ConfigureAwait(false)) .Subscribe(); homeAssistantRunner.OnDisconnect.Subscribe(OnHomeAssistantClientDisconnected); }
public NetDaemonRuntime( IHomeAssistantRunner homeAssistantRunner, IOptions <HomeAssistantSettings> settings, IOptions <AppConfigurationLocationSetting> locationSettings, IAppModel appModel, IServiceProvider serviceProvider, ILogger <NetDaemonRuntime> logger, ICacheManager cacheManager) { _haSettings = settings.Value; _homeAssistantRunner = homeAssistantRunner; _locationSettings = locationSettings; _appModel = appModel; _serviceProvider = serviceProvider; _logger = logger; _cacheManager = cacheManager; }
public RunnerService( ILoggerFactory loggerFactory, IOptions <NetDaemonSettings> netDaemonSettings, IOptions <HomeAssistantSettings> homeAssistantSettings, IServiceProvider serviceProvider, IYamlConfig yamlConfig, IDaemonAppCompiler daemonAppCompiler ) { _ = homeAssistantSettings ?? throw new NetDaemonArgumentNullException(nameof(homeAssistantSettings)); _ = netDaemonSettings ?? throw new NetDaemonArgumentNullException(nameof(netDaemonSettings)); _logger = loggerFactory.CreateLogger <RunnerService>(); _homeAssistantSettings = homeAssistantSettings.Value; _netDaemonSettings = netDaemonSettings.Value; _serviceProvider = serviceProvider; _yamlConfig = yamlConfig; _daemonAppCompiler = daemonAppCompiler; }
/// <summary> /// Connect to Home Assistant /// </summary> /// <param name="host">The host name</param> /// <param name="port">Network port</param> /// <param name="ssl">Set true to use ssl</param> /// <param name="token">The access token to use</param> /// <param name="websocketPath">The relative websocket path to use connecting</param> /// <param name="cancelToken">Cancellation token</param> public static async Task <IHomeAssistantConnection> ConnectClientAsync(string host, int port, bool ssl, string token, string websocketPath, CancellationToken cancelToken) { var loggerFactory = LoggerFactory.Create(b => b.AddConsole()); var loggerConnect = loggerFactory.CreateLogger <IHomeAssistantConnection>(); var loggerClient = loggerFactory.CreateLogger <IHomeAssistantClient>(); var loggerResultMessageHandler = loggerFactory.CreateLogger <ResultMessageHandler>(); var settings = new HomeAssistantSettings { Host = host, Port = port, Ssl = ssl, Token = token }; var optionsSettings = Options.Create(settings); var apiManager = new HomeAssistantApiManager(optionsSettings, new HttpClient()); var connectionFactory = new HomeAssistantConnectionFactory(loggerConnect, apiManager); var pipeLineFactory = new WebSocketClientTransportPipelineFactory(); var websocketClientFactory = new WebSocketClientFactory(Options.Create(settings)); var client = new HomeAssistantClient(loggerClient, websocketClientFactory, pipeLineFactory, connectionFactory); return(await client.ConnectAsync(host, port, ssl, token, websocketPath, cancelToken).ConfigureAwait(false)); }