11111
This commit is contained in:
@@ -288,17 +288,27 @@ public sealed class SceneLightingIntegrationTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ProductionRegistrationAddsConfiguredStripWithoutCreatingASecondDeviceControlImplementation()
|
||||
public async Task ProductionRegistrationAddsSceneStripWithIndependentManualPower()
|
||||
{
|
||||
var services = new ServiceCollection(); services.AddOptions(); services.AddLogging(); services.AddHttpClient();
|
||||
services.AddSingleton<IOptions<HomeAssistantOptions>>(Options.Create(Settings()));
|
||||
services.AddHealthDevices(); services.AddSingleton<IHomeAssistantGateway>(new FakeHaGateway());
|
||||
var settings = Settings();
|
||||
settings.AdditionalSleepLights.Single().StartSleepOnManualPowerOn = false;
|
||||
var gateway = new FakeHaGateway();
|
||||
gateway.States[Strip] = Light(Strip);
|
||||
services.AddSingleton<IOptions<HomeAssistantOptions>>(Options.Create(settings));
|
||||
services.AddHealthDevices(); services.AddSingleton<IHomeAssistantGateway>(gateway);
|
||||
services.AddSingleton<IAudioPlaybackGateway>(new FakeAudioGateway());
|
||||
using var provider = services.BuildServiceProvider();
|
||||
var registry = provider.GetRequiredService<DeviceModuleRegistry>();
|
||||
Assert.IsType<ConfiguredSleepLightModule>(registry.ForEntities([Strip]));
|
||||
var strip = Assert.IsType<ConfiguredSleepLightModule>(registry.ForEntities([Strip]));
|
||||
Assert.IsType<LightingModule>(registry.ForEntities([Primary]));
|
||||
Assert.IsType<ClimateModule>(registry.ForEntities([Climate]));
|
||||
await strip.SetPowerAsync(true, default);
|
||||
var command = Assert.Single(gateway.Calls);
|
||||
Assert.Equal(Strip, command.EntityId);
|
||||
Assert.Equal("turn_on", command.Service);
|
||||
Assert.Single(command.Data!); // 详情页开灯不套用舒睡模式或亮度。
|
||||
Assert.False(provider.GetRequiredService<HomeAssistantLightTransitionService>().ForEntity(Strip).GetStatus().Running);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
@@ -96,6 +96,43 @@ public sealed class StandardLightControlTests
|
||||
Assert.Single(gateway.Calls);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ConfiguredManualLightsAreDiscoveredIndependentlyWithInventoryFilteringEnabled()
|
||||
{
|
||||
const string auxiliary = "light.auxiliary", unconfigured = "light.unconfigured";
|
||||
var gateway = new FakeHaGateway();
|
||||
foreach (var id in new[] { LightA, LightB, auxiliary, unconfigured }) gateway.States[id] = State(id);
|
||||
var catalog = new HomeAssistantDeviceCatalog(Options.Create(new HomeAssistantOptions
|
||||
{
|
||||
OnlyConfiguredDevices = true, ManualLightEntityIds = [LightA, LightB, LightB]
|
||||
}), new DeviceModuleRegistry([]));
|
||||
var haRegistry = new HomeAssistantRegistries
|
||||
{
|
||||
Devices = [new() { Id = "a", Name = "顶灯一" }, new() { Id = "b", Name = "顶灯二" }, new() { Id = "other" }],
|
||||
Entities = [new() { DeviceId = "a", EntityId = auxiliary }, new() { DeviceId = "a", EntityId = LightA },
|
||||
new() { DeviceId = "b", EntityId = LightB }, new() { DeviceId = "other", EntityId = unconfigured }]
|
||||
};
|
||||
var controller = Controller(gateway);
|
||||
foreach (var registry in new[] { haRegistry, null })
|
||||
{
|
||||
var devices = catalog.BuildDiscoveredDevices(registry, gateway.States);
|
||||
Assert.Equal(2, devices.Count);
|
||||
var first = Assert.Single(devices, item => item.PrimaryControlEntityId == LightA);
|
||||
var second = Assert.Single(devices, item => item.PrimaryControlEntityId == LightB);
|
||||
Assert.NotEqual(first.DeviceId, second.DeviceId);
|
||||
Assert.All(devices, item =>
|
||||
{
|
||||
Assert.Equal(nameof(HealthDeviceCategory.Lighting), item.Category);
|
||||
Assert.Equal("", item.ModuleKey);
|
||||
});
|
||||
await controller.ExecuteAsync(first, gateway.States, "light_brightness", 30, LightA, default);
|
||||
await controller.ExecuteAsync(second, gateway.States, "light_color_temperature", 3100, LightB, default);
|
||||
await Assert.ThrowsAsync<InvalidOperationException>(() => controller.ExecuteAsync(
|
||||
second, gateway.States, "light_brightness", 40, LightA, default));
|
||||
}
|
||||
Assert.Equal(new[] { LightA, LightB, LightA, LightB }, gateway.Calls.Select(call => call.EntityId));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task TwoLightsUseIndependentRangesAndEffectLists()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user