From eda9393bc94322d564a70759966181a39f54db53 Mon Sep 17 00:00:00 2001 From: sleevezipper Date: Sun, 17 Jan 2021 16:27:50 +0100 Subject: [PATCH] fix sensors not updating after adding #22 --- hass-workstation-service/Worker.cs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/hass-workstation-service/Worker.cs b/hass-workstation-service/Worker.cs index 18ddfa3..3911130 100644 --- a/hass-workstation-service/Worker.cs +++ b/hass-workstation-service/Worker.cs @@ -41,14 +41,12 @@ namespace hass_workstation_service } _logger.LogInformation("Connected. Sending auto discovery messages."); - List sensors = _configurationService.ConfiguredSensors.ToList(); - List commands = _configurationService.ConfiguredCommands.ToList(); _mqttPublisher.AnnounceAvailability("sensor"); - foreach (AbstractSensor sensor in sensors) + foreach (AbstractSensor sensor in _configurationService.ConfiguredSensors.ToList()) { sensor.PublishAutoDiscoveryConfigAsync(); } - foreach (AbstractCommand command in commands) + foreach (AbstractCommand command in _configurationService.ConfiguredCommands.ToList()) { command.PublishAutoDiscoveryConfigAsync(); } @@ -62,7 +60,7 @@ namespace hass_workstation_service _mqttPublisher.AnnounceAvailability("sensor"); } - foreach (AbstractSensor sensor in sensors) + foreach (AbstractSensor sensor in _configurationService.ConfiguredSensors.ToList()) { try { @@ -74,7 +72,7 @@ namespace hass_workstation_service } } - foreach (AbstractCommand command in commands) + foreach (AbstractCommand command in _configurationService.ConfiguredCommands.ToList()) { try { @@ -89,11 +87,11 @@ namespace hass_workstation_service // announce autodiscovery every 30 seconds if (_mqttPublisher.LastConfigAnnounce < DateTime.UtcNow.AddSeconds(-30)) { - foreach (AbstractSensor sensor in sensors) + foreach (AbstractSensor sensor in _configurationService.ConfiguredSensors.ToList()) { sensor.PublishAutoDiscoveryConfigAsync(); } - foreach (AbstractCommand command in commands) + foreach (AbstractCommand command in _configurationService.ConfiguredCommands.ToList()) { command.PublishAutoDiscoveryConfigAsync(); }