Skip to content

Commit bd553d2

Browse files
committed
View config of bridges by IP
1 parent d2a6287 commit bd553d2

File tree

7 files changed

+117
-58
lines changed

7 files changed

+117
-58
lines changed

HueEntertainmentPro/Client/Pages/AddBridgeDialog.razor

Lines changed: 44 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,31 +12,46 @@
1212
<FluentDialog Modal="true" TrapFocus="true" Header="Add Hue Bridge">
1313
<FluentCard>
1414
<FluentStack Orientation="Orientation.Vertical" Style="padding: 16px; min-width: 400px;">
15-
16-
<FluentListbox
17-
Items="@DiscoveredIps"
15+
16+
<FluentCard>
17+
18+
<FluentListbox Items="@DiscoveredIps"
1819
Height="150px"
1920
Label="Discovered IP Addresses"
2021
OptionValue="@(i => i.BridgeId)"
21-
ValueChanged="@(async (string id) => OnBridgeIdSelected(id))">
22-
<OptionTemplate>
23-
@context.IpAddress
24-
</OptionTemplate>
22+
ValueChanged="@(async (string id) => OnBridgeIdSelected(id))">
23+
<OptionTemplate>
24+
@context.IpAddress
25+
</OptionTemplate>
2526
</FluentListbox>
2627

27-
<FluentCheckbox @bind-Value="@EditIp"
28-
Label="Manually enter IP" />
28+
</FluentCard>
29+
30+
31+
<FluentCard>
32+
33+
<FluentCheckbox @bind-Value="@EditIp"
34+
Label="Manually enter IP" />
35+
36+
<FluentTextField Label="IP Address"
37+
@bind-Value="@BridgeConfig.IpAddress"
38+
Placeholder="e.g., 192.168.1.100"
39+
Disabled="@(!EditIp)" />
40+
41+
@if (IsFormValid)
42+
{
43+
<br />
44+
<FluentAnchor Appearance="Appearance.Neutral" Href="@($"/bridge/{BridgeConfig.IpAddress}")" Target="_blank">
45+
View Bridge Config
46+
</FluentAnchor>
47+
}
48+
49+
</FluentCard>
2950

30-
<FluentTextField Label="IP Address"
31-
@bind-Value="@BridgeConfig.IpAddress"
32-
Placeholder="e.g., 192.168.1.100"
33-
Disabled="@(!EditIp)" />
3451

35-
36-
52+
<FluentCard>
3753
<FluentCheckbox @bind-Value="@ShowSecrets"
38-
Label="Manually enter username and key"
39-
/>
54+
Label="Manually enter username and key" />
4055

4156
@if (ShowSecrets)
4257
{
@@ -47,6 +62,8 @@
4762
@bind-Value="@BridgeConfig.StreamingClientKey"
4863
Placeholder="Streaming Client Key" />
4964
}
65+
</FluentCard>
66+
5067

5168
<FluentTextField Label="Name (optional)"
5269
@bind-Value="@BridgeConfig.Name"
@@ -59,6 +76,7 @@
5976

6077
<FluentStack Orientation="Orientation.Horizontal" HorizontalAlignment="HorizontalAlignment.Right" Style="margin-top: 16px;">
6178
<FluentButton Appearance="Appearance.Neutral" OnClick="@CloseDialog">Cancel</FluentButton>
79+
6280
@if (ShowSecrets)
6381
{
6482
<FluentButton Appearance="Appearance.Accent"
@@ -75,7 +93,7 @@
7593
Push Bridge Button and Click Save
7694
</FluentButton>
7795
}
78-
96+
7997
</FluentStack>
8098
</FluentStack>
8199
</FluentCard>
@@ -136,11 +154,11 @@
136154
if (!ShowSecrets)
137155
{
138156
var setup = await HueSetupService.RegisterAsync(new HueLightDJ.Services.Interfaces.Models.Requests.HueSetupRequest
139-
{
140-
Ip = BridgeConfig.IpAddress
141-
});
157+
{
158+
Ip = BridgeConfig.IpAddress
159+
});
142160

