Exemple #1
0
        public EvoHomeWorker(TokenManager manager, EvoHomeSettings evoHomeSettings, Store store,
                             ILogger <EvoHomeWorker> logger, MqttWorker mqttWorker, IHttpClientFactory clientFactory)
        {
            _manager         = manager;
            _evoHomeSettings = evoHomeSettings;
            _store           = store;
            _logger          = logger;
            _mqttWorker      = mqttWorker;
            Client           = RestClient.For <IEvoClient>(clientFactory.CreateClient(Constants.EvoClientName));

            _configuredDevices =
                _store.Get <ConfiguredDevices>() ?? new ConfiguredDevices()
            {
                ZoneIds = new List <string>()
            };
        }
Exemple #2
0
        public MqttWorker(EvoHomeSettings evoHomeSettings, ILogger <MqttWorker> logger)
        {
            _settings = evoHomeSettings;
            _logger   = logger;

            if (evoHomeSettings.DisableMqtt)
            {
                _logger.LogInformation("Mqtt Disabled");
                return;
            }

            var builder = new MqttClientOptionsBuilder()
                          .WithClientId(evoHomeSettings.MqttClientName);

            if (!string.IsNullOrWhiteSpace(evoHomeSettings.MqttUser))
            {
                builder.WithCredentials(evoHomeSettings.MqttUser, evoHomeSettings.MqttPassword);
            }

            if (evoHomeSettings.MqttWebSockets)
            {
                builder.WithWebSocketServer($"{evoHomeSettings.MqttConnection}:{evoHomeSettings.MqttPort}");
            }
            else
            {
                builder.WithTcpServer(evoHomeSettings.MqttConnection, evoHomeSettings.MqttPort);
            }

            var options = builder.Build();

            _managedOptions = new ManagedMqttClientOptionsBuilder()
                              .WithAutoReconnectDelay(TimeSpan.FromSeconds(5))
                              .WithClientOptions(options)
                              .Build();

            var factory = new MqttFactory();

            _mqttClient = factory.CreateManagedMqttClient();
        }
Exemple #3
0
 public Store(ILogger <Store> logger, EvoHomeSettings evoHomeSettings)
 {
     _logger          = logger;
     _evoHomeSettings = evoHomeSettings;
 }