-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIPublished.cs
More file actions
47 lines (43 loc) · 1.53 KB
/
IPublished.cs
File metadata and controls
47 lines (43 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
namespace LabTracker;
/// <summary>
/// Read current published MQTT messages to initialize client state.
/// </summary>
public interface IPublished
{
/// <summary>
/// Whether this implementation forces a complete snapshot of all connected clients.
/// </summary>
bool ForceSnapshot { get; }
/// <summary>
/// Read current published client states from MQTT retained messages.
/// </summary>
/// <returns>Dictionary with client ID as key and connection state as value</returns>
Task<Dictionary<string, ClientState>> ReadCurrentStatesAsync();
}
/// <summary>
/// Current state of a client from published MQTT messages.
/// </summary>
public class ClientState
{
public string ClientId { get; set; } = string.Empty;
public string? ApHostname { get; set; }
public bool IsConnected { get; set; }
public DateTime LastUpdated { get; set; }
public string? LastPayload { get; set; }
}
/// <summary>
/// Utility methods for IPublished implementations.
/// </summary>
public static class PublishedUtils
{
/// <summary>
/// Creates a standardized client state key combining AP hostname and client ID.
/// </summary>
/// <param name="clientId">The client identifier (typically MAC address)</param>
/// <param name="apHostname">The AP hostname or null for unknown AP</param>
/// <returns>A formatted key in the format "hostname:clientId"</returns>
public static string CreateClientStateKey(string clientId, string? apHostname)
{
return $"{apHostname ?? "unknown"}:{clientId}";
}
}