1111
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
using Evergreen.Health.Application.Health.Integrations.HomeAssistant;
|
||||
using Evergreen.Health.Application.Health.Scenes;
|
||||
using Evergreen.Health.Application.Health.Sleep;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace Evergreen.Health.Application.Health.Devices.Curtain;
|
||||
|
||||
public sealed class BedPresenceCurtainCloseAction(CurtainModule curtain, DeviceActionRunner runner,
|
||||
IOptions<HomeAssistantOptions> options) : IBedPresenceAction
|
||||
{
|
||||
public string Key => "curtain-close";
|
||||
public string Description => "关闭窗帘";
|
||||
public TimeSpan ExecutionTimeout => TimeSpan.FromSeconds(55);
|
||||
|
||||
public bool SupportsTarget(string entityId) => options.Value.Enabled &&
|
||||
entityId?.StartsWith("cover.", StringComparison.Ordinal) == true && entityId == curtain.PrimaryEntityId;
|
||||
|
||||
public async Task<string> ExecuteAsync(string entityId, CancellationToken token)
|
||||
{
|
||||
if (!SupportsTarget(entityId)) return "target-not-configured";
|
||||
var state = await runner.ReadAvailableStateAsync(entityId, token);
|
||||
if (state.State == "closed") return "already-closed";
|
||||
if (state.State == "closing") return "already-closing";
|
||||
if (state.State != "open") return "state-not-open";
|
||||
|
||||
var close = curtain.BuildParameterCommand("curtain_action", "close");
|
||||
var command = close with
|
||||
{
|
||||
ExpectedState = "closed",
|
||||
ValidateCurrentState = current =>
|
||||
{
|
||||
close.ValidateCurrentState?.Invoke(current);
|
||||
if (current.State != "open") throw new InvalidOperationException("窗帘状态已改变,跳过关帘");
|
||||
}
|
||||
};
|
||||
await runner.SendAsync(command, token);
|
||||
try
|
||||
{
|
||||
// 机械行程需要较长回读时间。沿用窗帘命令的只读回读配置,失败不重发关帘。
|
||||
await runner.VerifyParameterAsync(command, token, verificationAttempts: 20);
|
||||
return "readback-confirmed";
|
||||
}
|
||||
catch (InvalidOperationException)
|
||||
{
|
||||
return "sent-readback-unconfirmed";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@ using Microsoft.Extensions.Options;
|
||||
|
||||
namespace Evergreen.Health.Application.Health.Devices.Curtain;
|
||||
|
||||
/// <summary>窗帘开合不是电源开关;本版只提供单独手动控制,不擅自加入舒睡/全关。</summary>
|
||||
/// <summary>集中定义窗帘开合动作和能力校验,供手动控制与独立联动复用。</summary>
|
||||
public sealed class CurtainModule : HealthDeviceModule
|
||||
{
|
||||
private readonly string _entityId;
|
||||
@@ -70,7 +70,7 @@ public sealed class CurtainModule : HealthDeviceModule
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
context.Results.Add(new() { Name = "窗帘场景联动", EntityId = _entityId, Status = "Skipped",
|
||||
Message = string.IsNullOrWhiteSpace(_entityId) ? "窗帘实体尚未配置" : "本版窗帘只支持手动控制,舒睡不自动改变开合位置" });
|
||||
Message = string.IsNullOrWhiteSpace(_entityId) ? "窗帘实体尚未配置" : "一键舒睡保持窗帘当前位置" });
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user