This commit is contained in:
fuenmao
2026-11-11 16:11:41 +08:00
parent 3ca90c4cf3
commit 61e25175db
39 changed files with 2176 additions and 31 deletions
@@ -71,10 +71,18 @@ internal sealed class LightTransitionWorker : ILightTransitionRuntime
}
public async Task<HomeAssistantLightTransitionOutput> StartSleepAsync(int colorTemperatureKelvin, CancellationToken cancellationToken)
=> (await StartSleepCoreAsync(colorTemperatureKelvin, onlyIfIdle: false, cancellationToken))!;
internal Task<HomeAssistantLightTransitionOutput?> StartSleepIfIdleAsync(int colorTemperatureKelvin, CancellationToken cancellationToken)
=> StartSleepCoreAsync(colorTemperatureKelvin, onlyIfIdle: true, cancellationToken);
private async Task<HomeAssistantLightTransitionOutput?> StartSleepCoreAsync(int colorTemperatureKelvin, bool onlyIfIdle,
CancellationToken cancellationToken)
{
await _operationLock.WaitAsync(cancellationToken);
try
{
if (onlyIfIdle && GetStatus().Running) return null;
await StopCurrentAsync();
var light = await ReadAvailableLightAsync(cancellationToken);
var data = BuildSleepStartData(light, colorTemperatureKelvin);