53 lines
1.5 KiB
C#
53 lines
1.5 KiB
C#
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();
|
|
}
|
|
} |