What it does
Read the exact source snapshot below for its parameters, behavior, and registration.
Read the implementation
This page describes the selected release. The source link points to the same exact commit; it cannot silently open a newer implementation.
Lilith/Core/HomeAutomation/HomeOperations.cs ↗Implementation code
Read the implementation from this version's exact source snapshot. Helper links below stay on the same release.
Lilith/Core/HomeAutomation/HomeOperations.cs
C#
using System.Text.Json;
using Lilith.Core.Commands;
namespace Lilith.Core.HomeAutomation;
internal static class HomeOperations
{
internal static readonly HashSet<string> Names=["home_devices_operation","home_state_operation","home_power_operation","home_brightness_operation","home_color_operation"];
internal static bool Mutates(string name)=>name is "home_power_operation" or "home_brightness_operation" or "home_color_operation";
internal static async Task<string> ExecuteAsync(ProviderClient provider,string name,IReadOnlyDictionary<string,string> inputs,CancellationToken ct)
{
string action=name switch {"home_devices_operation"=>"devices","home_state_operation"=>"state","home_power_operation"=>"power","home_brightness_operation"=>"brightness","home_color_operation"=>"color",_=>throw new ArgumentException("Unknown home task.")};
return JsonSerializer.Serialize(await (provider.Home??throw new InvalidOperationException("Home automation is not configured.")).ExecuteAsync(action,inputs.GetValueOrDefault("device")??"",inputs.GetValueOrDefault("value")??"",ct));
}
}
public static class HomeCommands
{
public static void Register(ChatCommandRegistry commands,Func<ProviderClient> provider)
{
commands.RegisterAsync("home-pending","Review exact pending home-device tasks.",async c=>new(true,await (provider().Home??throw new InvalidOperationException("Home automation not configured.")).ReviewAsync(c.CancellationToken)));
foreach(bool approve in new[]{true,false})
{
bool decision=approve;
commands.RegisterAsync(approve?"home-approve":"home-reject","Decide an exact home proposal: PROPOSAL_ID.",async c=>new(true,await provider().DecideHomeAsync(c.Arguments.Trim(),decision,c.CancellationToken)));
}
}
}
Scenarios using this tool
- home brightness — bundled