File tree Expand file tree Collapse file tree
TgHomeBot.SmartHome.HomeAssistant Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -27,7 +27,7 @@ public class HomeAssistantMonitor(
2727 private readonly CancellationTokenSource _cancellationTokenSource = new ( ) ;
2828 private readonly X509Certificate2 ? _caCertificate = string . IsNullOrEmpty ( options . Value . CertificateAuthorityPath )
2929 ? null
30- : X509CertificateLoader . LoadCertificateFromFile ( options . Value . CertificateAuthorityPath ) ;
30+ : LoadCertificate ( options . Value . CertificateAuthorityPath ) ;
3131
3232 private bool _reconnect ;
3333
@@ -276,6 +276,15 @@ private async Task ProcessEvent(string message)
276276 }
277277 }
278278
279+ private static X509Certificate2 LoadCertificate ( string path )
280+ {
281+ using var reader = new StreamReader ( path ) ;
282+ var firstLine = reader . ReadLine ( ) ;
283+ return firstLine ? . Contains ( "-----BEGIN CERTIFICATE-----" ) == true
284+ ? X509Certificate2 . CreateFromPemFile ( path )
285+ : X509CertificateLoader . LoadCertificateFromFile ( path ) ;
286+ }
287+
279288 private static DeviceState GetState ( DeviceStateThresholds deviceThresholds , string state )
280289 {
281290 if ( ! float . TryParse ( state , out var value ) )
You can’t perform that action at this time.
0 commit comments