Skip to content

Commit

Permalink
Merge pull request #11 from ReikanYsora/feature/run_pipeline
Browse files Browse the repository at this point in the history
feat: Add GetPipelinesList method
  • Loading branch information
vicfergar committed Aug 22, 2023
2 parents 7a105a2 + 3be557e commit d24a8b0
Show file tree
Hide file tree
Showing 5 changed files with 144 additions and 0 deletions.
70 changes: 70 additions & 0 deletions src/HassClient.Core/Models/PipelineInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
using Newtonsoft.Json;

namespace HassClient.Models
{
/// <summary>
/// Defines information related with a Home Assistant 'Assist Pipeline' definition.
/// </summary>
public class PipelineInfo
{
/// <summary>
/// Gets the pipeline conversation engine.
/// </summary>
[JsonProperty("conversation_engine")]
public string ConversationEngine { get; private set; }

/// <summary>
/// Gets the pipeline conversation defined language.
/// </summary>
[JsonProperty("conversation_language")]
public string ConversationLanguage { get; private set; }

/// <summary>
/// Gets the pipeline defined language.
/// </summary>
[JsonProperty("language")]
public string Language { get; private set; }

/// <summary>
/// Gets the pipeline name.
/// </summary>
[JsonProperty("name")]
public string Name { get; private set; }

/// <summary>
/// Gets the SpeechToText engine.
/// </summary>
[JsonProperty("stt_engine")]
public string STTEngine { get; private set; }

/// <summary>
/// Gets the SpeechToText defined language.
/// </summary>
[JsonProperty("stt_language")]
public string STTLanguage { get; private set; }

/// <summary>
/// Gets the TextToSpeach engine.
/// </summary>
[JsonProperty("tts_engine")]
public string TTSEngine { get; private set; }

/// <summary>
/// Gets the TextToSpeach defined language.
/// </summary>
[JsonProperty("tts_language")]
public string TTSLanguage { get; private set; }

/// <summary>
/// Gets the name of TextToSpeach defined voice.
/// </summary>
[JsonProperty("tts_voice")]
public string TTSVoice { get; private set; }

/// <summary>
/// Gets the name of pipeline id.
/// </summary>
[JsonProperty("id")]
public string ID { get; private set; }
}
}
23 changes: 23 additions & 0 deletions src/HassClient.Core/Models/PipelineList.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Newtonsoft.Json;
using System.Collections.Generic;

namespace HassClient.Models
{
/// <summary>
/// Defines information related with Home Assistant list of 'Assist Pipeline' definitions.
/// </summary>
public class PipelineList
{
/// <summary>
/// Gets all defined 'Assist Pipelines' definitions.
/// </summary>[SerializeField]
[JsonProperty("pipelines")]
public List<PipelineInfo> Pipelines { get; private set; }

/// <summary>
/// Gets the preferred defined Assist Pipeline.
/// </summary>[SerializeField]
[JsonProperty("preferred_pipeline")]
public string PreferredPipeline;
}
}
25 changes: 25 additions & 0 deletions src/HassClient.WS.Tests/PipelinesApiTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using HassClient.Models;
using NUnit.Framework;
using System.Threading.Tasks;

namespace HassClient.WS.Tests
{
public class PipelinesApiTests : BaseHassWSApiTest
{
private PipelineList pipelines;

[OneTimeSetUp]
[Test]
public async Task GetPipelines()
{
if (this.pipelines != null)
{
return;
}

this.pipelines = await this.hassWSApi.GetPipelinesListAsync();

Assert.IsNotNull(this.pipelines);
}
}
}
16 changes: 16 additions & 0 deletions src/HassClient.WS/HASSWSApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -977,6 +977,22 @@ public Task<SearchRelatedResponse> SearchRelatedAsync(ItemTypes itemType, string
return this.hassClientWebSocket.SendCommandWithResultAsync<SearchRelatedResponse>(commandMessage, cancellationToken);
}

/// <summary>
/// Gets a pipelines list item with the <see cref="PipelineList"/> for defined Home Assistant Assist Pipelines.
/// </summary>
/// <param name="cancellationToken">
/// A cancellation token used to propagate notification that this operation should be canceled.
/// </param>
/// <returns>
/// A task representing the asynchronous operation. The result of the task is a
/// <see cref="PipelineList"/> of all Home Assistant instance defined 'Assist Pipelines' and the preferred pipeline.
/// </returns>
public async Task<PipelineList> GetPipelinesListAsync(CancellationToken cancellationToken = default)
{
var commandMessage = new PipelineListMessage();
return await this.hassClientWebSocket.SendCommandWithResultAsync<PipelineList>(commandMessage, cancellationToken);
}

/// <summary>
/// Performs a pipeline run starting with a <see cref="StageTypes.Intent"/> stage.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace HassClient.WS.Messages
{
internal class PipelineListMessage : BaseOutgoingMessage
{
public PipelineListMessage()
: base("assist_pipeline/pipeline/list")
{
}
}
}

0 comments on commit d24a8b0

Please sign in to comment.