Skip to content

Commit 840c0aa

Browse files
committed
Code cleanup
1 parent b3ed20c commit 840c0aa

File tree

5 files changed

+36
-33
lines changed

5 files changed

+36
-33
lines changed

HueEntertainmentPro.Services/ProAreaDataService.cs

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using HueEntertainmentPro.Database.Models;
33
using HueEntertainmentPro.Services.Extensions;
44
using HueEntertainmentPro.Shared.Interfaces;
5+
using HueEntertainmentPro.Shared.Models;
56
using HueEntertainmentPro.Shared.Models.Requests;
67
using Microsoft.EntityFrameworkCore;
78
using ProtoBuf.Grpc;
@@ -42,7 +43,12 @@ public class ProAreaDataService(HueEntertainmentProDbContext dbContext) : IProAr
4243

4344
await dbContext.SaveChangesAsync();
4445

45-
return await GetProArea(new GuidRequest { Id = proArea.Id }, context);
46+
var area = await GetProArea(new GuidRequest { Id = proArea.Id }, context);
47+
if (area == null)
48+
{
49+
throw new NullReferenceException($"Area is null. Id: {proArea.Id}");
50+
}
51+
return area;
4652
}
4753

4854
public async Task DeleteBridgeGroup(GuidRequest req, CallContext context = default)
@@ -78,12 +84,17 @@ public async Task DeleteProArea(GuidRequest req, CallContext context = default)
7884
await dbContext.SaveChangesAsync();
7985
}
8086

81-
return await GetProArea(new GuidRequest { Id = req.Id }, context);
87+
var area = await GetProArea(new GuidRequest { Id = req.Id }, context);
88+
if (area == null)
89+
{
90+
throw new NullReferenceException($"Area is null. Id: {req.Id}");
91+
}
92+
return area;
8293
}
8394

