1
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
using Evergreen.Health.Application.Health.Integrations.HomeAssistant;
|
||||
|
||||
namespace Evergreen.Health.Application.Health.Devices.Contracts;
|
||||
|
||||
public enum DeviceCommandIntent { Normal, StartMassage, TurnRelaxationLightOn, TurnRelaxationLightOff }
|
||||
|
||||
/// <summary>实体由后端模块提供,不接受客户端任意实体或任意服务名。</summary>
|
||||
public sealed record DeviceCommand(string Name, string EntityId, string Domain, string Service,
|
||||
IReadOnlyDictionary<string, object?>? Data = null, string? ExpectedState = null)
|
||||
{
|
||||
public DeviceCommandIntent Intent { get; init; } = DeviceCommandIntent.Normal;
|
||||
// 新设备的能力校验由模块提供,所有发送路径(含场景关闭)都不可绕过。
|
||||
public Action<HomeAssistantState>? ValidateCurrentState { get; init; }
|
||||
// 不为空时 ExpectedState 表示此属性的期望值,而不是实体的顶层状态。
|
||||
public string? ExpectedAttribute { get; init; }
|
||||
public bool RetryOnVerificationMismatch { get; init; } = true;
|
||||
public Dictionary<string, object?> ToServiceData()
|
||||
{
|
||||
var result = Data is null ? new Dictionary<string, object?>() : new Dictionary<string, object?>(Data);
|
||||
result["entity_id"] = EntityId;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
public sealed record DeviceParameterDefinition(string Key, string EntityId,
|
||||
Func<object?, DeviceCommand> Build, string Label,
|
||||
int? Minimum = null, int? Maximum = null, IReadOnlyList<string>? Options = null);
|
||||
Reference in New Issue
Block a user