This commit is contained in:
fuenmao
2026-11-13 14:03:25 +08:00
parent 718b138033
commit 9cfd9e24d7
6 changed files with 105 additions and 9 deletions
@@ -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()
{