feat(hass): move play_artist script to NetDaemon
All checks were successful
Discord / discord commits (push) Has been skipped

This commit is contained in:
matt1432 2024-10-05 21:51:43 -04:00
parent 1b0421f87c
commit 1beab47051
5 changed files with 11 additions and 46 deletions

View file

@ -297,7 +297,7 @@ in [
type = "script";
sequence = [
{
service = "script.play_artist";
service = "netdaemon.spotify_play_artist";
data = {
criteria = "{{ query }}";
};

View file

@ -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<ServiceData>(
"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"
}
);
}

View file

@ -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 %}
'';
};
}
];
}
];
};
};
};
}