Add MusicCast discovery service
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\MusicCast.Net.Api.Client\MusicCast.Net.Api.Client.csproj" PrivateAssets="*" />
|
||||
<ProjectReference Include="..\MusicCast.Net.Client\MusicCast.Net.Client.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -3,37 +3,22 @@
|
||||
// API requires no authentication, so use the anonymous
|
||||
// authentication provider
|
||||
|
||||
using System.Text.Json;
|
||||
using Microsoft.Kiota.Abstractions.Authentication;
|
||||
using Microsoft.Kiota.Http.HttpClientLibrary;
|
||||
using MusicCast.Net.Api.Client;
|
||||
using MusicCast.Net.Api.Client.YamahaExtendedControl.V1.Main.SetPower;
|
||||
using MusicCast.Net.Client;
|
||||
|
||||
// API requires no authentication, so use the anonymous
|
||||
// authentication provider
|
||||
var authProvider = new AnonymousAuthenticationProvider();
|
||||
// Get device IP Address
|
||||
var discoveryService = new MusicCastDiscoveryService();
|
||||
|
||||
// Create request adapter using the HttpClient-based implementation
|
||||
using var adapter = new HttpClientRequestAdapter(authProvider);
|
||||
adapter.BaseUrl = "http://192.168.129.21";
|
||||
var localIpAddress = discoveryService.GetLocalSubnetAddress()!;
|
||||
|
||||
var client = new MusicCastApiClient(adapter);
|
||||
var deviceAddresses = await discoveryService.GetMusicCastDeviceAddresses(localIpAddress);
|
||||
|
||||
var status = await client.YamahaExtendedControl.V1.Main.GetStatus.GetAsync();
|
||||
Console.WriteLine(status!.Power);
|
||||
foreach (var deviceAddress in deviceAddresses)
|
||||
{
|
||||
Console.WriteLine(deviceAddress);
|
||||
}
|
||||
|
||||
await client.YamahaExtendedControl.V1.Main.SetPower.GetAsync(conf => conf.QueryParameters.Power = GetPowerQueryParameterType.On);
|
||||
// Create and use client
|
||||
var client = new MusicCastClient(deviceAddresses.First());
|
||||
|
||||
await Task.Delay(5000);
|
||||
Console.WriteLine(await client.PowerOff());
|
||||
|
||||
status = await client.YamahaExtendedControl.V1.Main.GetStatus.GetAsync();
|
||||
Console.WriteLine(status!.Power);
|
||||
|
||||
await client.YamahaExtendedControl.V1.Main.SetPower.GetAsync(r =>
|
||||
r.QueryParameters.Power = GetPowerQueryParameterType.Standby
|
||||
);
|
||||
|
||||
await Task.Delay(5000);
|
||||
|
||||
status = await client.YamahaExtendedControl.V1.Main.GetStatus.GetAsync();
|
||||
Console.WriteLine(status!.Power);
|
||||
Reference in New Issue
Block a user