protected override async Task Initialize( ClientCharacteristicsRequestObject clientCharacteristicsRequestObject = null, CancellationToken cancellationToken = default) { await base.Initialize(clientCharacteristicsRequestObject, cancellationToken); if (!HttpClient.DefaultRequestHeaders.Contains(AUTHTOKEN)) { HttpClient.DefaultRequestHeaders.Add(AUTHTOKEN, HomematicConfiguration.AuthToken); } _clientWebSocket.Options.SetRequestHeader(AUTHTOKEN, HomematicConfiguration.AuthToken); _clientWebSocket.Options.SetRequestHeader(CLIENTAUTH, ClientAuthToken); }
protected virtual async Task Initialize(ClientCharacteristicsRequestObject clientCharacteristicsRequestObject = null, CancellationToken cancellationToken = default) { if (clientCharacteristicsRequestObject == null) { clientCharacteristicsRequestObject = new ClientCharacteristicsRequestObject(HomematicConfiguration.AccessPointId, _clientCharacteristics); } ClientCharacteristicsStringContent = GetStringContent(clientCharacteristicsRequestObject); var httpResponseMessage = await HttpClient.PostAsync("https://lookup.homematic.com:48335/getHost", ClientCharacteristicsStringContent, cancellationToken); RestAndWebSocketUrls restAndWebSocketUrls; if (httpResponseMessage.IsSuccessStatusCode) { var content = await httpResponseMessage.Content.ReadAsStringAsync(); restAndWebSocketUrls = JsonConvert.DeserializeObject <RestAndWebSocketUrls>(content); } else { if ((int)httpResponseMessage.StatusCode == 418) //I'm a teapot message { throw new ArgumentException($"It is highly likely that you accidentally mistyped your access point id."); } throw new Exception($"Error looking up the host: {httpResponseMessage.StatusCode}, {httpResponseMessage.ReasonPhrase}"); } HttpClient = HttpClientFactory(); HttpClient.BaseAddress = new Uri($"{restAndWebSocketUrls.UrlREST}/"); if (!HttpClient.DefaultRequestHeaders.Contains("VERSION")) { HttpClient.DefaultRequestHeaders.Add("VERSION", "12"); } if (!HttpClient.DefaultRequestHeaders.Contains(CLIENTAUTH)) { HttpClient.DefaultRequestHeaders.Add(CLIENTAUTH, ClientAuthToken); } UrlWebSocket = restAndWebSocketUrls.UrlWebSocket; }