Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: ignore availability topic option for sensors #22

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ internal static async Task UnpublishAllCommands()
foreach (var command in Variables.Commands)
{
await command.UnPublishAutoDiscoveryConfigAsync();
await Variables.MqttManager.UnubscribeAsync(command);
await Variables.MqttManager.UnsubscribeAsync(command);
command.ClearAutoDiscoveryConfig();
count++;
}
Expand Down Expand Up @@ -188,7 +188,7 @@ internal static async Task<bool> StoreAsync(List<ConfiguredCommand> commands, Li

// remove and unregister
await abstractCommand.UnPublishAutoDiscoveryConfigAsync();
await Variables.MqttManager.UnubscribeAsync(abstractCommand);
await Variables.MqttManager.UnsubscribeAsync(abstractCommand);
Variables.Commands.RemoveAt(Variables.Commands.FindIndex(x => x.Id == abstractCommand.Id));

Log.Information("[COMMANDS] Removed command: {command}", abstractCommand.Name);
Expand Down Expand Up @@ -220,7 +220,7 @@ internal static async Task<bool> StoreAsync(List<ConfiguredCommand> commands, Li
Log.Information("[COMMANDS] Command changed, re-registering as new entity: {old} to {new}", Variables.Commands[currentCommandIndex].Name, abstractCommand.Name);

await Variables.Commands[currentCommandIndex].UnPublishAutoDiscoveryConfigAsync();
await Variables.MqttManager.UnubscribeAsync(Variables.Commands[currentCommandIndex]);
await Variables.MqttManager.UnsubscribeAsync(Variables.Commands[currentCommandIndex]);
await Variables.MqttManager.SubscribeAsync(abstractCommand);
}

Expand Down
259 changes: 139 additions & 120 deletions src/HASS.Agent.Staging/HASS.Agent.Satellite.Service/MQTT/MqttManager.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class ConfiguredSensor
public string Counter { get; set; } = string.Empty;
public string Instance { get; set; } = string.Empty;
public string Name { get; set; } = string.Empty;
public bool IgnoreAvailability { get; set; } = false;
public bool ApplyRounding { get; set; } = false;
public int? Round { get; set; }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public string ObjectId
public bool UseAttributes { get; set; } = false;

public abstract DiscoveryConfigModel GetAutoDiscoveryConfig();
public bool IgnoreAvailability { get; set; } = false;
public abstract void ClearAutoDiscoveryConfig();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ namespace HASS.Agent.Shared.Models.HomeAssistant
[SuppressMessage("ReSharper", "InconsistentNaming")]
public abstract class DiscoveryConfigModel
{
/// <summary>
/// (Optional) The MQTT topic subscribed to receive availability (online/offline) updates.
/// </summary>
/// <value></value>
public string Availability_topic { get; set; }

/// <summary>
/// (Optional) Information about the device this entity is a part of to tie it into the device registry. Only works through MQTT discovery and when unique_id is set.
/// </summary>
Expand All @@ -27,7 +33,7 @@ public abstract class DiscoveryConfigModel
/// </summary>
/// <value></value>
public string FriendlyName { get; set; }

/// <summary>
/// The MQTT topic subscribed to receive entity values.
/// </summary>
Expand All @@ -38,12 +44,6 @@ public abstract class DiscoveryConfigModel
[SuppressMessage("ReSharper", "InconsistentNaming")]
public class SensorDiscoveryConfigModel : DiscoveryConfigModel
{
/// <summary>
/// (Optional) The MQTT topic subscribed to receive availability (online/offline) updates.
/// </summary>
/// <value></value>
public string Availability_topic { get; set; }

/// <summary>
/// (Optional) The type/class of the sensor to set the icon in the frontend. See https://www.home-assistant.io/integrations/sensor/#device-class for options.
/// </summary>
Expand Down Expand Up @@ -198,7 +198,7 @@ public class CommandDiscoveryConfigModel : DiscoveryConfigModel
/// <value></value>
public string Value_template { get; set; }
}

/// <summary>
/// This information will be used when announcing this device on the mqtt topic
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public interface IMqttManager
Task ClearDeviceConfigAsync();
void Disconnect();
Task SubscribeAsync(AbstractCommand command);
Task UnubscribeAsync(AbstractCommand command);
Task UnsubscribeAsync(AbstractCommand command);

Task SubscribeNotificationsAsync();

Expand Down
6 changes: 3 additions & 3 deletions src/HASS.Agent.Staging/HASS.Agent/Commands/CommandsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ internal static async Task UnpublishAllCommands()
foreach (var command in Variables.Commands)
{
await command.UnPublishAutoDiscoveryConfigAsync();
await Variables.MqttManager.UnubscribeAsync(command);
await Variables.MqttManager.UnsubscribeAsync(command);
}
}

Expand Down Expand Up @@ -212,7 +212,7 @@ internal static async Task<bool> StoreAsync(List<ConfiguredCommand> commands, Li
{
// remove and unregister
await abstractCommand.UnPublishAutoDiscoveryConfigAsync();
await Variables.MqttManager.UnubscribeAsync(abstractCommand);
await Variables.MqttManager.UnsubscribeAsync(abstractCommand);
Variables.Commands.RemoveAt(Variables.Commands.FindIndex(x => x.Id == abstractCommand.Id));

Log.Information("[COMMANDS] Removed command: {command}", abstractCommand.Name);
Expand Down Expand Up @@ -242,7 +242,7 @@ internal static async Task<bool> StoreAsync(List<ConfiguredCommand> commands, Li
Log.Information("[COMMANDS] Command changed, re-registering as new entity: {old} to {new}", Variables.Commands[currentCommandIndex].Name, abstractCommand.Name);

await Variables.Commands[currentCommandIndex].UnPublishAutoDiscoveryConfigAsync();
await Variables.MqttManager.UnubscribeAsync(Variables.Commands[currentCommandIndex]);
await Variables.MqttManager.UnsubscribeAsync(Variables.Commands[currentCommandIndex]);
await Variables.MqttManager.SubscribeAsync(abstractCommand);
}

Expand Down
Loading