8495
public async Task<HueEntertainmentPro.Shared.Models.ProArea> CreateProArea(CreateProAreaRequest req, CallContext context = default)
8596
{
86-
var newArea = new ProArea
97+
var newArea = new Database.Models.ProArea
8798
{
8899
Id = Guid.NewGuid(),
89100
Name = req.Name,
@@ -93,11 +104,16 @@ public async Task DeleteProArea(GuidRequest req, CallContext context = default)
93104
dbContext.ProAreas.Add(newArea);
94105
await dbContext.SaveChangesAsync();
95106

96-
return await GetProArea(new GuidRequest { Id = newArea.Id }, context);
107+
var area = await GetProArea(new GuidRequest { Id = newArea.Id }, context);
108+
if(area == null)
109+
{
110+
throw new NullReferenceException($"Area is null. Id: {newArea.Id}");
111+
}
112+
return area;
97113

98114
}
99115

100-
public async Task<HueEntertainmentPro.Shared.Models.ProArea> GetProArea(GuidRequest req, CallContext context = default)
116+
public async Task<HueEntertainmentPro.Shared.Models.ProArea?> GetProArea(GuidRequest req, CallContext context = default)
101117
{
102118
if (req.Id == demo1Id)
103119
{
@@ -159,8 +175,9 @@ public async Task DeleteProArea(GuidRequest req, CallContext context = default)
159175
var area = await dbContext.ProAreas
160176
.Include(x => x.ProAreaBridgeGroups).ThenInclude(bg => bg.Bridge)
161177
.FirstOrDefaultAsync(pa => pa.Id == req.Id);
178+
162179
if (area == null)
163-
return null!;
180+
return null;
164181

165182
return area.ToApiModel();
166183
}

HueEntertainmentPro/Client/Pages/AddBridgeDialog.razor

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
Height="150px"
1919
Label="Discovered IP Addresses"
2020
OptionValue="@(i => i.BridgeId)"
21-
ValueChanged="@(async (string id) => await OnBridgeIdSelected(id))">
21+
ValueChanged="@(async (string id) => OnBridgeIdSelected(id))">
2222
<OptionTemplate>
2323
@context.IpAddress
2424
</OptionTemplate>
@@ -101,17 +101,6 @@
101101
await DiscoverIps();
102102
}
103103

104-
private async Task OnModeChanged()
105-
{
106-
ErrorMessage = string.Empty;
107-
BridgeConfig = new HueBridgeConfig();
108-
// if (ConfigurationMode == "Discover")
109-
// {
110-
// await DiscoverIps();
111-
// }
112-
StateHasChanged();
113-
}
114-
115104
private async Task DiscoverIps()
116105
{
117106
try
@@ -125,7 +114,7 @@
125114
StateHasChanged();
126115
}
127116

128-
private async Task OnBridgeIdSelected(string bridgeId)
117+
private void OnBridgeIdSelected(string bridgeId)
129118
{
130119
var selected = DiscoveredIps.FirstOrDefault(b => b.BridgeId == bridgeId);
131120
if (selected == null)
@@ -192,7 +181,7 @@
192181
return;
193182
}
194183
}
195-
catch (Exception ex)
184+
catch (Exception)
196185
{
197186
ErrorMessage = "Failed to connect to bridge with the values provided.";
198187
StateHasChanged();

HueEntertainmentPro/Shared/Interfaces/IBridgeDataService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public interface IBridgeDataService
1515
Task<Bridge?> GetBridge(GuidRequest req, CallContext context = default);
1616

1717
[OperationContract]
18-
Task<Bridge?> AddBridge(AddBridgeRequest req, CallContext context = default);
18+
Task<Bridge> AddBridge(AddBridgeRequest req, CallContext context = default);
1919

2020
[OperationContract]
2121
Task<Bridge?> UpdateBridge(UpdateBridgeRequest req, CallContext context = default);

HueLightDJ.Services/HueSetupService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public async Task<EntertainmentGroupResult> GetEntertainmentGroupsAsync(HueSetup
3939
ErrorMessage = "Unauthorized. Please check if your key is correct."
4040
};
4141
}
42-
catch (Exception ex)
42+
catch (Exception)
4343
{
4444
return new EntertainmentGroupResult()
4545
{
@@ -92,7 +92,7 @@ public async Task<IEnumerable<LocatedBridge>> LocateBridgesAsync(CallContext con
9292
ErrorMessage = "Link button not pressed. Please press the link button on the bridge and try again."
9393
};
9494
}
95-
catch(Exception ex)
95+
catch(Exception)
9696
{
9797
return new Interfaces.Models.RegisterEntertainmentResult()
9898
{

HueLightDJ.Services/LightDJService.cs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,26 +66,23 @@ public Task StartGroupEffect(StartEffectRequest request, CallContext context = d
6666
return Task.CompletedTask;
6767
}
6868

69-
public Task IncreaseBPM(IntRequest req, CallContext context = default)
69+
public async Task IncreaseBPM(IntRequest req, CallContext context = default)
7070
{
71-
streamingSetup.IncreaseBPM(req.Value);
72-
return GetStatus();
73-
71+
await streamingSetup.IncreaseBPM(req.Value);
72+
await GetStatus();
7473
}
7574

76-
public Task SetBPM(IntRequest req, CallContext context = default)
75+
public async Task SetBPM(IntRequest req, CallContext context = default)
7776
{
78-
streamingSetup.SetBPM(req.Value);
79-
return GetStatus();
80-
77+
await streamingSetup.SetBPM(req.Value);
78+
await GetStatus();
8179
}
8280

8381
public Task SetBri(DoubleRequest req, CallContext context = default)
8482
{
8583
var filterValue = 100 - req.Value;
8684

87-
streamingSetup.SetBrightnessFilter(filterValue);
88-
return Task.CompletedTask;
85+
return streamingSetup.SetBrightnessFilter(filterValue);
8986
}
9087

9188

0 commit comments

Comments
 (0)