去掉老床垫相关功能
This commit is contained in:
@@ -4,7 +4,6 @@ using Evergreen.Health.Application.Health.Devices.Contracts;
|
||||
using Evergreen.Health.Application.Health.Devices.Discovery;
|
||||
using Evergreen.Health.Application.Health.Devices.Environment;
|
||||
using Evergreen.Health.Application.Health.Devices.Lighting;
|
||||
using Evergreen.Health.Application.Health.Devices.Mattress;
|
||||
using Evergreen.Health.Application.Health.Integrations.HomeAssistant;
|
||||
using Evergreen.Health.Application.Health.Integrations.MiAirX;
|
||||
using Evergreen.Health.Application.Health.Models;
|
||||
@@ -28,11 +27,8 @@ public sealed class DeviceArchitectureTests
|
||||
Entities = new()
|
||||
{
|
||||
AmbientLight = "light.bedroom", Speaker = "media_player.speaker", SpeakerSleepMode = "switch.sleep",
|
||||
Temperature = "sensor.room_temperature", MattressLeftMode = "select.left_mode", MattressRightMode = "select.right_mode",
|
||||
MattressLeftHeatingLevel = "number.left_heat", MattressRightHeatingLevel = "number.right_heat",
|
||||
MattressLeftMassagePart = "select.left_massage", MattressRightMassagePart = "select.right_massage",
|
||||
MattressMassageLevel = "select.massage_level", MattressFirmness = new() { ["left_shoulder"] = "select.left_shoulder" }
|
||||
}, SleepScene = new() { EnableMattress = true }
|
||||
Temperature = "sensor.room_temperature"
|
||||
}
|
||||
};
|
||||
private static HomeAssistantState Temperature(double value, DateTimeOffset? observed) => new()
|
||||
{
|
||||
@@ -40,25 +36,6 @@ public sealed class DeviceArchitectureTests
|
||||
LastReported = observed, Attributes = JsonSerializer.SerializeToElement(new { unit_of_measurement = "°C" })
|
||||
};
|
||||
|
||||
[Theory]
|
||||
[InlineData(18.4, "很软")]
|
||||
[InlineData(18.5, "稍软")]
|
||||
[InlineData(24.0, "稍硬")]
|
||||
[InlineData(28.0, "很硬")]
|
||||
[InlineData(31.1, "很硬")]
|
||||
[InlineData(32.0, "最硬")]
|
||||
public void BmiUsesStableFirmnessBoundaries(double bmi, string expected)
|
||||
=> Assert.Equal(expected, BmiFirmnessPolicy.Firmness((decimal)bmi));
|
||||
|
||||
[Fact]
|
||||
public void MissingOrInvalidBodyDataNeverProducesFirmness()
|
||||
{
|
||||
Assert.Null(BmiFirmnessPolicy.Calculate(null, 80));
|
||||
Assert.Null(BmiFirmnessPolicy.Calculate(0, 80));
|
||||
Assert.Null(BmiFirmnessPolicy.Firmness(null));
|
||||
Assert.Equal(31.1m, BmiFirmnessPolicy.Calculate(180, 100.8m));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(21.9, "heat")]
|
||||
[InlineData(22.0, "off")]
|
||||
@@ -131,10 +108,6 @@ public sealed class DeviceArchitectureTests
|
||||
Assert.Throws<InvalidOperationException>(() => light.BuildParameterCommand("color_temp", 6500));
|
||||
Assert.Equal("light.bedroom", light.BuildParameterCommand("brightness", 0).EntityId);
|
||||
Assert.Equal("turn_off", light.BuildParameterCommand("brightness", 0).Service);
|
||||
var mattress = new MattressModule(runner, Options.Create(Configuration()));
|
||||
Assert.Equal("全身", mattress.BuildParameterCommand("mattress_massage_right_part", "全身").Data!["option"]);
|
||||
Assert.Equal("轻柔", mattress.BuildParameterCommand("mattress_massage_level", "轻柔").Data!["option"]);
|
||||
Assert.Throws<InvalidOperationException>(() => mattress.BuildParameterCommand("mattress_right_mode", "随意模式"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -163,15 +136,15 @@ public sealed class DeviceArchitectureTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FallbackOnlyContainsConfiguredModulesAndIncludesMattressEntities()
|
||||
public void FallbackOnlyContainsConfiguredModules()
|
||||
{
|
||||
var runner = Runner(new());
|
||||
var options = Options.Create(Configuration());
|
||||
var catalog = new HomeAssistantDeviceCatalog(options, new DeviceModuleRegistry([new MattressModule(runner, options)]));
|
||||
var catalog = new HomeAssistantDeviceCatalog(options, new DeviceModuleRegistry([new LightingModule(runner, options, new FakeLight(), new LightOffDispatcher([]))]));
|
||||
var device = Assert.Single(catalog.BuildDiscoveredDevices(null, new Dictionary<string, HomeAssistantState>()));
|
||||
Assert.Equal("mattress", device.ModuleKey);
|
||||
Assert.Contains(device.Entities, entity => entity.EntityId == "select.right_massage");
|
||||
Assert.Null(device.PrimaryControlEntityId);
|
||||
Assert.Equal("lighting", device.ModuleKey);
|
||||
Assert.Contains(device.Entities, entity => entity.EntityId == "light.bedroom");
|
||||
Assert.Equal("light.bedroom", device.PrimaryControlEntityId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -218,17 +191,15 @@ public sealed class DeviceArchitectureTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ManualLightOffUsesSceneLinkageToStopBothMassageSides()
|
||||
public async Task ManualLightOffOnlyControlsTheLight()
|
||||
{
|
||||
var gateway = new FakeHaGateway();
|
||||
var runner = Runner(gateway);
|
||||
var options = Options.Create(Configuration());
|
||||
var mattress = new MattressModule(runner, options);
|
||||
var light = new LightingModule(runner, options, new FakeLight(), new LightOffDispatcher([mattress]));
|
||||
var light = new LightingModule(runner, options, new FakeLight(), new LightOffDispatcher([]));
|
||||
await light.ExecuteParameterAsync(light.BuildParameterCommand("brightness", 0), default);
|
||||
Assert.Equal("off", gateway.States["light.bedroom"].State);
|
||||
Assert.Equal("无", gateway.States["select.right_massage"].State);
|
||||
Assert.Equal("无", gateway.States["select.left_massage"].State);
|
||||
Assert.All(gateway.Calls, command => Assert.Equal("light.bedroom", command.EntityId));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -248,7 +219,9 @@ public sealed class DeviceArchitectureTests
|
||||
using var provider = services.BuildServiceProvider(new ServiceProviderOptions { ValidateOnBuild = true, ValidateScopes = true });
|
||||
Assert.NotNull(provider.GetRequiredService<HealthSceneCoordinator>());
|
||||
Assert.Equal(2, provider.GetServices<IHostedService>().Count());
|
||||
Assert.Contains(provider.GetRequiredService<DeviceModuleRegistry>().Modules, module => module.Key == "mattress");
|
||||
Assert.DoesNotContain(provider.GetRequiredService<DeviceModuleRegistry>().Modules, module => module.Key == "mattress");
|
||||
Assert.Empty(provider.GetServices<ILightOffHandler>());
|
||||
Assert.Throws<InvalidOperationException>(() => provider.GetRequiredService<DeviceModuleRegistry>().ForParameter("mattress_left_heating"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
Reference in New Issue
Block a user