diff --git a/MusicCast.Net.Api.Client/Models/BaseResponse.cs b/MusicCast.Net.Api.Client/Models/BaseResponse.cs index 588d645..a8d87c3 100644 --- a/MusicCast.Net.Api.Client/Models/BaseResponse.cs +++ b/MusicCast.Net.Api.Client/Models/BaseResponse.cs @@ -15,13 +15,7 @@ namespace MusicCast.Net.Api.Client.Models /// Stores additional data not described in the OpenAPI description found when deserializing. Can be used for serialization as well. public IDictionary AdditionalData { get; set; } /// The response_code property -#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER -#nullable enable - public string? ResponseCode { get; set; } -#nullable restore -#else - public string ResponseCode { get; set; } -#endif + public int? ResponseCode { get; set; } /// /// Instantiates a new and sets the default values. /// @@ -47,7 +41,7 @@ namespace MusicCast.Net.Api.Client.Models { return new Dictionary> { - { "response_code", n => { ResponseCode = n.GetStringValue(); } }, + { "response_code", n => { ResponseCode = n.GetIntValue(); } }, }; } /// @@ -57,7 +51,7 @@ namespace MusicCast.Net.Api.Client.Models public virtual void Serialize(ISerializationWriter writer) { _ = writer ?? throw new ArgumentNullException(nameof(writer)); - writer.WriteStringValue("response_code", ResponseCode); + writer.WriteIntValue("response_code", ResponseCode); writer.WriteAdditionalData(AdditionalData); } } diff --git a/MusicCast.Net.Api.Client/MusicCast.Net.Api.Server.json b/MusicCast.Net.Api.Client/MusicCast.Net.Api.Server.json deleted file mode 100644 index c4d4dc8..0000000 --- a/MusicCast.Net.Api.Client/MusicCast.Net.Api.Server.json +++ /dev/null @@ -1,2436 +0,0 @@ -{ - "openapi": "3.0.1", - "info": { - "title": "MusicCast.Net.Api.Server | v1", - "version": "1.0.0" - }, - "paths": { - "/YamahaExtendedControl/v1/dist/getDistributionInfo": { - "get": { - "tags": [ - "Dist" - ], - "responses": { - "200": { - "description": "OK", - "content": { - "text/plain": { - "schema": { - "$ref": "#/components/schemas/GetDistributionInfoResponse" - } - }, - "application/json": { - "schema": { - "$ref": "#/components/schemas/GetDistributionInfoResponse" - } - }, - "text/json": { - "schema": { - "$ref": "#/components/schemas/GetDistributionInfoResponse" - } - } - } - } - } - } - }, - "/YamahaExtendedControl/v1/main/getStatus": { - "get": { - "tags": [ - "Main" - ], - "responses": { - "200": { - "description": "OK", - "content": { - "text/plain": { - "schema": { - "$ref": "#/components/schemas/GetStatusResponse" - } - }, - "application/json": { - "schema": { - "$ref": "#/components/schemas/GetStatusResponse" - } - }, - "text/json": { - "schema": { - "$ref": "#/components/schemas/GetStatusResponse" - } - } - } - } - } - } - }, - "/YamahaExtendedControl/v1/main/getSignalInfo": { - "get": { - "tags": [ - "Main" - ], - "responses": { - "200": { - "description": "OK", - "content": { - "text/plain": { - "schema": { - "$ref": "#/components/schemas/GetSignalInfoResponse" - } - }, - "application/json": { - "schema": { - "$ref": "#/components/schemas/GetSignalInfoResponse" - } - }, - "text/json": { - "schema": { - "$ref": "#/components/schemas/GetSignalInfoResponse" - } - } - } - } - } - } - }, - "/YamahaExtendedControl/v1/main/setVolume": { - "get": { - "tags": [ - "Main" - ], - "parameters": [ - { - "name": "volume", - "in": "query", - "schema": { - "type": "integer", - "format": "int32" - } - } - ], - "responses": { - "200": { - "description": "OK", - "content": { - "text/plain": { - "schema": { - "$ref": "#/components/schemas/BaseResponse" - } - }, - "application/json": { - "schema": { - "$ref": "#/components/schemas/BaseResponse" - } - }, - "text/json": { - "schema": { - "$ref": "#/components/schemas/BaseResponse" - } - } - } - } - } - } - }, - "/YamahaExtendedControl/v1/main/prepareInputChange": { - "get": { - "tags": [ - "Main" - ], - "parameters": [ - { - "name": "input", - "in": "query", - "schema": { - "type": "string" - } - } - ], - "responses": { - "200": { - "description": "OK", - "content": { - "text/plain": { - "schema": { - "$ref": "#/components/schemas/BaseResponse" - } - }, - "application/json": { - "schema": { - "$ref": "#/components/schemas/BaseResponse" - } - }, - "text/json": { - "schema": { - "$ref": "#/components/schemas/BaseResponse" - } - } - } - } - } - } - }, - "/YamahaExtendedControl/v1/main/setInput": { - "get": { - "tags": [ - "Main" - ], - "parameters": [ - { - "name": "input", - "in": "query", - "schema": { - "type": "string" - } - } - ], - "responses": { - "200": { - "description": "OK", - "content": { - "text/plain": { - "schema": { - "$ref": "#/components/schemas/BaseResponse" - } - }, - "application/json": { - "schema": { - "$ref": "#/components/schemas/BaseResponse" - } - }, - "text/json": { - "schema": { - "$ref": "#/components/schemas/BaseResponse" - } - } - } - } - } - } - }, - "/YamahaExtendedControl/v1/main/setSleep": { - "get": { - "tags": [ - "Main" - ], - "summary": "Shutdown after the specified interval in minutes", - "parameters": [ - { - "name": "sleep", - "in": "query", - "schema": { - "type": "integer", - "format": "int32" - } - } - ], - "responses": { - "200": { - "description": "OK", - "content": { - "text/plain": { - "schema": { - "$ref": "#/components/schemas/BaseResponse" - } - }, - "application/json": { - "schema": { - "$ref": "#/components/schemas/BaseResponse" - } - }, - "text/json": { - "schema": { - "$ref": "#/components/schemas/BaseResponse" - } - } - } - } - } - } - }, - "/YamahaExtendedControl/v1/main/setPower": { - "get": { - "tags": [ - "Main" - ], - "parameters": [ - { - "name": "power", - "in": "query", - "schema": { - "enum": [ - "on", - "standby" - ] - } - } - ], - "responses": { - "200": { - "description": "OK", - "content": { - "text/plain": { - "schema": { - "$ref": "#/components/schemas/BaseResponse" - } - }, - "application/json": { - "schema": { - "$ref": "#/components/schemas/BaseResponse" - } - }, - "text/json": { - "schema": { - "$ref": "#/components/schemas/BaseResponse" - } - } - } - } - } - } - }, - "/YamahaExtendedControl/v1/netusb/getMcPlaylistName": { - "get": { - "tags": [ - "NetUsb" - ], - "responses": { - "200": { - "description": "OK", - "content": { - "text/plain": { - "schema": { - "$ref": "#/components/schemas/GetMcPlaylistNameResponse" - } - }, - "application/json": { - "schema": { - "$ref": "#/components/schemas/GetMcPlaylistNameResponse" - } - }, - "text/json": { - "schema": { - "$ref": "#/components/schemas/GetMcPlaylistNameResponse" - } - } - } - } - } - } - }, - "/YamahaExtendedControl/v1/netusb/getStreamingServiceSettings": { - "get": { - "tags": [ - "NetUsb" - ], - "responses": { - "200": { - "description": "OK", - "content": { - "text/plain": { - "schema": { - "$ref": "#/components/schemas/GetStreamingServiceSettingsResponse" - } - }, - "application/json": { - "schema": { - "$ref": "#/components/schemas/GetStreamingServiceSettingsResponse" - } - }, - "text/json": { - "schema": { - "$ref": "#/components/schemas/GetStreamingServiceSettingsResponse" - } - } - } - } - } - } - }, - "/YamahaExtendedControl/v1/netusb/getPlayInfo": { - "get": { - "tags": [ - "NetUsb" - ], - "responses": { - "200": { - "description": "OK", - "content": { - "text/plain": { - "schema": { - "$ref": "#/components/schemas/GetPlayInfoResponse" - } - }, - "application/json": { - "schema": { - "$ref": "#/components/schemas/GetPlayInfoResponse" - } - }, - "text/json": { - "schema": { - "$ref": "#/components/schemas/GetPlayInfoResponse" - } - } - } - } - } - } - }, - "/YamahaExtendedControl/v1/netusb/getPlayQueue": { - "get": { - "tags": [ - "NetUsb" - ], - "parameters": [ - { - "name": "index", - "in": "query", - "schema": { - "type": "integer", - "format": "int32" - } - } - ], - "responses": { - "200": { - "description": "OK", - "content": { - "text/plain": { - "schema": { - "$ref": "#/components/schemas/GetPlayQueueResponse" - } - }, - "application/json": { - "schema": { - "$ref": "#/components/schemas/GetPlayQueueResponse" - } - }, - "text/json": { - "schema": { - "$ref": "#/components/schemas/GetPlayQueueResponse" - } - } - } - } - } - } - }, - "/YamahaExtendedControl/v1/netusb/getRecentInfo": { - "get": { - "tags": [ - "NetUsb" - ], - "responses": { - "200": { - "description": "OK", - "content": { - "text/plain": { - "schema": { - "$ref": "#/components/schemas/GetRecentInfoResponse" - } - }, - "application/json": { - "schema": { - "$ref": "#/components/schemas/GetRecentInfoResponse" - } - }, - "text/json": { - "schema": { - "$ref": "#/components/schemas/GetRecentInfoResponse" - } - } - } - } - } - } - }, - "/YamahaExtendedControl/v1/netusb/recallRecentItem": { - "get": { - "tags": [ - "NetUsb" - ], - "parameters": [ - { - "name": "zone", - "in": "query", - "schema": { - "type": "string" - } - }, - { - "name": "num", - "in": "query", - "schema": { - "type": "integer", - "format": "int32" - } - } - ], - "responses": { - "200": { - "description": "OK", - "content": { - "text/plain": { - "schema": { - "$ref": "#/components/schemas/BaseResponse" - } - }, - "application/json": { - "schema": { - "$ref": "#/components/schemas/BaseResponse" - } - }, - "text/json": { - "schema": { - "$ref": "#/components/schemas/BaseResponse" - } - } - } - } - } - } - }, - "/YamahaExtendedControl/v1/netusb/setPlayback": { - "get": { - "tags": [ - "NetUsb" - ], - "parameters": [ - { - "name": "playback", - "in": "query", - "schema": { - "enum": [ - "pause", - "previous", - "next", - "stop" - ] - } - } - ], - "responses": { - "200": { - "description": "OK", - "content": { - "text/plain": { - "schema": { - "$ref": "#/components/schemas/BaseResponse" - } - }, - "application/json": { - "schema": { - "$ref": "#/components/schemas/BaseResponse" - } - }, - "text/json": { - "schema": { - "$ref": "#/components/schemas/BaseResponse" - } - } - } - } - } - } - }, - "/YamahaExtendedControl/v1/netusb/toggleShuffle": { - "get": { - "tags": [ - "NetUsb" - ], - "responses": { - "200": { - "description": "OK", - "content": { - "text/plain": { - "schema": { - "$ref": "#/components/schemas/BaseResponse" - } - }, - "application/json": { - "schema": { - "$ref": "#/components/schemas/BaseResponse" - } - }, - "text/json": { - "schema": { - "$ref": "#/components/schemas/BaseResponse" - } - } - } - } - } - } - }, - "/YamahaExtendedControl/v1/netusb/toggleRepeat": { - "get": { - "tags": [ - "NetUsb" - ], - "responses": { - "200": { - "description": "OK", - "content": { - "text/plain": { - "schema": { - "$ref": "#/components/schemas/BaseResponse" - } - }, - "application/json": { - "schema": { - "$ref": "#/components/schemas/BaseResponse" - } - }, - "text/json": { - "schema": { - "$ref": "#/components/schemas/BaseResponse" - } - } - } - } - } - } - }, - "/YamahaExtendedControl/v1/netusb/getListInfo": { - "get": { - "tags": [ - "NetUsb" - ], - "parameters": [ - { - "name": "list_id", - "in": "query", - "schema": { - "type": "string" - } - }, - { - "name": "input", - "in": "query", - "schema": { - "type": "string" - } - }, - { - "name": "size", - "in": "query", - "schema": { - "type": "integer", - "format": "int32" - } - }, - { - "name": "lang", - "in": "query", - "schema": { - "type": "string" - } - } - ], - "responses": { - "200": { - "description": "OK", - "content": { - "text/plain": { - "schema": { - "$ref": "#/components/schemas/GetListInfoResponse" - } - }, - "application/json": { - "schema": { - "$ref": "#/components/schemas/GetListInfoResponse" - } - }, - "text/json": { - "schema": { - "$ref": "#/components/schemas/GetListInfoResponse" - } - } - } - } - } - } - }, - "/YamahaExtendedControl/v1/netusb/setListControl": { - "get": { - "tags": [ - "NetUsb" - ], - "parameters": [ - { - "name": "type", - "in": "query", - "schema": { - "enum": [ - "select", - "play", - "return" - ] - } - }, - { - "name": "index", - "in": "query", - "schema": { - "type": "integer", - "format": "int32" - } - }, - { - "name": "zone", - "in": "query", - "schema": { - "type": "string" - } - } - ], - "responses": { - "200": { - "description": "OK", - "content": { - "text/plain": { - "schema": { - "$ref": "#/components/schemas/BaseResponse" - } - }, - "application/json": { - "schema": { - "$ref": "#/components/schemas/BaseResponse" - } - }, - "text/json": { - "schema": { - "$ref": "#/components/schemas/BaseResponse" - } - } - } - } - } - } - }, - "/YamahaExtendedControl/v1/netusb/manageList": { - "get": { - "tags": [ - "NetUsb" - ], - "parameters": [ - { - "name": "list_id", - "in": "query", - "schema": { - "type": "string" - } - }, - { - "name": "type", - "in": "query", - "schema": { - "enum": [ - "play_now", - "play_next", - "add_to_queue" - ] - } - }, - { - "name": "index", - "in": "query", - "schema": { - "type": "integer", - "format": "int32" - } - }, - { - "name": "timeout", - "in": "query", - "schema": { - "type": "integer", - "format": "int32" - } - }, - { - "name": "zone", - "in": "query", - "schema": { - "type": "string" - } - } - ], - "responses": { - "200": { - "description": "OK", - "content": { - "text/plain": { - "schema": { - "$ref": "#/components/schemas/BaseResponse" - } - }, - "application/json": { - "schema": { - "$ref": "#/components/schemas/BaseResponse" - } - }, - "text/json": { - "schema": { - "$ref": "#/components/schemas/BaseResponse" - } - } - } - } - } - } - }, - "/YamahaExtendedControl/v1/netusb/managePlayQueue": { - "get": { - "tags": [ - "NetUsb" - ], - "parameters": [ - { - "name": "type", - "in": "query", - "schema": { - "enum": [ - "play", - "remove" - ] - } - }, - { - "name": "index", - "in": "query", - "schema": { - "type": "integer", - "format": "int32" - } - }, - { - "name": "zone", - "in": "query", - "schema": { - "type": "string" - } - } - ], - "responses": { - "200": { - "description": "OK", - "content": { - "text/plain": { - "schema": { - "$ref": "#/components/schemas/BaseResponse" - } - }, - "application/json": { - "schema": { - "$ref": "#/components/schemas/BaseResponse" - } - }, - "text/json": { - "schema": { - "$ref": "#/components/schemas/BaseResponse" - } - } - } - } - } - } - }, - "/YamahaExtendedControl/v1/netusb/copyPlayQueue": { - "get": { - "tags": [ - "NetUsb" - ], - "parameters": [ - { - "name": "index", - "in": "query", - "schema": { - "type": "integer", - "format": "int32" - } - } - ], - "responses": { - "200": { - "description": "OK", - "content": { - "text/plain": { - "schema": { - "$ref": "#/components/schemas/BaseResponse" - } - }, - "application/json": { - "schema": { - "$ref": "#/components/schemas/BaseResponse" - } - }, - "text/json": { - "schema": { - "$ref": "#/components/schemas/BaseResponse" - } - } - } - } - } - } - }, - "/YamahaExtendedControl/v1/netusb/movePlayQueueItem": { - "get": { - "tags": [ - "NetUsb" - ], - "parameters": [ - { - "name": "from", - "in": "query", - "schema": { - "type": "integer", - "format": "int32" - } - }, - { - "name": "to", - "in": "query", - "schema": { - "type": "integer", - "format": "int32" - } - } - ], - "responses": { - "200": { - "description": "OK", - "content": { - "text/plain": { - "schema": { - "$ref": "#/components/schemas/BaseResponse" - } - }, - "application/json": { - "schema": { - "$ref": "#/components/schemas/BaseResponse" - } - }, - "text/json": { - "schema": { - "$ref": "#/components/schemas/BaseResponse" - } - } - } - } - } - } - }, - "/YamahaExtendedControl/v1/system/getFeatures": { - "get": { - "tags": [ - "System" - ], - "summary": "Get the available features for this device", - "responses": { - "200": { - "description": "OK", - "content": { - "text/plain": { - "schema": { - "$ref": "#/components/schemas/GetFeaturesResponse" - } - }, - "application/json": { - "schema": { - "$ref": "#/components/schemas/GetFeaturesResponse" - } - }, - "text/json": { - "schema": { - "$ref": "#/components/schemas/GetFeaturesResponse" - } - } - } - } - } - } - }, - "/YamahaExtendedControl/v1/system/getLocationInfo": { - "get": { - "tags": [ - "System" - ], - "responses": { - "200": { - "description": "OK", - "content": { - "text/plain": { - "schema": { - "$ref": "#/components/schemas/GetLocationInfoResponse" - } - }, - "application/json": { - "schema": { - "$ref": "#/components/schemas/GetLocationInfoResponse" - } - }, - "text/json": { - "schema": { - "$ref": "#/components/schemas/GetLocationInfoResponse" - } - } - } - } - } - } - }, - "/YamahaExtendedControl/v1/system/getNameText": { - "get": { - "tags": [ - "System" - ], - "summary": "Get sources friendly names", - "responses": { - "200": { - "description": "OK", - "content": { - "text/plain": { - "schema": { - "$ref": "#/components/schemas/GetNameTextResponse" - } - }, - "application/json": { - "schema": { - "$ref": "#/components/schemas/GetNameTextResponse" - } - }, - "text/json": { - "schema": { - "$ref": "#/components/schemas/GetNameTextResponse" - } - } - } - } - } - } - }, - "/YamahaExtendedControl/v1/system/getDeviceInfo": { - "get": { - "tags": [ - "System" - ], - "responses": { - "200": { - "description": "OK", - "content": { - "text/plain": { - "schema": { - "$ref": "#/components/schemas/GetDeviceInfoResponse" - } - }, - "application/json": { - "schema": { - "$ref": "#/components/schemas/GetDeviceInfoResponse" - } - }, - "text/json": { - "schema": { - "$ref": "#/components/schemas/GetDeviceInfoResponse" - } - } - } - } - } - } - }, - "/YamahaExtendedControl/v1/system/isNewFirmwareAvailable": { - "get": { - "tags": [ - "System" - ], - "parameters": [ - { - "name": "type", - "in": "query", - "schema": { - "type": "string" - } - } - ], - "responses": { - "200": { - "description": "OK", - "content": { - "text/plain": { - "schema": { - "$ref": "#/components/schemas/IsNewFirmwareAvailableResponse" - } - }, - "application/json": { - "schema": { - "$ref": "#/components/schemas/IsNewFirmwareAvailableResponse" - } - }, - "text/json": { - "schema": { - "$ref": "#/components/schemas/IsNewFirmwareAvailableResponse" - } - } - } - } - } - } - }, - "/YamahaExtendedControl/v1/system/getFuncStatus": { - "get": { - "tags": [ - "System" - ], - "responses": { - "200": { - "description": "OK", - "content": { - "text/plain": { - "schema": { - "$ref": "#/components/schemas/GetFuncStatusResponse" - } - }, - "application/json": { - "schema": { - "$ref": "#/components/schemas/GetFuncStatusResponse" - } - }, - "text/json": { - "schema": { - "$ref": "#/components/schemas/GetFuncStatusResponse" - } - } - } - } - } - } - }, - "/YamahaExtendedControl/v1/system/getDisklavierSettings": { - "get": { - "tags": [ - "System" - ], - "responses": { - "200": { - "description": "OK", - "content": { - "text/plain": { - "schema": { - "$ref": "#/components/schemas/GetDisklavierSettingsResponse" - } - }, - "application/json": { - "schema": { - "$ref": "#/components/schemas/GetDisklavierSettingsResponse" - } - }, - "text/json": { - "schema": { - "$ref": "#/components/schemas/GetDisklavierSettingsResponse" - } - } - } - } - } - } - }, - "/YamahaExtendedControl/v1/system/getTag": { - "get": { - "tags": [ - "System" - ], - "responses": { - "200": { - "description": "OK", - "content": { - "text/plain": { - "schema": { - "$ref": "#/components/schemas/GetTagResponse" - } - }, - "application/json": { - "schema": { - "$ref": "#/components/schemas/GetTagResponse" - } - }, - "text/json": { - "schema": { - "$ref": "#/components/schemas/GetTagResponse" - } - } - } - } - } - } - }, - "/YamahaExtendedControl/v1/system/getYpaoConfig": { - "get": { - "tags": [ - "System" - ], - "responses": { - "200": { - "description": "OK", - "content": { - "text/plain": { - "schema": { - "$ref": "#/components/schemas/GetYpaoConfigResponse" - } - }, - "application/json": { - "schema": { - "$ref": "#/components/schemas/GetYpaoConfigResponse" - } - }, - "text/json": { - "schema": { - "$ref": "#/components/schemas/GetYpaoConfigResponse" - } - } - } - } - } - } - }, - "/YamahaExtendedControl/v1/system/setSpeakerA": { - "get": { - "tags": [ - "System" - ], - "parameters": [ - { - "name": "enable", - "in": "query", - "schema": { - "type": "boolean" - } - } - ], - "responses": { - "200": { - "description": "OK", - "content": { - "text/plain": { - "schema": { - "$ref": "#/components/schemas/BaseResponse" - } - }, - "application/json": { - "schema": { - "$ref": "#/components/schemas/BaseResponse" - } - }, - "text/json": { - "schema": { - "$ref": "#/components/schemas/BaseResponse" - } - } - } - } - } - } - }, - "/YamahaExtendedControl/v1/system/setSpeakerB": { - "get": { - "tags": [ - "System" - ], - "parameters": [ - { - "name": "enable", - "in": "query", - "schema": { - "type": "boolean" - } - } - ], - "responses": { - "200": { - "description": "OK", - "content": { - "text/plain": { - "schema": { - "$ref": "#/components/schemas/BaseResponse" - } - }, - "application/json": { - "schema": { - "$ref": "#/components/schemas/BaseResponse" - } - }, - "text/json": { - "schema": { - "$ref": "#/components/schemas/BaseResponse" - } - } - } - } - } - } - }, - "/YamahaExtendedControl/v1/system/getNetworkStandby": { - "get": { - "tags": [ - "System" - ], - "responses": { - "200": { - "description": "OK", - "content": { - "text/plain": { - "schema": { - "$ref": "#/components/schemas/GetNetworkStandbyResponse" - } - }, - "application/json": { - "schema": { - "$ref": "#/components/schemas/GetNetworkStandbyResponse" - } - }, - "text/json": { - "schema": { - "$ref": "#/components/schemas/GetNetworkStandbyResponse" - } - } - } - } - } - } - } - }, - "components": { - "schemas": { - "Audio": { - "type": "object", - "properties": { - "error": { - "type": "integer", - "format": "int32" - }, - "format": { - "type": "string" - }, - "fs": { - "type": "string" - } - } - }, - "BaseResponse": { - "type": "object", - "properties": { - "response_code": { - "type": "string" - } - } - }, - "Ccs": { - "type": "object", - "properties": { - "supported": { - "type": "boolean" - } - } - }, - "Common": { - "type": "object", - "properties": { - "attribute": { - "type": "integer", - "format": "int32" - }, - "swfr_crossover_list": { - "type": "array", - "items": { - "type": "integer", - "format": "int32" - } - }, - "speaker_size": { - "type": "array", - "items": { - "$ref": "#/components/schemas/Speaker_size" - } - } - } - }, - "Disklavier": { - "type": "object", - "properties": { - "ip_address": { - "type": "string" - } - } - }, - "Distribution": { - "type": "object", - "properties": { - "version": { - "type": "integer", - "format": "int32" - }, - "compatible_client": { - "type": "array", - "items": { - "type": "integer", - "format": "int32" - } - }, - "client_max": { - "type": "integer", - "format": "int32" - }, - "server_zone_list": { - "type": "array", - "items": { - "type": "string" - } - } - } - }, - "Front_l": { - "type": "object", - "properties": { - "attribute": { - "type": "integer", - "format": "int32" - }, - "range_step": { - "type": "array", - "items": { - "$ref": "#/components/schemas/Range_step" - } - } - } - }, - "Front_r": { - "type": "object", - "properties": { - "attribute": { - "type": "integer", - "format": "int32" - }, - "range_step": { - "type": "array", - "items": { - "$ref": "#/components/schemas/Range_step1" - } - } - } - }, - "GetDeviceInfoResponse": { - "type": "object", - "properties": { - "response_code": { - "type": "integer", - "format": "int32" - }, - "model_name": { - "type": "string" - }, - "destination": { - "type": "string" - }, - "device_id": { - "type": "string" - }, - "system_id": { - "type": "string" - }, - "system_version": { - "type": "integer", - "format": "int32" - }, - "api_version": { - "type": "number", - "format": "double" - }, - "netmodule_generation": { - "type": "integer", - "format": "int32" - }, - "netmodule_version": { - "type": "string" - }, - "netmodule_checksum": { - "type": "string" - }, - "operation_mode": { - "type": "string" - }, - "update_error_code": { - "type": "string" - } - } - }, - "GetDisklavierSettingsResponse": { - "type": "object", - "properties": { - "response_code": { - "type": "integer", - "format": "int32" - }, - "enable": { - "type": "boolean" - }, - "mode": { - "type": "string" - }, - "input": { - "type": "string" - }, - "pair": { - "$ref": "#/components/schemas/Pair" - }, - "disklavier": { - "$ref": "#/components/schemas/Disklavier" - } - } - }, - "GetDistributionInfoResponse": { - "type": "object", - "properties": { - "response_code": { - "type": "integer", - "format": "int32" - }, - "group_id": { - "type": "string" - }, - "group_name": { - "type": "string" - }, - "role": { - "type": "string" - }, - "server_zone": { - "type": "string" - }, - "client_list": { - "type": "array" - } - } - }, - "GetFeaturesResponse": { - "type": "object", - "properties": { - "response_code": { - "type": "integer", - "format": "int32" - }, - "system": { - "$ref": "#/components/schemas/System" - }, - "zone": { - "type": "array", - "items": { - "$ref": "#/components/schemas/Zone" - } - }, - "tuner": { - "$ref": "#/components/schemas/Tuner" - }, - "netusb": { - "$ref": "#/components/schemas/Netusb" - }, - "distribution": { - "$ref": "#/components/schemas/Distribution" - }, - "ccs": { - "$ref": "#/components/schemas/Ccs" - } - } - }, - "GetFuncStatusResponse": { - "type": "object", - "properties": { - "response_code": { - "type": "integer", - "format": "int32" - }, - "auto_power_standby": { - "type": "boolean" - }, - "speaker_a": { - "type": "boolean" - }, - "speaker_b": { - "type": "boolean" - }, - "headphone": { - "type": "boolean" - } - } - }, - "GetListInfoResponse": { - "type": "object", - "properties": { - "response_code": { - "type": "integer", - "format": "int32" - }, - "input": { - "type": "string" - }, - "menu_layer": { - "type": "integer", - "format": "int32" - }, - "max_line": { - "type": "integer", - "format": "int32" - }, - "index": { - "type": "integer", - "format": "int32" - }, - "playing_index": { - "type": "integer", - "format": "int32" - }, - "menu_name": { - "type": "string" - }, - "list_info": { - "type": "array", - "items": { - "$ref": "#/components/schemas/List_info" - } - } - } - }, - "GetLocationInfoResponse": { - "type": "object", - "properties": { - "response_code": { - "type": "integer", - "format": "int32" - }, - "id": { - "type": "string" - }, - "name": { - "type": "string" - }, - "zone_list": { - "$ref": "#/components/schemas/Zone_list" - } - } - }, - "GetMcPlaylistNameResponse": { - "type": "object", - "properties": { - "response_code": { - "type": "integer", - "format": "int32" - }, - "name_list": { - "type": "array", - "items": { - "type": "string" - } - } - } - }, - "GetNameTextResponse": { - "type": "object", - "properties": { - "response_code": { - "type": "integer", - "format": "int32" - }, - "zone_list": { - "type": "array", - "items": { - "$ref": "#/components/schemas/Zone_list2" - } - }, - "input_list": { - "type": "array", - "items": { - "$ref": "#/components/schemas/Input_list2" - } - }, - "sound_program_list": { - "type": "array" - } - } - }, - "GetNetworkStandbyResponse": { - "type": "object", - "properties": { - "response_code": { - "type": "integer", - "format": "int32" - }, - "network_standby": { - "type": "string" - } - } - }, - "GetPlayInfoResponse": { - "type": "object", - "properties": { - "response_code": { - "type": "integer", - "format": "int32" - }, - "input": { - "type": "string" - }, - "play_queue_type": { - "type": "string" - }, - "playback": { - "type": "string" - }, - "repeat": { - "type": "string" - }, - "shuffle": { - "type": "string" - }, - "play_time": { - "type": "integer", - "format": "int32" - }, - "total_time": { - "type": "integer", - "format": "int32" - }, - "artist": { - "type": "string" - }, - "album": { - "type": "string" - }, - "track": { - "type": "string" - }, - "albumart_url": { - "type": "string" - }, - "albumart_id": { - "type": "integer", - "format": "int32" - }, - "usb_devicetype": { - "type": "string" - }, - "auto_stopped": { - "type": "boolean" - }, - "attribute": { - "type": "integer", - "format": "int32" - }, - "repeat_available": { - "type": "array", - "items": { - "type": "string" - } - }, - "shuffle_available": { - "type": "array", - "items": { - "type": "string" - } - } - } - }, - "GetPlayQueueResponse": { - "type": "object", - "properties": { - "response_code": { - "type": "integer", - "format": "int32" - }, - "type": { - "type": "string" - }, - "max_line": { - "type": "integer", - "format": "int32" - }, - "playing_index": { - "type": "integer", - "format": "int32" - }, - "index": { - "type": "integer", - "format": "int32" - }, - "track_info": { - "type": "array", - "items": { - "$ref": "#/components/schemas/Track_info" - } - } - } - }, - "GetRecentInfoResponse": { - "type": "object", - "properties": { - "response_code": { - "type": "integer", - "format": "int32" - }, - "recent_info": { - "type": "array", - "items": { - "$ref": "#/components/schemas/Recent_info" - } - } - } - }, - "GetSignalInfoResponse": { - "type": "object", - "properties": { - "response_code": { - "type": "integer", - "format": "int32" - }, - "audio": { - "$ref": "#/components/schemas/Audio" - } - } - }, - "GetStatusResponse": { - "type": "object", - "properties": { - "response_code": { - "type": "integer", - "format": "int32" - }, - "power": { - "type": "string" - }, - "sleep": { - "type": "integer", - "format": "int32" - }, - "volume": { - "type": "integer", - "format": "int32" - }, - "mute": { - "type": "boolean" - }, - "max_volume": { - "type": "integer", - "format": "int32" - }, - "input": { - "type": "string" - }, - "distribution_enable": { - "type": "boolean" - }, - "link_control": { - "type": "string" - }, - "link_audio_delay": { - "type": "string" - }, - "link_audio_quality": { - "type": "string" - }, - "disable_flags": { - "type": "integer", - "format": "int32" - } - } - }, - "GetStreamingServiceSettingsResponse": { - "type": "object", - "properties": { - "response_code": { - "type": "integer", - "format": "int32" - }, - "services": { - "type": "array", - "items": { - "$ref": "#/components/schemas/Services" - } - } - } - }, - "GetTagResponse": { - "type": "object", - "properties": { - "response_code": { - "type": "integer", - "format": "int32" - }, - "zone_list": { - "type": "array", - "items": { - "$ref": "#/components/schemas/Zone_list3" - } - }, - "input_list": { - "type": "array", - "items": { - "$ref": "#/components/schemas/Input_list3" - } - } - } - }, - "GetYpaoConfigResponse": { - "type": "object", - "properties": { - "response_code": { - "type": "integer", - "format": "int32" - }, - "ypao_status": { - "type": "string" - }, - "ypao_setting": { - "type": "boolean" - }, - "ypao_speaker_unit": { - "type": "string" - }, - "ypao_volume": { - "type": "boolean" - }, - "disable_flags": { - "type": "integer", - "format": "int32" - } - } - }, - "Input_list": { - "type": "object", - "properties": { - "id": { - "type": "string" - }, - "distribution_enable": { - "type": "boolean" - }, - "rename_enable": { - "type": "boolean" - }, - "account_enable": { - "type": "boolean" - }, - "play_info_type": { - "type": "string" - } - } - }, - "Input_list2": { - "type": "object", - "properties": { - "id": { - "type": "string" - }, - "text": { - "type": "string" - } - } - }, - "Input_list3": { - "type": "object", - "properties": { - "id": { - "type": "string" - }, - "tag": { - "type": "integer", - "format": "int32" - } - } - }, - "IsNewFirmwareAvailableResponse": { - "type": "object", - "properties": { - "response_code": { - "type": "integer", - "format": "int32" - }, - "available": { - "type": "boolean" - } - } - }, - "List_info": { - "type": "object", - "properties": { - "text": { - "type": "string" - }, - "subtexts": { - "type": "array" - }, - "thumbnail": { - "type": "string" - }, - "logo": { - "type": "string" - }, - "attribute": { - "type": "integer", - "format": "int32" - } - } - }, - "Mc_playlist": { - "type": "object", - "properties": { - "size": { - "type": "integer", - "format": "int32" - }, - "num": { - "type": "integer", - "format": "int32" - } - } - }, - "Netusb": { - "type": "object", - "properties": { - "func_list": { - "type": "array", - "items": { - "type": "string" - } - }, - "preset": { - "$ref": "#/components/schemas/Preset1" - }, - "recent_info": { - "$ref": "#/components/schemas/Recent_info2" - }, - "play_queue": { - "$ref": "#/components/schemas/Play_queue" - }, - "mc_playlist": { - "$ref": "#/components/schemas/Mc_playlist" - }, - "net_radio_type": { - "type": "string" - }, - "pandora": { - "$ref": "#/components/schemas/Pandora" - }, - "siriusxm": { - "$ref": "#/components/schemas/Siriusxm" - } - } - }, - "Pair": { - "type": "object", - "properties": { - "mac_address": { - "type": "string" - } - } - }, - "Pandora": { - "type": "object", - "properties": { - "sort_option_list": { - "type": "array", - "items": { - "type": "string" - } - } - } - }, - "Play_queue": { - "type": "object", - "properties": { - "size": { - "type": "integer", - "format": "int32" - } - } - }, - "Preset": { - "type": "object", - "properties": { - "type": { - "type": "string" - }, - "num": { - "type": "integer", - "format": "int32" - } - } - }, - "Preset1": { - "type": "object", - "properties": { - "num": { - "type": "integer", - "format": "int32" - } - } - }, - "Range_step": { - "type": "object", - "properties": { - "id": { - "type": "string" - }, - "min": { - "type": "integer", - "format": "int32" - }, - "max": { - "type": "integer", - "format": "int32" - }, - "step": { - "type": "integer", - "format": "int32" - } - } - }, - "Range_step1": { - "type": "object", - "properties": { - "id": { - "type": "string" - }, - "min": { - "type": "integer", - "format": "int32" - }, - "max": { - "type": "integer", - "format": "int32" - }, - "step": { - "type": "integer", - "format": "int32" - } - } - }, - "Range_step2": { - "type": "object", - "properties": { - "id": { - "type": "string" - }, - "min": { - "type": "integer", - "format": "int32" - }, - "max": { - "type": "integer", - "format": "int32" - }, - "step": { - "type": "integer", - "format": "int32" - } - } - }, - "Range_step3": { - "type": "object", - "properties": { - "id": { - "type": "string" - }, - "min": { - "type": "integer", - "format": "int32" - }, - "max": { - "type": "integer", - "format": "int32" - }, - "step": { - "type": "integer", - "format": "int32" - } - } - }, - "Range_step4": { - "type": "object", - "properties": { - "id": { - "type": "string" - }, - "min": { - "type": "integer", - "format": "int32" - }, - "max": { - "type": "integer", - "format": "int32" - }, - "step": { - "type": "integer", - "format": "int32" - } - } - }, - "Recent_info": { - "type": "object", - "properties": { - "input": { - "type": "string" - }, - "text": { - "type": "string" - }, - "albumart_url": { - "type": "string" - }, - "play_count": { - "type": "integer", - "format": "int32" - }, - "attribute": { - "type": "integer", - "format": "int32" - } - } - }, - "Recent_info2": { - "type": "object", - "properties": { - "num": { - "type": "integer", - "format": "int32" - } - } - }, - "Services": { - "type": "object", - "properties": { - "input": { - "type": "string" - }, - "confirmed": { - "type": "boolean" - }, - "use_service": { - "type": "boolean" - } - } - }, - "Siriusxm": { - "type": "object", - "properties": { - "api_type": { - "type": "string" - } - } - }, - "Speaker_settings": { - "type": "object", - "properties": { - "type": { - "type": "string" - }, - "common": { - "$ref": "#/components/schemas/Common" - }, - "front_l": { - "$ref": "#/components/schemas/Front_l" - }, - "front_r": { - "$ref": "#/components/schemas/Front_r" - }, - "swfr": { - "$ref": "#/components/schemas/Swfr" - } - } - }, - "Speaker_size": { - "type": "object", - "properties": { - "id": { - "type": "string" - }, - "size_list": { - "type": "array", - "items": { - "type": "string" - } - } - } - }, - "Swfr": { - "type": "object", - "properties": { - "attribute": { - "type": "integer", - "format": "int32" - }, - "range_step": { - "type": "array", - "items": { - "$ref": "#/components/schemas/Range_step2" - } - } - } - }, - "System": { - "type": "object", - "properties": { - "func_list": { - "type": "array", - "items": { - "type": "string" - } - }, - "zone_num": { - "type": "integer", - "format": "int32" - }, - "input_list": { - "type": "array", - "items": { - "$ref": "#/components/schemas/Input_list" - } - }, - "speaker_settings": { - "$ref": "#/components/schemas/Speaker_settings" - }, - "ypao_speaker_unit_list": { - "type": "array", - "items": { - "type": "string" - } - } - } - }, - "Track_info": { - "type": "object", - "properties": { - "input": { - "type": "string" - }, - "text": { - "type": "string" - }, - "thumbnail": { - "type": "string" - }, - "attribute": { - "type": "integer", - "format": "int32" - } - } - }, - "Tuner": { - "type": "object", - "properties": { - "func_list": { - "type": "array", - "items": { - "type": "string" - } - }, - "range_step": { - "type": "array", - "items": { - "$ref": "#/components/schemas/Range_step4" - } - }, - "preset": { - "$ref": "#/components/schemas/Preset" - } - } - }, - "Zone": { - "type": "object", - "properties": { - "id": { - "type": "string" - }, - "func_list": { - "type": "array", - "items": { - "type": "string" - } - }, - "input_list": { - "type": "array", - "items": { - "type": "string" - } - }, - "link_control_list": { - "type": "array", - "items": { - "type": "string" - } - }, - "link_audio_delay_list": { - "type": "array", - "items": { - "type": "string" - } - }, - "link_audio_quality_list": { - "type": "array", - "items": { - "type": "string" - } - }, - "range_step": { - "type": "array", - "items": { - "$ref": "#/components/schemas/Range_step3" - } - } - } - }, - "Zone_list": { - "type": "object", - "properties": { - "main": { - "type": "boolean" - } - } - }, - "Zone_list2": { - "type": "object", - "properties": { - "id": { - "type": "string" - }, - "text": { - "type": "string" - } - } - }, - "Zone_list3": { - "type": "object", - "properties": { - "id": { - "type": "string" - }, - "tag": { - "type": "integer", - "format": "int32" - } - } - } - } - }, - "tags": [ - { - "name": "Dist" - }, - { - "name": "Main" - }, - { - "name": "NetUsb" - }, - { - "name": "System" - } - ] -} \ No newline at end of file diff --git a/MusicCast.Net.Api.Client/generate.fish b/MusicCast.Net.Api.Client/generate.fish index b8b4048..eb940bf 100644 --- a/MusicCast.Net.Api.Client/generate.fish +++ b/MusicCast.Net.Api.Client/generate.fish @@ -1,3 +1,3 @@ #!/usr/bin/fish -kiota.exe generate -l Csharp -c MusicCastApiClient -n MusicCast.Net.Api.Client -d MusicCast.Net.Api.Server.json -o . --exclude-backward-compatible +kiota.exe generate -l Csharp -c MusicCastApiClient -n MusicCast.Net.Api.Client -d ../MusicCast.Net.Api.Server/MusicCast.Net.Api.Server.json -o . --exclude-backward-compatible diff --git a/MusicCast.Net.Api.Client/kiota-lock.json b/MusicCast.Net.Api.Client/kiota-lock.json index 2a5c12f..5c62359 100644 --- a/MusicCast.Net.Api.Client/kiota-lock.json +++ b/MusicCast.Net.Api.Client/kiota-lock.json @@ -1,6 +1,6 @@ { - "descriptionHash": "C948E365F06EF135D929D78013E8AA08B1DD90FE86A80A3C7F3495672B6F1C32F98B1AAA7F84A151FAB4B0B8D12DB49F46CCCA14DE96A06143E25983F49846AA", - "descriptionLocation": "MusicCast.Net.Api.Server.json", + "descriptionHash": "54CA7AB3C7F7B94748F3D15ED096DB34D3A70EA1BC52DF9436D08BC31C7CCCFAC79F1FE2861D190E1915FE1C3C4036BDF1A1D6FB1CBACED8866663BC9D708742", + "descriptionLocation": "../MusicCast.Net.Api.Server/MusicCast.Net.Api.Server.json", "lockFileVersion": "1.0.0", "kiotaVersion": "1.26.1", "clientClassName": "MusicCastApiClient", diff --git a/MusicCast.Net.Api.Server/Models/BaseResponse.cs b/MusicCast.Net.Api.Server/Models/BaseResponse.cs index ee0a012..87e47e6 100644 --- a/MusicCast.Net.Api.Server/Models/BaseResponse.cs +++ b/MusicCast.Net.Api.Server/Models/BaseResponse.cs @@ -2,5 +2,5 @@ namespace MusicCast.Net.Api.Server.Models; public class BaseResponse { - public string response_code { get; set; } + public int response_code { get; set; } } \ No newline at end of file diff --git a/MusicCast.Net.Api.Server/MusicCast.Net.Api.Server.json b/MusicCast.Net.Api.Server/MusicCast.Net.Api.Server.json index c4d4dc8..264fb90 100644 --- a/MusicCast.Net.Api.Server/MusicCast.Net.Api.Server.json +++ b/MusicCast.Net.Api.Server/MusicCast.Net.Api.Server.json @@ -1320,7 +1320,8 @@ "type": "object", "properties": { "response_code": { - "type": "string" + "type": "integer", + "format": "int32" } } }, diff --git a/MusicCast.Net.Client/MusicCast.Net.Client.csproj b/MusicCast.Net.Client/MusicCast.Net.Client.csproj index b1fdc03..ceba503 100644 --- a/MusicCast.Net.Client/MusicCast.Net.Client.csproj +++ b/MusicCast.Net.Client/MusicCast.Net.Client.csproj @@ -7,7 +7,11 @@ - + + + + + diff --git a/MusicCast.Net.Client/MusicCastClient.cs b/MusicCast.Net.Client/MusicCastClient.cs new file mode 100644 index 0000000..29c354e --- /dev/null +++ b/MusicCast.Net.Client/MusicCastClient.cs @@ -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 PowerOn() + { + var response = await _apiClient.YamahaExtendedControl.V1.Main.SetPower.GetAsync(r => + r.QueryParameters.Power = GetPowerQueryParameterType.On + ); + + return IsSuccess(response); + } + + public async Task 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(); + } +} \ No newline at end of file diff --git a/MusicCast.Net.Client/MusicCastDiscoveryService.cs b/MusicCast.Net.Client/MusicCastDiscoveryService.cs new file mode 100644 index 0000000..95db913 --- /dev/null +++ b/MusicCast.Net.Client/MusicCastDiscoveryService.cs @@ -0,0 +1,162 @@ +using System.Net; +using System.Net.NetworkInformation; +using System.Net.Sockets; +using System.Text; +using System.Text.RegularExpressions; +using System.Xml; +using System.Xml.Linq; +using System.Xml.XPath; + +namespace MusicCast.Net.Client; + +public partial class MusicCastDiscoveryService +{ + private static readonly byte[] MulticastPacket = """ + M-SEARCH * HTTP/1.1 + HOST: 239.255.255.250:1900 + MAN: "ssdp:discover" + ST: urn:schemas-upnp-org:device:MediaRenderer:1 + MX: 1 + + + """u8.ToArray(); + + private static readonly HttpClient _httpClient = new(); + + private const string LocationUrlGroupName = "url"; + [GeneratedRegex(@$"Location:\s(?<{LocationUrlGroupName}>http[s]?:\/\/.+\.xml)", RegexOptions.IgnoreCase)] + private static partial Regex LocationRegex(); + + /// + /// Get the ip address associated with the current local network. + /// If multiple networks cards are installed it only returns the first one. + /// + /// + public IPAddress? GetLocalSubnetAddress() + { + // Get a list of all network interfaces (usually one per network card, dialup, and VPN connection) + var networkInterfaces = NetworkInterface.GetAllNetworkInterfaces(); + + foreach (NetworkInterface network in networkInterfaces) + { + // Read the IP configuration for each network + IPInterfaceProperties properties = network.GetIPProperties(); + + if (network.NetworkInterfaceType is NetworkInterfaceType.Ethernet or NetworkInterfaceType.Wireless80211 && + network.OperationalStatus == OperationalStatus.Up && + !network.Description.Contains("virtual", StringComparison.OrdinalIgnoreCase) && + !network.Description.Contains("pseudo", StringComparison.OrdinalIgnoreCase)) + { + // Each network interface may have multiple IP addresses + foreach (UnicastIPAddressInformation address in properties.UnicastAddresses) + { + // We're only interested in IPv4 addresses for now + if (address.Address.AddressFamily != AddressFamily.InterNetwork) + continue; + + // Ignore loopback addresses (e.g., 127.0.0.1) + if (IPAddress.IsLoopback(address.Address)) + continue; + + return address.Address; + } + } + } + + return null; + } + + public Task> GetMusicCastDeviceAddresses(IPAddress bindAddress) + => GetMusicCastDeviceAddresses(bindAddress, TimeSpan.FromSeconds(2)); + + /// + /// Scan for MusicCast devices on the network associated with the bind address. Only return devices that support + /// the YamahaExtendedControl v1 api + /// + /// + /// Duration of the scan + /// + public async Task> GetMusicCastDeviceAddresses(IPAddress bindAddress, TimeSpan scanDuration) + { + using var client = new UdpClient(AddressFamily.InterNetwork); + + client.Client.Bind(new IPEndPoint(bindAddress, 0)); + client.JoinMulticastGroup(IPAddress.Parse("239.255.255.250")); + + await client.SendAsync(MulticastPacket, "239.255.255.250", 1900); + await client.SendAsync(MulticastPacket, "239.255.255.250", 1900); + await client.SendAsync(MulticastPacket, "239.255.255.250", 1900); + + var musicCastDevices = new HashSet(); + + // Start scanning + var cancellationToken = new CancellationTokenSource(scanDuration).Token; + + try + { + while (!cancellationToken.IsCancellationRequested) + { + var received = await client.ReceiveAsync(cancellationToken); + var message = Encoding.UTF8.GetString(received.Buffer); + + // Try to find the location of the DLNA description file + var match = LocationRegex().Match(message); + + if (!match.Success || !match.Groups.TryGetValue(LocationUrlGroupName, out var group)) + { + continue; + } + + var location = group.Value; + + var apiUrl = await GetApiUrlFromDlnaDescriptionFile(location, cancellationToken); + + if (apiUrl is not null) + { + musicCastDevices.Add(apiUrl); + } + } + } + catch (OperationCanceledException) + { + // Normal flow after scan duration + } + + return musicCastDevices; + } + + private static async Task GetApiUrlFromDlnaDescriptionFile(string location, CancellationToken cancellationToken) + { + try + { + var response = await _httpClient.GetAsync(location, cancellationToken); + await using var descriptionFileStream = await response.Content.ReadAsStreamAsync(cancellationToken); + + var document = await XDocument.LoadAsync(descriptionFileStream, LoadOptions.None, cancellationToken); + XNamespace yamahaNamespace = "urn:schemas-yamaha-com:device-1-0"; + + var urlBaseNode = document.Descendants(yamahaNamespace + "X_URLBase").FirstOrDefault(); + + if (urlBaseNode is null) + { + return null; + } + + var yamahaControlUrlNodes = document.Descendants(yamahaNamespace + "X_yxcControlURL"); + + foreach (var yamahaControlUrlNode in yamahaControlUrlNodes) + { + if (yamahaControlUrlNode is { Value: "/YamahaExtendedControl/v1/" }) + { + return urlBaseNode.Value; + } + } + } + catch (Exception) + { + // ignored + } + + return null; + } +} \ No newline at end of file diff --git a/MusicCast.Net.Test/MusicCast.Net.Test.csproj b/MusicCast.Net.Test/MusicCast.Net.Test.csproj index 2620762..467dc2a 100644 --- a/MusicCast.Net.Test/MusicCast.Net.Test.csproj +++ b/MusicCast.Net.Test/MusicCast.Net.Test.csproj @@ -8,7 +8,7 @@ - + diff --git a/MusicCast.Net.Test/Program.cs b/MusicCast.Net.Test/Program.cs index 6bd39aa..100a4bf 100644 --- a/MusicCast.Net.Test/Program.cs +++ b/MusicCast.Net.Test/Program.cs @@ -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); \ No newline at end of file