Add MusicCast discovery service

This commit is contained in:
2025-05-25 19:30:00 +02:00
parent 9904616751
commit 8bf0c981f9
11 changed files with 242 additions and 2479 deletions

View File

@@ -0,0 +1,53 @@
using Microsoft.Kiota.Abstractions.Authentication;
using Microsoft.Kiota.Http.HttpClientLibrary;
using MusicCast.Net.Api.Client;
using MusicCast.Net.Api.Client.Models;
using MusicCast.Net.Api.Client.YamahaExtendedControl.V1.Main.SetPower;
namespace MusicCast.Net.Client;
public class MusicCastClient : IDisposable
{
private readonly string _deviceAddress;
private readonly HttpClientRequestAdapter _apiClientRequestAdaptor;
private readonly MusicCastApiClient _apiClient;
public MusicCastClient(string deviceAddress)
{
_deviceAddress = deviceAddress;
_apiClientRequestAdaptor = new HttpClientRequestAdapter(new AnonymousAuthenticationProvider())
{
BaseUrl = _deviceAddress
};
_apiClient = new MusicCastApiClient(_apiClientRequestAdaptor);
}
public async Task<bool> PowerOn()
{
var response = await _apiClient.YamahaExtendedControl.V1.Main.SetPower.GetAsync(r =>
r.QueryParameters.Power = GetPowerQueryParameterType.On
);
return IsSuccess(response);
}
public async Task<bool> PowerOff()
{
var response = await _apiClient.YamahaExtendedControl.V1.Main.SetPower.GetAsync(r =>
r.QueryParameters.Power = GetPowerQueryParameterType.Standby
);
return IsSuccess(response);
}
private bool IsSuccess(BaseResponse? response)
{
return response is { ResponseCode: 0 };
}
public void Dispose()
{
_apiClientRequestAdaptor.Dispose();
}
}