Skip to content

Commit b3db576

Browse files
Fix loading root certificate
1 parent 3164587 commit b3db576

3 files changed

Lines changed: 3 additions & 25 deletions

File tree

TgHomeBot.SmartHome.HomeAssistant/CertificateHelper.cs

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,6 @@ internal static class CertificateHelper
66
{
77
internal static X509Certificate2 LoadCertificate(string path)
88
{
9-
const int maxScanLines = 50;
10-
var isPem = false;
11-
12-
using (var reader = new StreamReader(path))
13-
{
14-
string? line;
15-
var linesRead = 0;
16-
17-
while (linesRead < maxScanLines && (line = reader.ReadLine()) is not null)
18-
{
19-
linesRead++;
20-
21-
if (line.Contains("-----BEGIN CERTIFICATE-----", StringComparison.Ordinal))
22-
{
23-
isPem = true;
24-
break;
25-
}
26-
}
27-
}
28-
29-
return isPem
30-
? X509Certificate2.CreateFromPemFile(path)
31-
: X509CertificateLoader.LoadCertificateFromFile(path);
9+
return X509CertificateLoader.LoadCertificateFromFile(path);
3210
}
3311
}

TgHomeBot.SmartHome.HomeAssistant/HomeAssistantConnector.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ private static SmartDevice ConvertDevice(HomeAssistantDevice d, string? name = n
8181
return new SmartDevice
8282
{
8383
Id = d.EntityId,
84-
Name = name ?? d.Attributes.FriendlyName,
84+
Name = name ?? d.Attributes.FriendlyName ?? d.EntityId,
8585
State = string.IsNullOrWhiteSpace(d.Attributes.UnitOfMeasurement) ? d.State : $"{d.State} {d.Attributes.UnitOfMeasurement}"
8686
};
8787
}

TgHomeBot.SmartHome.HomeAssistant/Models/HomeAssistantDeviceAttributes.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@ public class HomeAssistantDeviceAttributes
3232
public string? DeviceClass { get; init; }
3333

3434
[JsonPropertyName("friendly_name")]
35-
public required string FriendlyName { get; init; }
35+
public string? FriendlyName { get; init; }
3636
}

0 commit comments

Comments
 (0)