This commit is contained in:
fuenmao
2026-10-09 18:06:11 +08:00
parent e6b90a06ab
commit 2d44cc3966
17 changed files with 1161 additions and 264 deletions
@@ -37,11 +37,14 @@ internal sealed class FakeHaGateway : IHomeAssistantGateway
"select_option" => data["option"]!.ToString()!,
"set_value" => data["value"]!.ToString()!, _ => States.GetValueOrDefault(entity)?.State ?? "unknown"
};
if (service == "set_hvac_mode") state = (string)data["hvac_mode"]!;
var attributes = new Dictionary<string, object?>();
if (States.TryGetValue(entity, out var previous) && previous.Attributes.ValueKind == JsonValueKind.Object)
foreach (var property in previous.Attributes.EnumerateObject()) attributes[property.Name] = property.Value.Clone();
if (data.TryGetValue("brightness_pct", out var brightness))
attributes["brightness"] = Convert.ToDouble(brightness) / 100 * 255;
foreach (var key in new[] { "effect", "color_temp_kelvin", "temperature", "fan_mode" })
if (data.TryGetValue(key, out var value)) attributes[key] = value;
States[entity] = new() { EntityId = entity, State = state, LastReported = Time.GetUtcNow(), LastUpdated = Time.GetUtcNow(),
Attributes = JsonSerializer.SerializeToElement(attributes) };
return Task.CompletedTask;