Skip to content

Commit cbc03fe

Browse files
committed
don't show blood sugar or temperature if not in the config
1 parent 0e0b171 commit cbc03fe

4 files changed

Lines changed: 40 additions & 10 deletions

File tree

HomeSpeaker.Server2/Program.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,11 @@
103103
app.MapGrpcService<GreeterService>();
104104
app.MapGrpcService<HomeSpeakerService>();
105105
app.MapGet("/ns", (IConfiguration config) => config["NIGHTSCOUT_URL"] ?? string.Empty);
106+
app.MapGet("/api/features", (IConfiguration config) => new
107+
{
108+
TemperatureEnabled = !string.IsNullOrEmpty(config["Temperature:ApiBaseUrl"]),
109+
BloodSugarEnabled = !string.IsNullOrEmpty(config["NIGHTSCOUT_URL"])
110+
});
106111

107112
// Temperature API endpoint
108113
app.MapGet("/api/temperature", async (TemperatureService temperatureService, CancellationToken cancellationToken) =>

HomeSpeaker.Server2/appsettings.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
"OTEL_EXPORTER_OTLP_PROTOCOL": "grpc",
1313
"OTEL_EXPORTER_OTLP_ENDPOINT": "http://localhost:4317",
1414
"Temperature": {
15-
"ApiBaseUrl": "https://openapi.api.govee.com/router/api/v1/"
15+
"ApiBaseUrl": ""
1616
},
1717
"TemperatureThreshold": 2,
18-
"NIGHTSCOUT_URL": "https://janedoe.azurewebsites.net"
18+
"NIGHTSCOUT_URL": ""
1919
}

HomeSpeaker.WebAssembly/Pages/Index.razor

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,26 @@
11
@page "/"
22
@inject HomeSpeakerService svc;
33
@inject ILogger<Index> logger
4+
@inject HttpClient Http
45
@using Microsoft.Fast.Components.FluentUI
56

6-
<div class="row g-2 mb-2">
7-
<div class="col-md-6 col-12">
8-
<TemperatureMonitor />
9-
</div>
10-
<div class="col-md-6 col-12">
11-
<BloodSugarMonitor />
7+
@if (showTemperature || showBloodSugar)
8+
{
9+
<div class="row g-2 mb-2">
10+
@if (showTemperature)
11+
{
12+
<div class="col-md-6 col-12">
13+
<TemperatureMonitor />
14+
</div>
15+
}
16+
@if (showBloodSugar)
17+
{
18+
<div class="col-md-6 col-12">
19+
<BloodSugarMonitor />
20+
</div>
21+
}
1222
</div>
13-
</div>
23+
}
1424

1525
<div class="row">
1626
<div class="col">
@@ -63,6 +73,9 @@ else
6373
private int numPages = 0;
6474
private int artistCount;
6575
private string? filterValue;
76+
private bool showTemperature;
77+
private bool showBloodSugar;
78+
6679
public string? FilterValue
6780
{
6881
get => filterValue;
@@ -79,9 +92,21 @@ else
7992

8093
protected override async Task OnInitializedAsync()
8194
{
95+
try
96+
{
97+
var features = await Http.GetFromJsonAsync<FeaturesResponse>("/api/features");
98+
showTemperature = features?.TemperatureEnabled ?? false;
99+
showBloodSugar = features?.BloodSugarEnabled ?? false;
100+
}
101+
catch (Exception ex)
102+
{
103+
logger.LogWarning(ex, "Failed to load feature flags");
104+
}
82105
await reloadSongsAsync();
83106
}
84107

108+
private record FeaturesResponse(bool TemperatureEnabled, bool BloodSugarEnabled);
109+
85110
async Task reloadSongsAsync()
86111
{
87112
songs = null;

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
You have to create a certificate on the host machine
1212

1313
```bash
14-
dotnet dev-certs https -ep %USERPROFILE%\.aspnet\https\aspnetapp.pfx -p $CREDENTIAL_PLACEHOLDER$
14+
dotnet dev-certs https -ep %USERPROFILE%/.aspnet/https/aspnetapp.pfx -p $CREDENTIAL_PLACEHOLDER$
1515
dotnet dev-certs https --trust
1616
```
1717

0 commit comments

Comments
 (0)