去掉老床垫相关功能
This commit is contained in:
+2
-11
@@ -8,6 +8,8 @@ public sealed class HomeAssistantOptions : IConfigurableOptions
|
||||
public string BaseUrl { get; set; } = string.Empty;
|
||||
public string AccessToken { get; set; } = string.Empty;
|
||||
public int TimeoutSeconds { get; set; } = 15;
|
||||
// 匹配已退役设备的明确实体绑定,不按名称或品牌隐藏设备。
|
||||
public List<string> ExcludedDeviceEntityIds { get; set; } = [];
|
||||
public HomeAssistantEntityOptions Entities { get; set; } = new();
|
||||
public HomeAssistantSleepSceneOptions SleepScene { get; set; } = new();
|
||||
public List<SceneLightOptions> AdditionalSleepLights { get; set; } = [];
|
||||
@@ -41,14 +43,6 @@ public sealed class HomeAssistantEntityOptions
|
||||
public string AmbientLight { get; set; } = string.Empty;
|
||||
public string Speaker { get; set; } = string.Empty;
|
||||
public string SpeakerSleepMode { get; set; } = string.Empty;
|
||||
public string MattressLeftHeatingLevel { get; set; } = string.Empty;
|
||||
public string MattressRightHeatingLevel { get; set; } = string.Empty;
|
||||
public string MattressLeftMode { get; set; } = string.Empty;
|
||||
public string MattressRightMode { get; set; } = string.Empty;
|
||||
public Dictionary<string, string> MattressFirmness { get; set; } = new();
|
||||
public string MattressLeftMassagePart { get; set; } = string.Empty;
|
||||
public string MattressRightMassagePart { get; set; } = string.Empty;
|
||||
public string MattressMassageLevel { get; set; } = string.Empty;
|
||||
public string Temperature { get; set; } = string.Empty;
|
||||
public string Humidity { get; set; } = string.Empty;
|
||||
public string Pm25 { get; set; } = string.Empty;
|
||||
@@ -66,8 +60,5 @@ public sealed class HomeAssistantSleepSceneOptions
|
||||
public int LightColorTemperatureKelvin { get; set; } = 2700;
|
||||
public bool EnableFragrance { get; set; } = true;
|
||||
public bool EnableSpeakerSleepMode { get; set; }
|
||||
public bool EnableMattress { get; set; }
|
||||
public int MattressHeatingLevel { get; set; } = 1;
|
||||
public string MattressMode { get; set; } = "智能适配";
|
||||
public bool EnableUv { get; set; }
|
||||
}
|
||||
|
||||
+16
-16
@@ -20,7 +20,7 @@ internal sealed class LightTransitionWorker : ILightTransitionRuntime
|
||||
private readonly TimeProvider _time;
|
||||
private readonly string _entityId;
|
||||
private readonly string? _sleepEffect;
|
||||
private readonly bool _controlsMassage;
|
||||
private readonly bool _isPrimaryLight;
|
||||
private readonly ILogger<HomeAssistantLightTransitionService> _logger;
|
||||
private readonly SemaphoreSlim _operationLock = new(1, 1);
|
||||
private readonly object _statusLock = new();
|
||||
@@ -38,7 +38,7 @@ internal sealed class LightTransitionWorker : ILightTransitionRuntime
|
||||
{
|
||||
_entityId = light?.EntityId ?? options.Value.Entities.AmbientLight;
|
||||
_sleepEffect = light?.SleepEffect;
|
||||
_controlsMassage = light is null;
|
||||
_isPrimaryLight = light is null;
|
||||
_logger = logger;
|
||||
_homeAssistant = homeAssistant;
|
||||
_lightOff = lightOff;
|
||||
@@ -80,7 +80,7 @@ internal sealed class LightTransitionWorker : ILightTransitionRuntime
|
||||
var data = BuildSleepStartData(light, colorTemperatureKelvin);
|
||||
await _homeAssistant.CallServiceAsync("light", "turn_on", data, cancellationToken);
|
||||
|
||||
if (_controlsMassage) _safety.MarkOn();
|
||||
if (_isPrimaryLight) _safety.MarkOn();
|
||||
SetStatus(true, true, "sleep", SleepStartPercent, 0, "助眠渐暗已启动,每5秒降低1%亮度");
|
||||
Launch("sleep", SleepStartPercent);
|
||||
return GetStatus();
|
||||
@@ -95,7 +95,7 @@ internal sealed class LightTransitionWorker : ILightTransitionRuntime
|
||||
{
|
||||
await StopCurrentAsync();
|
||||
var light = await ReadAvailableLightAsync(cancellationToken);
|
||||
var knownOffAt = _controlsMassage ? _safety.OffAt : null;
|
||||
var knownOffAt = _isPrimaryLight ? _safety.OffAt : null;
|
||||
var isOff = string.Equals(light.State, "off", StringComparison.OrdinalIgnoreCase) ||
|
||||
(knownOffAt is not null && (light.LastUpdated is null || light.LastUpdated <= knownOffAt));
|
||||
var brightness = light.GetDoubleAttribute("brightness");
|
||||
@@ -105,7 +105,7 @@ internal sealed class LightTransitionWorker : ILightTransitionRuntime
|
||||
|
||||
if (current >= WakeTargetPercent && !isOff)
|
||||
{
|
||||
if (_controlsMassage) _safety.MarkOn();
|
||||
if (_isPrimaryLight) _safety.MarkOn();
|
||||
SetStatus(true, false, "wake", current, WakeTargetPercent, "当前亮度已达到70%或更高,保持原亮度");
|
||||
return GetStatus();
|
||||
}
|
||||
@@ -119,7 +119,7 @@ internal sealed class LightTransitionWorker : ILightTransitionRuntime
|
||||
}, cancellationToken);
|
||||
}
|
||||
|
||||
if (_controlsMassage) _safety.MarkOn();
|
||||
if (_isPrimaryLight) _safety.MarkOn();
|
||||
SetStatus(true, true, "wake", current, WakeTargetPercent, "晨起唤醒已启动,每5秒增加1%亮度");
|
||||
Launch("wake", current);
|
||||
return GetStatus();
|
||||
@@ -151,7 +151,7 @@ internal sealed class LightTransitionWorker : ILightTransitionRuntime
|
||||
JsonElement modes = default;
|
||||
var hasModes = state.Attributes.ValueKind == JsonValueKind.Object &&
|
||||
state.Attributes.TryGetProperty("supported_color_modes", out modes) && modes.ValueKind == JsonValueKind.Array;
|
||||
if (_controlsMassage && !hasModes)
|
||||
if (_isPrimaryLight && !hasModes)
|
||||
{
|
||||
data["color_temp_kelvin"] = Math.Clamp(kelvin, 2200, 5000);
|
||||
return data;
|
||||
@@ -208,17 +208,17 @@ internal sealed class LightTransitionWorker : ILightTransitionRuntime
|
||||
var light = await ReadAvailableLightAsync(cancellationToken);
|
||||
if (!string.Equals(light.State, "on", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
if (_controlsMassage) _safety.MarkOff(_time.GetUtcNow());
|
||||
if (mode == "sleep" && _controlsMassage)
|
||||
if (_isPrimaryLight) _safety.MarkOff(_time.GetUtcNow());
|
||||
if (mode == "sleep" && _isPrimaryLight)
|
||||
{
|
||||
try
|
||||
{
|
||||
await _lightOff.NotifyAsync(cancellationToken);
|
||||
SetStatus(true, false, mode, 0, 0, "灯已关闭,床垫按摩已停止");
|
||||
SetStatus(true, false, mode, 0, 0, "灯已关闭,渐变已停止");
|
||||
}
|
||||
catch (Exception exception) when (exception is not OperationCanceledException)
|
||||
{
|
||||
_logger.LogWarning(exception, "灯已关闭,但床垫按摩停止失败");
|
||||
_logger.LogWarning(exception, "灯已关闭,但关灯事件处理失败");
|
||||
SetStatus(false, false, mode, 0, 0, exception.Message);
|
||||
}
|
||||
}
|
||||
@@ -245,16 +245,16 @@ internal sealed class LightTransitionWorker : ILightTransitionRuntime
|
||||
{
|
||||
["entity_id"] = LightEntityId
|
||||
}, cancellationToken);
|
||||
if (_controlsMassage) _safety.MarkOff(_time.GetUtcNow());
|
||||
SetStatus(true, false, mode, 0, 0, _controlsMassage ? "灯光已关闭,正在停止床垫按摩" : "助眠渐暗已完成,灯光已关闭");
|
||||
if (_isPrimaryLight) _safety.MarkOff(_time.GetUtcNow());
|
||||
SetStatus(true, false, mode, 0, 0, "助眠渐暗已完成,灯光已关闭");
|
||||
try
|
||||
{
|
||||
if (_controlsMassage) await _lightOff.NotifyAsync(cancellationToken);
|
||||
SetStatus(true, false, mode, 0, 0, _controlsMassage ? "助眠渐暗已完成,灯光与床垫按摩已关闭" : "助眠渐暗已完成,灯光已关闭");
|
||||
if (_isPrimaryLight) await _lightOff.NotifyAsync(cancellationToken);
|
||||
SetStatus(true, false, mode, 0, 0, "助眠渐暗已完成,灯光已关闭");
|
||||
}
|
||||
catch (Exception exception) when (exception is not OperationCanceledException)
|
||||
{
|
||||
_logger.LogWarning(exception, "助眠渐暗已完成,但床垫按摩停止失败");
|
||||
_logger.LogWarning(exception, "助眠渐暗已完成,但关灯事件处理失败");
|
||||
SetStatus(false, false, mode, 0, 0, exception.Message);
|
||||
}
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user