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

@@ -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>

View File

@@ -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);