143-
if(!string.IsNullOrEmpty(setup?.ErrorMessage))
161+
if (!string.IsNullOrEmpty(setup?.ErrorMessage))
144162
{
145163
ErrorMessage = setup.ErrorMessage;
146164
StateHasChanged();
@@ -169,10 +187,10 @@
169187
try
170188
{
171189
var setup = await HueSetupService.GetEntertainmentGroupsAsync(new HueLightDJ.Services.Interfaces.Models.Requests.HueSetupRequest
172-
{
173-
Ip = BridgeConfig.IpAddress,
174-
Key = BridgeConfig.Username
175-
});
190+
{
191+
Ip = BridgeConfig.IpAddress,
192+
Key = BridgeConfig.Username
193+
});
176194

177195
if (!string.IsNullOrEmpty(setup?.ErrorMessage))
178196
{

HueEntertainmentPro/Client/Pages/BridgeDetail.razor

Lines changed: 53 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
@page "/bridge/{Id:guid}"
2+
@page "/bridge/{*Ip}"
23
@using HueApi.Models.Clip
34
@using HueEntertainmentPro.Client.Services
45
@using HueEntertainmentPro.Client.Shared.ResourceExplorerComponents
@@ -15,6 +16,8 @@
1516
@inject IToastService ToastService
1617
@inject ResourceExplorerService ResourceExplorerService
1718

19+
<PageTitle>Bridge Details</PageTitle>
20+
1821
<h3>Bridge Details</h3>
1922

2023
@if (errorMessage != null)
@@ -54,30 +57,40 @@
5457
<FluentLabel>No entertainment groups found for this bridge.</FluentLabel>
5558
}
5659

57-
<h4 style="margin-top: 20px;">Bridge Config</h4>
58-
<p>
59-
Explore more bridge details on the <a href="/resource-explorer/@Id">Resource Explorer</a>.<br />
60-
View <a href="http://@bridge.Ip/description.xml" target="_blank">description.xml</a>.<br />
61-
</p>
62-
@if (bridgeConfig == null)
63-
{
64-
<FluentProgressRing>Loading bridge config...</FluentProgressRing>
65-
}
66-
else
67-
{
68-
<JsonViewer Element="@JsonSerializer.SerializeToElement(bridgeConfig)" Bridge="@bridge" />
69-
}
7060

61+
}
62+
else if (Id.HasValue)
63+
{
64+
<FluentProgressRing>Loading bridge details...</FluentProgressRing>
65+
}
7166

67+
@if (bridgeConfig == null)
68+
{
69+
<FluentProgressRing>Loading bridge config...</FluentProgressRing>
7270
}
7371
else
7472
{
75-
<FluentProgressRing>Loading bridge details...</FluentProgressRing>
73+
<h4 style="margin-top: 20px;">Bridge Config</h4>
74+
<p>
75+
@if (Id.HasValue)
76+
{
77+
<span>
78+
Explore more bridge details on the <a href="/resource-explorer/@Id">Resource Explorer</a>.
79+
</span>
80+
<br />
81+
}
82+
View <a href="http://@Ip/description.xml" target="_blank">description.xml</a>.<br />
83+
</p>
84+
85+
<JsonViewer Element="@JsonSerializer.SerializeToElement(bridgeConfig)" />
7686
}
7787

