This commit is contained in:
fuenmao
2026-11-11 16:11:41 +08:00
parent 3ca90c4cf3
commit 61e25175db
39 changed files with 2176 additions and 31 deletions
@@ -86,22 +86,23 @@ public sealed class DeviceActionRunner
}
}
public async Task VerifyParameterAsync(DeviceCommand command, CancellationToken cancellationToken)
public async Task VerifyParameterAsync(DeviceCommand command, CancellationToken cancellationToken, int? verificationAttempts = null)
{
var results = new List<HomeAssistantActionResult>
{
new() { Name = command.Name, EntityId = command.EntityId, Status = "Succeeded" }
};
await VerifyBatchAsync([command], results, cancellationToken);
await VerifyBatchAsync([command], results, cancellationToken, verificationAttempts);
if (results[0].Status != "Succeeded") throw new InvalidOperationException(results[0].Message);
}
public async Task VerifyBatchAsync(IReadOnlyList<DeviceCommand> commands,
List<HomeAssistantActionResult> results, CancellationToken cancellationToken)
List<HomeAssistantActionResult> results, CancellationToken cancellationToken, int? verificationAttempts = null)
{
var attempts = verificationAttempts ?? _options.VerificationAttempts;
var pending = commands.Where(command => !string.IsNullOrWhiteSpace(command.EntityId) &&
command.ExpectedState is not null).ToList();
for (var round = 0; round < _options.VerificationAttempts && pending.Count > 0; round++)
for (var round = 0; round < attempts && pending.Count > 0; round++)
{
await DelayAsync(_options.VerificationDelay, cancellationToken);
IReadOnlyList<HomeAssistantState> states;
@@ -126,7 +127,7 @@ public sealed class DeviceActionRunner
action.Status = "Succeeded"; action.Message = round == 0 ? "已回读确认目标状态" : "重试后已回读确认目标状态";
pending.Remove(command); continue;
}
if (round == _options.VerificationAttempts - 1)
if (round == attempts - 1)
{
action.Status = "Failed"; action.Message = $"未确认目标{(command.ExpectedAttribute is null ? "状态" : command.ExpectedAttribute)} {command.ExpectedState}(当前:{actual ?? "未读取到"})";
pending.Remove(command); continue;