111111
This commit is contained in:
+27
@@ -0,0 +1,27 @@
|
||||
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.Fragrance;
|
||||
|
||||
public sealed class BedPresenceFragranceReleaseAction(DeviceActionRunner runner, IOptions<HomeAssistantOptions> options,
|
||||
bool wakeDevice) : IBedPresenceAction
|
||||
{
|
||||
private string ConfiguredButton => wakeDevice ? options.Value.Entities.WakeFragranceQuickRelease : options.Value.Entities.FragranceQuickRelease;
|
||||
|
||||
public string Key => wakeDevice ? "wake-fragrance-quick-release" : "fragrance-quick-release";
|
||||
public string Description => wakeDevice ? "让香氛机「唤醒」出香一次" : "让米家智能香氛机出香一次";
|
||||
|
||||
public bool SupportsTarget(string entityId) => options.Value.Enabled &&
|
||||
entityId?.StartsWith("button.", StringComparison.Ordinal) == true && entityId == ConfiguredButton;
|
||||
|
||||
public async Task<string> ExecuteAsync(string entityId, CancellationToken token)
|
||||
{
|
||||
if (!SupportsTarget(entityId)) return "target-not-configured";
|
||||
var reason = await runner.SendIfAsync(FragranceModule.BuildQuickRelease(entityId), states =>
|
||||
states.Any(state => string.Equals(state.EntityId, entityId, StringComparison.OrdinalIgnoreCase) &&
|
||||
DeviceActionRunner.IsAvailable(state)) ? null : "fragrance-release-unavailable", token);
|
||||
return reason ?? "fragrance-release-sent";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user