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,45 @@
using System.ComponentModel;
using System.Text.Json;
using HomeAssistant.McpServer.Services;
using ModelContextProtocol.Server;
namespace HomeAssistant.McpServer.Tools;
[McpServerToolType]
public sealed class LogbookTools
{
private readonly IHomeAssistantApiClient _client;
public LogbookTools(IHomeAssistantApiClient client)
{
_client = client;
}
[McpServerTool, Description(
"Get Home Assistant logbook entries. Shows state changes and events for entities. " +
"Useful for understanding what happened and when. Filter by entity and/or time range.")]
public async Task<string> GetLogbook(
[Description("Optional entity ID to filter, e.g. 'switch.boiler'. Leave empty for all.")] string? entityId = null,
[Description("Start time in ISO 8601 format. Defaults to 24 hours ago.")] string? startTime = null,
[Description("End time in ISO 8601 format. Defaults to now.")] string? endTime = null,
CancellationToken cancellationToken = default)
{
DateTimeOffset? start = string.IsNullOrWhiteSpace(startTime)
? null
: DateTimeOffset.Parse(startTime);
DateTimeOffset? end = string.IsNullOrWhiteSpace(endTime)
? null
: DateTimeOffset.Parse(endTime);
var result = await _client.GetLogbookAsync(entityId, start, end, cancellationToken)
.ConfigureAwait(false);
return JsonSerializer.Serialize(result, SerializerOptions);
}
private static readonly JsonSerializerOptions SerializerOptions = new()
{
WriteIndented = true
};
}