diff --git a/devices/homie/modules/home-assistant/netdaemon/.version b/devices/homie/modules/home-assistant/netdaemon/.version index fb0b462a..09a59f22 100644 --- a/devices/homie/modules/home-assistant/netdaemon/.version +++ b/devices/homie/modules/home-assistant/netdaemon/.version @@ -1 +1 @@ -24.37.1 +24.42.0 diff --git a/devices/homie/modules/home-assistant/netdaemon/HomeAssistantGenerated.cs b/devices/homie/modules/home-assistant/netdaemon/HomeAssistantGenerated.cs index 98c6a00c..8fc8f696 100644 --- a/devices/homie/modules/home-assistant/netdaemon/HomeAssistantGenerated.cs +++ b/devices/homie/modules/home-assistant/netdaemon/HomeAssistantGenerated.cs @@ -1,9 +1,9 @@ //------------------------------------------------------------------------------ // -// Generated using NetDaemon CodeGenerator nd-codegen v24.37.1.0 -// At: 2024-10-10T12:06:21.5284008-04:00 +// Generated using NetDaemon CodeGenerator nd-codegen v24.42.0.0 +// At: 2024-10-20T18:46:11.3758534-04:00 // -// *** Make sure the version of the codegen tool and your nugets Joysoftware.NetDaemon.* have the same version.*** +// *** Make sure the version of the codegen tool and your nugets NetDaemon.* have the same version.*** // You can use following command to keep it up to date with the latest version: // dotnet tool update NetDaemon.HassModel.CodeGen // @@ -35,6 +35,7 @@ public static class GeneratedExtensions ///Registers all injectable generated types in the serviceCollection public static IServiceCollection AddHomeAssistantGenerated(this IServiceCollection serviceCollection) { + serviceCollection.AddTransient(); serviceCollection.AddTransient(); serviceCollection.AddTransient(); serviceCollection.AddTransient(); @@ -53,6 +54,7 @@ public static class GeneratedExtensions serviceCollection.AddTransient(); serviceCollection.AddTransient(); serviceCollection.AddTransient(); + serviceCollection.AddTransient(); serviceCollection.AddTransient(); serviceCollection.AddTransient(); serviceCollection.AddTransient(); @@ -95,7 +97,6 @@ public static class GeneratedExtensions serviceCollection.AddTransient(); serviceCollection.AddTransient(); serviceCollection.AddTransient(); - serviceCollection.AddTransient(); serviceCollection.AddTransient(); serviceCollection.AddTransient(); serviceCollection.AddTransient(); @@ -116,6 +117,49 @@ public static class GeneratedExtensions } } +/// +/// Allows HassModel to instantiate the correct generated Entity types +/// +public class GeneratedEntityFactory : IEntityFactory +{ + public Entity CreateEntity(IHaContext haContext, string entityId) + { + var dot = entityId.IndexOf('.', StringComparison.Ordinal); + var domain = dot < 0 ? entityId.AsSpan() : entityId[..dot]; + return domain switch + { + "automation" => new AutomationEntity(haContext, entityId), + "binary_sensor" => new BinarySensorEntity(haContext, entityId), + "button" => new ButtonEntity(haContext, entityId), + "calendar" => new CalendarEntity(haContext, entityId), + "conversation" => new ConversationEntity(haContext, entityId), + "device_tracker" => new DeviceTrackerEntity(haContext, entityId), + "input_boolean" => new InputBooleanEntity(haContext, entityId), + "input_text" => new InputTextEntity(haContext, entityId), + "light" => new LightEntity(haContext, entityId), + "lock" => new LockEntity(haContext, entityId), + "media_player" => new MediaPlayerEntity(haContext, entityId), + "number" => new NumberEntity(haContext, entityId), + "person" => new PersonEntity(haContext, entityId), + "remote" => new RemoteEntity(haContext, entityId), + "script" => new ScriptEntity(haContext, entityId), + "select" => new SelectEntity(haContext, entityId), + "sensor" when IsNumeric() => new NumericSensorEntity(haContext, entityId), + "sensor" => new SensorEntity(haContext, entityId), + "stt" => new SttEntity(haContext, entityId), + "sun" => new SunEntity(haContext, entityId), + "switch" => new SwitchEntity(haContext, entityId), + "timer" => new TimerEntity(haContext, entityId), + "todo" => new TodoEntity(haContext, entityId), + "tts" => new TtsEntity(haContext, entityId), + "wake_word" => new WakeWordEntity(haContext, entityId), + "weather" => new WeatherEntity(haContext, entityId), + "zone" => new ZoneEntity(haContext, entityId), + _ => new Entity(haContext, entityId)}; + bool IsNumeric() => haContext.GetState(entityId)?.AttributesJson?.TryGetProperty("unit_of_measurement", out _) ?? false; + } +} + public interface IEntities { LightEntities Light { get; } @@ -234,8 +278,6 @@ public partial class MediaPlayerEntities ///UE Boom 2 public MediaPlayerEntity MusicPlayerDaemon => new(_haContext, "media_player.music_player_daemon"); ///onn. 4K Streaming Box - public MediaPlayerEntity Onn4kStreamingBox => new(_haContext, "media_player.onn_4k_streaming_box"); - ///onn. 4K Streaming Box public MediaPlayerEntity Onn4kStreamingBox2 => new(_haContext, "media_player.onn_4k_streaming_box_2"); ///Spotify matt public MediaPlayerEntity SpotifyMatt => new(_haContext, "media_player.spotify_matt"); @@ -984,6 +1026,9 @@ public partial record MediaPlayerAttributes [JsonPropertyName("sp_user_uri")] public string? SpUserUri { get; init; } + + [JsonPropertyName("media_playlist")] + public string? MediaPlaylist { get; init; } } public partial record AutomationEntity : Entity, AutomationAttributes>, IAutomationEntityCore @@ -1476,6 +1521,9 @@ public partial record SensorAttributes [JsonPropertyName("total_media_session_count")] public double? TotalMediaSessionCount { get; init; } + + [JsonPropertyName("74278bda-b644-4520-8f0c-720eaf059935_0_53140")] + public double? _74278bdab64445208f0c720eaf059935053140 { get; init; } } public partial record NumericSensorEntity : NumericEntity, NumericSensorAttributes>, ISensorEntityCore @@ -1864,8 +1912,6 @@ public interface IServices RecorderServices Recorder { get; } - RemoteServices Remote { get; } - RestServices Rest { get; } SceneServices Scene { get; } @@ -1939,7 +1985,6 @@ public partial class Services : IServices public PersistentNotificationServices PersistentNotification => new(_haContext); public PersonServices Person => new(_haContext); public RecorderServices Recorder => new(_haContext); - public RemoteServices Remote => new(_haContext); public RestServices Rest => new(_haContext); public SceneServices Scene => new(_haContext); public ScheduleServices Schedule => new(_haContext); @@ -4465,158 +4510,6 @@ public partial record RecorderPurgeEntitiesParameters public double? KeepDays { get; init; } } -public partial class RemoteServices -{ - private readonly IHaContext _haContext; - public RemoteServices(IHaContext haContext) - { - _haContext = haContext; - } - - ///Deletes a command or a list of commands from the database. - ///The target for this service call - public void DeleteCommand(ServiceTarget target, RemoteDeleteCommandParameters data) - { - _haContext.CallService("remote", "delete_command", target, data); - } - - ///Deletes a command or a list of commands from the database. - ///Device from which commands will be deleted. eg: television - ///The single command or the list of commands to be deleted. eg: Mute - public void DeleteCommand(ServiceTarget target, object command, string? device = null) - { - _haContext.CallService("remote", "delete_command", target, new RemoteDeleteCommandParameters { Device = device, Command = command }); - } - - ///Learns a command or a list of commands from a device. - ///The target for this service call - public void LearnCommand(ServiceTarget target, RemoteLearnCommandParameters data) - { - _haContext.CallService("remote", "learn_command", target, data); - } - - ///Learns a command or a list of commands from a device. - ///Device ID to learn command from. eg: television - ///A single command or a list of commands to learn. eg: Turn on - ///The type of command to be learned. - ///If code must be stored as an alternative. This is useful for discrete codes. Discrete codes are used for toggles that only perform one function. For example, a code to only turn a device on. If it is on already, sending the code won't change the state. - ///Timeout for the command to be learned. - public void LearnCommand(ServiceTarget target, string? device = null, object? command = null, object? commandType = null, bool? alternative = null, long? timeout = null) - { - _haContext.CallService("remote", "learn_command", target, new RemoteLearnCommandParameters { Device = device, Command = command, CommandType = commandType, Alternative = alternative, Timeout = timeout }); - } - - ///Sends a command or a list of commands to a device. - ///The target for this service call - public void SendCommand(ServiceTarget target, RemoteSendCommandParameters data) - { - _haContext.CallService("remote", "send_command", target, data); - } - - ///Sends a command or a list of commands to a device. - ///Device ID to send command to. eg: 32756745 - ///A single command or a list of commands to send. eg: Play - ///The number of times you want to repeat the commands. - ///The time you want to wait in between repeated commands. - ///The time you want to have it held before the release is send. - public void SendCommand(ServiceTarget target, object command, string? device = null, double? numRepeats = null, double? delaySecs = null, double? holdSecs = null) - { - _haContext.CallService("remote", "send_command", target, new RemoteSendCommandParameters { Device = device, Command = command, NumRepeats = numRepeats, DelaySecs = delaySecs, HoldSecs = holdSecs }); - } - - ///Toggles a device on/off. - ///The target for this service call - public void Toggle(ServiceTarget target, object? data = null) - { - _haContext.CallService("remote", "toggle", target, data); - } - - ///Turns the device off. - ///The target for this service call - public void TurnOff(ServiceTarget target, object? data = null) - { - _haContext.CallService("remote", "turn_off", target, data); - } - - ///Sends the power on command. - ///The target for this service call - public void TurnOn(ServiceTarget target, RemoteTurnOnParameters data) - { - _haContext.CallService("remote", "turn_on", target, data); - } - - ///Sends the power on command. - ///Activity ID or activity name to be started. eg: BedroomTV - public void TurnOn(ServiceTarget target, string? activity = null) - { - _haContext.CallService("remote", "turn_on", target, new RemoteTurnOnParameters { Activity = activity }); - } -} - -public partial record RemoteDeleteCommandParameters -{ - ///Device from which commands will be deleted. eg: television - [JsonPropertyName("device")] - public string? Device { get; init; } - - ///The single command or the list of commands to be deleted. eg: Mute - [JsonPropertyName("command")] - public object? Command { get; init; } -} - -public partial record RemoteLearnCommandParameters -{ - ///Device ID to learn command from. eg: television - [JsonPropertyName("device")] - public string? Device { get; init; } - - ///A single command or a list of commands to learn. eg: Turn on - [JsonPropertyName("command")] - public object? Command { get; init; } - - ///The type of command to be learned. - [JsonPropertyName("command_type")] - public object? CommandType { get; init; } - - ///If code must be stored as an alternative. This is useful for discrete codes. Discrete codes are used for toggles that only perform one function. For example, a code to only turn a device on. If it is on already, sending the code won't change the state. - [JsonPropertyName("alternative")] - public bool? Alternative { get; init; } - - ///Timeout for the command to be learned. - [JsonPropertyName("timeout")] - public long? Timeout { get; init; } -} - -public partial record RemoteSendCommandParameters -{ - ///Device ID to send command to. eg: 32756745 - [JsonPropertyName("device")] - public string? Device { get; init; } - - ///A single command or a list of commands to send. eg: Play - [JsonPropertyName("command")] - public object? Command { get; init; } - - ///The number of times you want to repeat the commands. - [JsonPropertyName("num_repeats")] - public double? NumRepeats { get; init; } - - ///The time you want to wait in between repeated commands. - [JsonPropertyName("delay_secs")] - public double? DelaySecs { get; init; } - - ///The time you want to have it held before the release is send. - [JsonPropertyName("hold_secs")] - public double? HoldSecs { get; init; } -} - -public partial record RemoteTurnOnParameters -{ - ///Activity ID or activity name to be started. eg: BedroomTV - [JsonPropertyName("activity")] - public string? Activity { get; init; } -} - public partial class RestServices { private readonly IHaContext _haContext; @@ -10086,163 +9979,6 @@ public static class NumberEntityExtensionMethods } } -public static class RemoteEntityExtensionMethods -{ - ///Deletes a command or a list of commands from the database. - public static void DeleteCommand(this IRemoteEntityCore target, RemoteDeleteCommandParameters data) - { - target.CallService("delete_command", data); - } - - ///Deletes a command or a list of commands from the database. - public static void DeleteCommand(this IEnumerable target, RemoteDeleteCommandParameters data) - { - target.CallService("delete_command", data); - } - - ///Deletes a command or a list of commands from the database. - ///The IRemoteEntityCore to call this service for - ///Device from which commands will be deleted. eg: television - ///The single command or the list of commands to be deleted. eg: Mute - public static void DeleteCommand(this IRemoteEntityCore target, object command, string? device = null) - { - target.CallService("delete_command", new RemoteDeleteCommandParameters { Device = device, Command = command }); - } - - ///Deletes a command or a list of commands from the database. - ///The IEnumerable<IRemoteEntityCore> to call this service for - ///Device from which commands will be deleted. eg: television - ///The single command or the list of commands to be deleted. eg: Mute - public static void DeleteCommand(this IEnumerable target, object command, string? device = null) - { - target.CallService("delete_command", new RemoteDeleteCommandParameters { Device = device, Command = command }); - } - - ///Learns a command or a list of commands from a device. - public static void LearnCommand(this IRemoteEntityCore target, RemoteLearnCommandParameters data) - { - target.CallService("learn_command", data); - } - - ///Learns a command or a list of commands from a device. - public static void LearnCommand(this IEnumerable target, RemoteLearnCommandParameters data) - { - target.CallService("learn_command", data); - } - - ///Learns a command or a list of commands from a device. - ///The IRemoteEntityCore to call this service for - ///Device ID to learn command from. eg: television - ///A single command or a list of commands to learn. eg: Turn on - ///The type of command to be learned. - ///If code must be stored as an alternative. This is useful for discrete codes. Discrete codes are used for toggles that only perform one function. For example, a code to only turn a device on. If it is on already, sending the code won't change the state. - ///Timeout for the command to be learned. - public static void LearnCommand(this IRemoteEntityCore target, string? device = null, object? command = null, object? commandType = null, bool? alternative = null, long? timeout = null) - { - target.CallService("learn_command", new RemoteLearnCommandParameters { Device = device, Command = command, CommandType = commandType, Alternative = alternative, Timeout = timeout }); - } - - ///Learns a command or a list of commands from a device. - ///The IEnumerable<IRemoteEntityCore> to call this service for - ///Device ID to learn command from. eg: television - ///A single command or a list of commands to learn. eg: Turn on - ///The type of command to be learned. - ///If code must be stored as an alternative. This is useful for discrete codes. Discrete codes are used for toggles that only perform one function. For example, a code to only turn a device on. If it is on already, sending the code won't change the state. - ///Timeout for the command to be learned. - public static void LearnCommand(this IEnumerable target, string? device = null, object? command = null, object? commandType = null, bool? alternative = null, long? timeout = null) - { - target.CallService("learn_command", new RemoteLearnCommandParameters { Device = device, Command = command, CommandType = commandType, Alternative = alternative, Timeout = timeout }); - } - - ///Sends a command or a list of commands to a device. - public static void SendCommand(this IRemoteEntityCore target, RemoteSendCommandParameters data) - { - target.CallService("send_command", data); - } - - ///Sends a command or a list of commands to a device. - public static void SendCommand(this IEnumerable target, RemoteSendCommandParameters data) - { - target.CallService("send_command", data); - } - - ///Sends a command or a list of commands to a device. - ///The IRemoteEntityCore to call this service for - ///Device ID to send command to. eg: 32756745 - ///A single command or a list of commands to send. eg: Play - ///The number of times you want to repeat the commands. - ///The time you want to wait in between repeated commands. - ///The time you want to have it held before the release is send. - public static void SendCommand(this IRemoteEntityCore target, object command, string? device = null, double? numRepeats = null, double? delaySecs = null, double? holdSecs = null) - { - target.CallService("send_command", new RemoteSendCommandParameters { Device = device, Command = command, NumRepeats = numRepeats, DelaySecs = delaySecs, HoldSecs = holdSecs }); - } - - ///Sends a command or a list of commands to a device. - ///The IEnumerable<IRemoteEntityCore> to call this service for - ///Device ID to send command to. eg: 32756745 - ///A single command or a list of commands to send. eg: Play - ///The number of times you want to repeat the commands. - ///The time you want to wait in between repeated commands. - ///The time you want to have it held before the release is send. - public static void SendCommand(this IEnumerable target, object command, string? device = null, double? numRepeats = null, double? delaySecs = null, double? holdSecs = null) - { - target.CallService("send_command", new RemoteSendCommandParameters { Device = device, Command = command, NumRepeats = numRepeats, DelaySecs = delaySecs, HoldSecs = holdSecs }); - } - - ///Toggles a device on/off. - public static void Toggle(this IRemoteEntityCore target, object? data = null) - { - target.CallService("toggle", data); - } - - ///Toggles a device on/off. - public static void Toggle(this IEnumerable target, object? data = null) - { - target.CallService("toggle", data); - } - - ///Turns the device off. - public static void TurnOff(this IRemoteEntityCore target, object? data = null) - { - target.CallService("turn_off", data); - } - - ///Turns the device off. - public static void TurnOff(this IEnumerable target, object? data = null) - { - target.CallService("turn_off", data); - } - - ///Sends the power on command. - public static void TurnOn(this IRemoteEntityCore target, RemoteTurnOnParameters data) - { - target.CallService("turn_on", data); - } - - ///Sends the power on command. - public static void TurnOn(this IEnumerable target, RemoteTurnOnParameters data) - { - target.CallService("turn_on", data); - } - - ///Sends the power on command. - ///The IRemoteEntityCore to call this service for - ///Activity ID or activity name to be started. eg: BedroomTV - public static void TurnOn(this IRemoteEntityCore target, string? activity = null) - { - target.CallService("turn_on", new RemoteTurnOnParameters { Activity = activity }); - } - - ///Sends the power on command. - ///The IEnumerable<IRemoteEntityCore> to call this service for - ///Activity ID or activity name to be started. eg: BedroomTV - public static void TurnOn(this IEnumerable target, string? activity = null) - { - target.CallService("turn_on", new RemoteTurnOnParameters { Activity = activity }); - } -} - public static class ScriptEntityExtensionMethods { ///Toggle a script. Starts it, if isn't running, stops it otherwise. diff --git a/devices/homie/modules/home-assistant/netdaemon/default.nix b/devices/homie/modules/home-assistant/netdaemon/default.nix index d346686c..bf53758a 100644 --- a/devices/homie/modules/home-assistant/netdaemon/default.nix +++ b/devices/homie/modules/home-assistant/netdaemon/default.nix @@ -4,6 +4,7 @@ pkgs, ... }: let + inherit (builtins) attrValues replaceStrings; inherit (config.sops) secrets; compiled = pkgs.callPackage ./package.nix {}; @@ -31,7 +32,7 @@ in { }; services.home-assistant = { - customComponents = builtins.attrValues { + customComponents = attrValues { inherit (self.legacyPackages.${pkgs.system}.hass-components) netdaemon @@ -39,13 +40,28 @@ in { }; }; - environment.systemPackages = [ + environment.systemPackages = let + nixFetchDeps = + replaceStrings [(toString self)] ["$FLAKE"] + #nix + '' + let + config = (builtins.getFlake ("$FLAKE")).nixosConfigurations.homie; + inherit (config) pkgs; + + netdaemonConfig = pkgs.callPackage ${toString ./package.nix} {}; + in + netdaemonConfig.fetch-deps + ''; + in [ (pkgs.writeShellApplication { - name = "updateNuDeps"; + name = "bumpNetdaemonDeps"; + runtimeInputs = with pkgs; [ dos2unix dotnet-sdk_8 ]; + text = '' # Install codegen dotnet tool install --create-manifest-if-needed NetDaemon.HassModel.CodeGen --version "$(cat ./.version)" @@ -68,7 +84,11 @@ in { done done - $(nix build --no-link --print-out-paths --impure --expr "let self = builtins.getFlake (\"$FLAKE\"); inherit (self.nixosConfigurations.homie) pkgs; in (pkgs.callPackage $FLAKE/devices/homie/modules/home-assistant/netdaemon/package.nix {}).fetch-deps") . + $(nix build --no-link --print-out-paths --impure --expr "$(cat < - - - - - - - - + + + + + + + +