feat: add BatteryMonitor implementation with discovery, notification, and scheduling services

This commit is contained in:
Marius
2026-04-01 10:55:33 +03:00
parent 11c2574235
commit 6e4d684359
114 changed files with 22820 additions and 527 deletions
@@ -0,0 +1,52 @@
using System.ComponentModel;
using System.Text.Json;
using HomeAssistant.McpServer.Services;
using ModelContextProtocol.Server;
namespace HomeAssistant.McpServer.Tools;
[McpServerToolType]
public sealed class SystemTools
{
private readonly IHomeAssistantApiClient _client;
public SystemTools(IHomeAssistantApiClient client)
{
_client = client;
}
[McpServerTool, Description(
"Get Home Assistant configuration including version, location, components, and unit system. " +
"Useful for understanding the HA environment.")]
public async Task<string> GetHaConfig(CancellationToken cancellationToken = default)
{
var result = await _client.GetConfigAsync(cancellationToken).ConfigureAwait(false);
return JsonSerializer.Serialize(result, SerializerOptions);
}
[McpServerTool, Description(
"Check if the Home Assistant API is reachable and responding. " +
"Returns the API status message or an error description.")]
public async Task<string> CheckApi(CancellationToken cancellationToken = default)
{
try
{
var result = await _client.GetApiStatusAsync(cancellationToken).ConfigureAwait(false);
return JsonSerializer.Serialize(result, SerializerOptions);
}
catch (HttpRequestException ex)
{
return JsonSerializer.Serialize(new { status = "error", message = ex.Message }, SerializerOptions);
}
catch (TaskCanceledException)
{
return JsonSerializer.Serialize(
new { status = "error", message = "Request timed out - HA may be unreachable" }, SerializerOptions);
}
}
private static readonly JsonSerializerOptions SerializerOptions = new()
{
WriteIndented = true
};
}