7888
@code {
7989
[Parameter]
80-
public Guid Id { get; set; }
90+
public Guid? Id { get; set; }
91+
92+
[Parameter]
93+
public string? Ip { get; set; }
8194

8295
private Bridge? bridge;
8396
private BridgeConfig? bridgeConfig;
@@ -92,23 +105,37 @@ else
92105
entertainmentGroups = null;
93106

94107
// Load bridge details
95-
bridge = await BridgeService.GetBridge(new GuidRequest() { Id = Id });
96-
if (bridge == null)
108+
if (Id.HasValue)
109+
{
110+
bridge = await BridgeService.GetBridge(new GuidRequest() { Id = Id.Value });
111+
Ip = bridge?.Ip;
112+
}
113+
114+
if (bridge == null && Ip == null)
97115
{
98116
errorMessage = "Bridge not found.";
99117
return;
100118
}
101119

102-
var localHueClient = ResourceExplorerService.GetHueClient(bridge);
103-
bridgeConfig = await localHueClient.GetConfigAsync();
104-
105-
// Load entertainment groups
106-
var result = await HueSetupService.GetEntertainmentGroupsAsync(new HueLightDJ.Services.Interfaces.Models.Requests.HueSetupRequest()
120+
if (bridge != null)
107121
{
108-
Ip = bridge.Ip,
109-
Key = bridge.Username
110-
});
111-
entertainmentGroups = result.Groups.AsQueryable();
122+
//TODO: Why does fail when using bridge (which includes key) and returns more data?
123+
var localHueClient = ResourceExplorerService.GetHueClient(bridge.Ip);
124+
bridgeConfig = await localHueClient.GetConfigAsync();
125+
126+
// Load entertainment groups
127+
var result = await HueSetupService.GetEntertainmentGroupsAsync(new HueLightDJ.Services.Interfaces.Models.Requests.HueSetupRequest()
128+
{
129+
Ip = bridge.Ip,
130+
Key = bridge.Username
131+
});
132+
entertainmentGroups = result.Groups.AsQueryable();
133+
}
134+
else if (Ip != null)
135+
{
136+
var localHueClient = ResourceExplorerService.GetHueClient(Ip);
137+
bridgeConfig = await localHueClient.GetConfigAsync();
138+
}
112139
}
113140
catch (Exception ex)
114141
{

HueEntertainmentPro/Client/Pages/ProAreaDetail.razor

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
@inject IDialogService DialogService
1212
@inject IToastService ToastService
1313

14+
<PageTitle>Pro Entertainment Area</PageTitle>
15+
1416
<h3>Pro Entertainment Area</h3>
1517

1618
@if (errorMessage != null)

HueEntertainmentPro/Client/Pages/ProAreaPlay.razor

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
@inject ILightDJService LightDJService
1111
@inject IHubService HubService
1212

13+
<PageTitle>Pro Entertainment Area</PageTitle>
14+
1315
<h3>Pro Entertainment Area</h3>
1416

1517
@if (errorMessage != null)

HueEntertainmentPro/Client/Services/ResourceExplorerService.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,17 @@ public LocalHueApi GetHueClient(Bridge bridge)
1717
return localHueApi;
1818
}
1919

20+
public LocalHueApi GetHueClient(string ip)
21+
{
22+
//Use new HttpClient because setting DangerousAcceptAnyServerCertificateValidator is not supported
23+
var localHueApi = new LocalHueApi(ip, null, new HttpClient());
24+
localHueApi.SetBaseAddress(new Uri($"{NavigationManager.BaseUri}hueproxy/{ip}/"));
25+
26+
// Console.WriteLine("Base URL: " + $"{NavigationManager.BaseUri}/hueproxy/{bridge.Ip}/");
27+
28+
return localHueApi;
29+
}
30+
2031
public string CreateResourceLink(Guid id, string? rtype, Guid? rid = null)
2132
{
2233
if (rtype == null)

HueEntertainmentPro/Client/Shared/ResourceExplorerComponents/JsonViewer.razor

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@
33
@using HueEntertainmentPro.Client.Services
44
@inject ResourceExplorerService ResourceExplorerService
55

6-
<div class="json-node" style="margin-left:@(Level * 10)px">
6+
<div class="json-node json-content" style="margin-left:@(Level * 10)px">
77
@if (!string.IsNullOrEmpty(Key))
88
{
9-
<b>@Key:</b>
9+
<b>@Key: </b>
1010
}
11-
<div class="json-content">
11+
1212
@if (Element.ValueKind == JsonValueKind.Object)
1313
{
1414
// Detect HueResource (must have rid + rtype properties)
1515
if (Element.TryGetProperty("rid", out var ridProp) &&
16-
Element.TryGetProperty("rtype", out var rtypeProp))
16+
Element.TryGetProperty("rtype", out var rtypeProp))
1717
{
1818
// Deserialize into your HueResource type
1919
var resource = Element.Deserialize<ResourceIdentifier>();
@@ -89,7 +89,6 @@
8989
{
9090
<span>null</span>
9191
}
92-
</div>
9392
</div>
9493

9594
@code {

HueEntertainmentPro/Server/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,6 @@
9595

9696
app.MapRazorPages();
9797
app.MapControllers();
98-
app.MapFallbackToFile("index.html");
98+
app.MapFallbackToFile("{**path}", "index.html");
9999

100100
app.Run();

0 commit comments

Comments
 (0)