diff --git a/Communication/MQTT/MqttPublisher.cs b/Communication/MQTT/MqttPublisher.cs index 4c890ea..cd9e46a 100644 --- a/Communication/MQTT/MqttPublisher.cs +++ b/Communication/MQTT/MqttPublisher.cs @@ -81,7 +81,7 @@ namespace hass_desktop_service.Communication PropertyNameCaseInsensitive = true }; var message = new MqttApplicationMessageBuilder() - .WithTopic($"homeassistant/sensor/{config.Device.Identifiers}/config") + .WithTopic($"homeassistant/sensor/{config.Name}/config") .WithPayload(clearPreviousConfig ? "" : JsonSerializer.Serialize(config, options)) .WithRetainFlag() .Build(); diff --git a/Domain/Sensors/AbstractSensor.cs b/Domain/Sensors/AbstractSensor.cs index 5da0ae7..c7e7159 100644 --- a/Domain/Sensors/AbstractSensor.cs +++ b/Domain/Sensors/AbstractSensor.cs @@ -9,6 +9,7 @@ namespace hass_desktop_service.Domain.Sensors { public Guid Id { get; protected set; } public string Name { get; protected set; } + public string PreviousPublishedState { get; protected set; } public MqttPublisher Publisher { get; protected set; } protected AutoDiscoveryConfigModel _autoDiscoveryConfigModel; protected AutoDiscoveryConfigModel SetAutoDiscoveryConfigModel(AutoDiscoveryConfigModel config) @@ -22,13 +23,20 @@ namespace hass_desktop_service.Domain.Sensors public async Task PublishStateAsync() { + string state = this.GetState(); + if (this.PreviousPublishedState == state) + { + // don't publish the state if it hasn't changed + return; + } var message = new MqttApplicationMessageBuilder() .WithTopic(this.GetAutoDiscoveryConfig().State_topic) - .WithPayload(this.GetState()) + .WithPayload(state) .WithExactlyOnceQoS() .WithRetainFlag() .Build(); await Publisher.Publish(message); + this.PreviousPublishedState = state; } public async Task PublishAutoDiscoveryConfigAsync() { diff --git a/Domain/Sensors/UserNotificationStateSensor.cs b/Domain/Sensors/UserNotificationStateSensor.cs index 96188c1..9da18bd 100644 --- a/Domain/Sensors/UserNotificationStateSensor.cs +++ b/Domain/Sensors/UserNotificationStateSensor.cs @@ -85,6 +85,15 @@ namespace hass_desktop_service.Domain.Sensors /// without those distractions. /// Quiet time also occurs for each user after an operating system upgrade or clean installation. /// - QuietTime = 6 + QuietTime = 6, + + /// + /// Introduced in Windows 7. The current user is in "quiet time", which is the first hour after + /// a new user logs into his or her account for the first time. During this time, most notifications + /// should not be sent or shown. This lets a user become accustomed to a new computer system + /// without those distractions. + /// Quiet time also occurs for each user after an operating system upgrade or clean installation. + /// + RunningWindowsStoreApp = 7 }; } \ No newline at end of file diff --git a/Program.cs b/Program.cs index cf8973a..9d7a818 100644 --- a/Program.cs +++ b/Program.cs @@ -37,10 +37,11 @@ namespace hass_desktop_service .Build(); var deviceConfig = new DeviceConfigModel { - Name = "hass-workstation-service3", - //TODO: make this more dynamic - Identifiers = "hass-workstation-service_unique4", - Sw_version = "0.0.4" + 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); diff --git a/Worker.cs b/Worker.cs index b2ade0d..033c9e4 100644 --- a/Worker.cs +++ b/Worker.cs @@ -50,7 +50,10 @@ namespace hass_desktop_service // announce autodiscovery every 30 seconds if (_mqttPublisher.LastConfigAnnounce < DateTime.UtcNow.AddSeconds(-30)) { - // TODO: make every sensor publish its auto discovery config + foreach (AbstractSensor sensor in _configuredSensorsService.ConfiguredSensors) + { + await sensor.PublishAutoDiscoveryConfigAsync(); + } } await Task.Delay(1000, stoppingToken); }