28 lines
1.3 KiB
C#
28 lines
1.3 KiB
C#
using Evergreen.Health.Application.Health.Integrations.HomeAssistant;
|
|
using Evergreen.Health.Application.Health.Sleep;
|
|
using Microsoft.Extensions.Options;
|
|
|
|
namespace Evergreen.Health.Application.Health.Devices.Dehumidifier;
|
|
|
|
public sealed class BedPresenceDehumidifierPreview(IHomeAssistantGateway gateway, IOptions<HomeAssistantOptions> options,
|
|
TimeProvider clock) : IBedPresenceAction
|
|
{
|
|
private HomeAssistantOptions Configuration => options.Value;
|
|
private int Threshold => Configuration.SleepScene.TargetHumidity;
|
|
|
|
public string Key => "dehumidifier-humidity-preview";
|
|
public string Description => "湿度偏高时开启除湿机";
|
|
public bool PreviewOnly => true;
|
|
public string ConditionLabel => $"室内相对湿度超过 {Threshold}% 时记录开机计划。";
|
|
|
|
public bool SupportsTarget(string entityId) => DehumidifierHumidityCondition.SupportsTarget(Configuration, entityId);
|
|
|
|
public async Task<string> ExecuteAsync(string entityId, CancellationToken token)
|
|
{
|
|
if (!SupportsTarget(entityId)) return "target-not-configured";
|
|
var states = await gateway.GetStatesAsync(token);
|
|
var reason = DehumidifierHumidityCondition.SkipReason(states, Configuration, clock.GetUtcNow());
|
|
return reason is null ? "preview-would-start" : $"preview-{reason}";
|
|
}
|
|
}
|