feat(hass): move play_artist script to NetDaemon
All checks were successful
Discord / discord commits (push) Has been skipped
All checks were successful
Discord / discord commits (push) Has been skipped
This commit is contained in:
parent
1b0421f87c
commit
1beab47051
5 changed files with 11 additions and 46 deletions
|
@ -297,7 +297,7 @@ in [
|
||||||
type = "script";
|
type = "script";
|
||||||
sequence = [
|
sequence = [
|
||||||
{
|
{
|
||||||
service = "script.play_artist";
|
service = "netdaemon.spotify_play_artist";
|
||||||
data = {
|
data = {
|
||||||
criteria = "{{ query }}";
|
criteria = "{{ query }}";
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
namespace AppModel;
|
namespace Spotify;
|
||||||
|
|
||||||
using HomeAssistantGenerated;
|
using HomeAssistantGenerated;
|
||||||
using NetDaemon.AppModel;
|
using NetDaemon.AppModel;
|
||||||
|
@ -9,7 +9,7 @@ using System.Text.Json;
|
||||||
record ServiceData(string? criteria);
|
record ServiceData(string? criteria);
|
||||||
|
|
||||||
[NetDaemonApp]
|
[NetDaemonApp]
|
||||||
public class TestScript
|
public class PlayArtist
|
||||||
{
|
{
|
||||||
// Snake-case json options
|
// Snake-case json options
|
||||||
private readonly JsonSerializerOptions _jsonOptions = new JsonSerializerOptions
|
private readonly JsonSerializerOptions _jsonOptions = new JsonSerializerOptions
|
||||||
|
@ -17,10 +17,10 @@ public class TestScript
|
||||||
PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower
|
PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower
|
||||||
};
|
};
|
||||||
|
|
||||||
public TestScript(IHaContext ha)
|
public PlayArtist(IHaContext ha)
|
||||||
{
|
{
|
||||||
ha.RegisterServiceCallBack<ServiceData>(
|
ha.RegisterServiceCallBack<ServiceData>(
|
||||||
"callback_demo",
|
"spotify_play_artist",
|
||||||
async (e) =>
|
async (e) =>
|
||||||
{
|
{
|
||||||
var result = (await ha.CallServiceWithResponseAsync(
|
var result = (await ha.CallServiceWithResponseAsync(
|
||||||
|
@ -39,12 +39,12 @@ public class TestScript
|
||||||
if (uri is not null)
|
if (uri is not null)
|
||||||
{
|
{
|
||||||
ha.CallService(
|
ha.CallService(
|
||||||
"notify",
|
"spotifyplus",
|
||||||
"persistent_notification",
|
"player_media_play_context",
|
||||||
data: new PersistentNotificationCreateParameters
|
data: new SpotifyplusPlayerMediaPlayContextParameters
|
||||||
{
|
{
|
||||||
Message = $"value: {uri}",
|
ContextUri = uri,
|
||||||
Title = "title"
|
EntityId = "media_player.spotifyplus"
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
namespace AppModel;
|
namespace Spotify;
|
||||||
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
|
@ -36,40 +36,5 @@ in {
|
||||||
extraComponents = [
|
extraComponents = [
|
||||||
"spotify"
|
"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 %}
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
}
|
|
||||||
];
|
|
||||||
}
|
|
||||||
];
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue