This commit is contained in:
fuenmao
2026-10-09 16:46:30 +08:00
parent 4a634ef4c2
commit e6b90a06ab
63 changed files with 4170 additions and 1518 deletions
@@ -6,7 +6,7 @@ using System.Text.Json;
namespace Evergreen.Health.Application.Health.Integrations.MiAirX;
public sealed class MiAirXClient
public sealed class MiAirXClient : IAudioPlaybackGateway
{
private readonly HttpClient _httpClient;
private readonly MiAirXOptions _options;
@@ -23,7 +23,6 @@ public sealed class MiAirXClient
public bool IsConfigured => _options.Enabled &&
!string.IsNullOrWhiteSpace(_options.BaseUrl) &&
!string.IsNullOrWhiteSpace(_options.DeviceId) &&
!string.IsNullOrWhiteSpace(_options.MusicUrl) &&
(!_options.RequireWebPassword || !string.IsNullOrWhiteSpace(_options.WebPassword));
public Task PlayAsync(CancellationToken cancellationToken = default)
@@ -48,6 +47,15 @@ public sealed class MiAirXClient
}
private async Task SendCommandAsync(string path, object payload, CancellationToken cancellationToken)
{
try { await SendCommandCoreAsync(path, payload, cancellationToken); }
catch (OperationCanceledException exception) when (!cancellationToken.IsCancellationRequested)
{
throw new TimeoutException("MiAirX 请求超时,未确认音箱操作完成", exception);
}
}
private async Task SendCommandCoreAsync(string path, object payload, CancellationToken cancellationToken)
{
var baseUri = GetBaseUri();
if (!string.IsNullOrWhiteSpace(_options.WebPassword))