using Evergreen.Health.Application.Health.Integrations.HomeAssistant;
namespace Evergreen.Health.Application.Health.Devices.Contracts;
public enum DeviceCommandIntent { Normal = 0, TurnRelaxationLightOn = 2, TurnRelaxationLightOff = 3 }
/// 实体由后端模块提供,不接受客户端任意实体或任意服务名。
public sealed record DeviceCommand(string Name, string EntityId, string Domain, string Service,
IReadOnlyDictionary? Data = null, string? ExpectedState = null)
{
public DeviceCommandIntent Intent { get; init; } = DeviceCommandIntent.Normal;
// 新设备的能力校验由模块提供,所有发送路径(含场景关闭)都不可绕过。
public Action? ValidateCurrentState { get; init; }
// 不为空时 ExpectedState 表示此属性的期望值,而不是实体的顶层状态。
public string? ExpectedAttribute { get; init; }
public string? ExpectedEntityState { get; init; }
public bool RetryOnVerificationMismatch { get; init; } = true;
public Dictionary ToServiceData()
{
var result = Data is null ? new Dictionary() : new Dictionary(Data);
result["entity_id"] = EntityId;
return result;
}
}
public sealed record DeviceParameterDefinition(string Key, string EntityId,
Func