11
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user