From 1beab470517c5ffe94f44ecd4416b571e8431e8e Mon Sep 17 00:00:00 2001 From: matt1432 Date: Sat, 5 Oct 2024 21:51:43 -0400 Subject: [PATCH] feat(hass): move play_artist script to NetDaemon --- .../modules/home-assistant/docs/functions.nix | 2 +- .../PlayArtist/PlayArtist.cs} | 18 +++++----- .../PlayArtist/PlayArtist.yaml} | 0 .../PlayArtist}/SpotifyTypes.cs | 2 +- .../homie/modules/home-assistant/spotify.nix | 35 ------------------- 5 files changed, 11 insertions(+), 46 deletions(-) rename devices/homie/modules/home-assistant/netdaemon/apps/{AppModel/TestScript/TestScript.cs => Spotify/PlayArtist/PlayArtist.cs} (75%) rename devices/homie/modules/home-assistant/netdaemon/apps/{AppModel/TestScript/TestScript.yaml => Spotify/PlayArtist/PlayArtist.yaml} (100%) rename devices/homie/modules/home-assistant/netdaemon/apps/{AppModel/TestScript => Spotify/PlayArtist}/SpotifyTypes.cs (98%) diff --git a/devices/homie/modules/home-assistant/docs/functions.nix b/devices/homie/modules/home-assistant/docs/functions.nix index 92df1127..1bec256e 100644 --- a/devices/homie/modules/home-assistant/docs/functions.nix +++ b/devices/homie/modules/home-assistant/docs/functions.nix @@ -297,7 +297,7 @@ in [ type = "script"; sequence = [ { - service = "script.play_artist"; + service = "netdaemon.spotify_play_artist"; data = { criteria = "{{ query }}"; }; diff --git a/devices/homie/modules/home-assistant/netdaemon/apps/AppModel/TestScript/TestScript.cs b/devices/homie/modules/home-assistant/netdaemon/apps/Spotify/PlayArtist/PlayArtist.cs similarity index 75% rename from devices/homie/modules/home-assistant/netdaemon/apps/AppModel/TestScript/TestScript.cs rename to devices/homie/modules/home-assistant/netdaemon/apps/Spotify/PlayArtist/PlayArtist.cs index 43fbb61f..3f681496 100644 --- a/devices/homie/modules/home-assistant/netdaemon/apps/AppModel/TestScript/TestScript.cs +++ b/devices/homie/modules/home-assistant/netdaemon/apps/Spotify/PlayArtist/PlayArtist.cs @@ -1,4 +1,4 @@ -namespace AppModel; +namespace Spotify; using HomeAssistantGenerated; using NetDaemon.AppModel; @@ -9,7 +9,7 @@ using System.Text.Json; record ServiceData(string? criteria); [NetDaemonApp] -public class TestScript +public class PlayArtist { // Snake-case json options private readonly JsonSerializerOptions _jsonOptions = new JsonSerializerOptions @@ -17,10 +17,10 @@ public class TestScript PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower }; - public TestScript(IHaContext ha) + public PlayArtist(IHaContext ha) { ha.RegisterServiceCallBack( - "callback_demo", + "spotify_play_artist", async (e) => { var result = (await ha.CallServiceWithResponseAsync( @@ -39,12 +39,12 @@ public class TestScript if (uri is not null) { ha.CallService( - "notify", - "persistent_notification", - data: new PersistentNotificationCreateParameters + "spotifyplus", + "player_media_play_context", + data: new SpotifyplusPlayerMediaPlayContextParameters { - Message = $"value: {uri}", - Title = "title" + ContextUri = uri, + EntityId = "media_player.spotifyplus" } ); } diff --git a/devices/homie/modules/home-assistant/netdaemon/apps/AppModel/TestScript/TestScript.yaml b/devices/homie/modules/home-assistant/netdaemon/apps/Spotify/PlayArtist/PlayArtist.yaml similarity index 100% rename from devices/homie/modules/home-assistant/netdaemon/apps/AppModel/TestScript/TestScript.yaml rename to devices/homie/modules/home-assistant/netdaemon/apps/Spotify/PlayArtist/PlayArtist.yaml diff --git a/devices/homie/modules/home-assistant/netdaemon/apps/AppModel/TestScript/SpotifyTypes.cs b/devices/homie/modules/home-assistant/netdaemon/apps/Spotify/PlayArtist/SpotifyTypes.cs similarity index 98% rename from devices/homie/modules/home-assistant/netdaemon/apps/AppModel/TestScript/SpotifyTypes.cs rename to devices/homie/modules/home-assistant/netdaemon/apps/Spotify/PlayArtist/SpotifyTypes.cs index b8d0e04e..ce60c36b 100644 --- a/devices/homie/modules/home-assistant/netdaemon/apps/AppModel/TestScript/SpotifyTypes.cs +++ b/devices/homie/modules/home-assistant/netdaemon/apps/Spotify/PlayArtist/SpotifyTypes.cs @@ -1,4 +1,4 @@ -namespace AppModel; +namespace Spotify; using System.Collections.Generic; diff --git a/devices/homie/modules/home-assistant/spotify.nix b/devices/homie/modules/home-assistant/spotify.nix index ed5cf83d..60d9d091 100644 --- a/devices/homie/modules/home-assistant/spotify.nix +++ b/devices/homie/modules/home-assistant/spotify.nix @@ -36,40 +36,5 @@ in { extraComponents = [ "spotify" ]; - - config = { - script.play_artist = { - alias = "Spotify - Play Artist"; - sequence = [ - { - sequence = [ - { - action = "spotifyplus.search_artists"; - data = { - entity_id = "media_player.spotifyplus"; - criteria = ''{{ criteria }}''; - limit = 1; - }; - response_variable = "sp_results"; - } - { - action = "spotifyplus.player_media_play_context"; - data = { - entity_id = "media_player.spotifyplus"; - context_uri = '' - {% for item in sp_results.result | dictsort %} - {% if item[0] == 'items' %} - {{ item[1][0].uri }} - {% break %} - {% endif %} - {%- endfor %} - ''; - }; - } - ]; - } - ]; - }; - }; }; }