Skip to content

Commit

Permalink
Fixes some new analyzer warnings MS added
Browse files Browse the repository at this point in the history
  • Loading branch information
i8beef committed May 27, 2023
1 parent caec413 commit f45b883
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void CanAddItem()
var device = DeviceTestData.FullDevice();

var expectedAddedTopics = device.Traits
.SelectMany(trait => trait.State)
.SelectMany(trait => trait.State!)
.Where(x => x.Value.Topic != null)
.Select(x => x.Value.Topic);

Expand Down Expand Up @@ -86,13 +86,13 @@ public void CanUpdateItem()
var device = DeviceTestData.FullDevice2();

var expectedDeletedTopics = oldDevice.Traits
.SelectMany(trait => trait.State)
.SelectMany(trait => trait.State!)
.Where(x => x.Value.Topic != null)
.Select(x => x.Value.Topic)
.ToList();

var expectedAddedTopics = device.Traits
.SelectMany(trait => trait.State)
.SelectMany(trait => trait.State!)
.Where(x => x.Value.Topic is not null)
.Select(x => x.Value.Topic);

Expand Down Expand Up @@ -130,7 +130,7 @@ public void CanDeleteItem()
var repository = new GoogleDeviceRepository(_logMock.Object, _messageHubMock.Object, _testFilePath);
var device = repository.FindById(DeviceTestData.FullDevice2().Id);
var expectedDeletedTopics = device!.Traits
.SelectMany(trait => trait.State)
.SelectMany(trait => trait.State!)
.Where(x => x.Value.Topic != null)
.Select(x => x.Value.Topic);

Expand Down
6 changes: 1 addition & 5 deletions src/HomeAutio.Mqtt.GoogleHome/GoogleDeviceRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,7 @@ public IList<Device> GetAll()
/// <inheritdoc />
public Device GetDetached(string deviceId)
{
var device = FindById(deviceId);
if (device is null)
{
throw new InvalidOperationException($"Device id {deviceId} not found");
}
var device = FindById(deviceId) ?? throw new InvalidOperationException($"Device id {deviceId} not found");

return JsonConvert.DeserializeObject<Device>(JsonConvert.SerializeObject(device))!;
}
Expand Down
6 changes: 1 addition & 5 deletions src/HomeAutio.Mqtt.GoogleHome/GoogleHomeGraphClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,7 @@ private async Task<AccessTokenResponse> GetAccessToken()
response.EnsureSuccessStatusCode();

var content = await response.Content.ReadAsStringAsync();
var accessToken = JsonConvert.DeserializeObject<AccessTokenResponse>(content);
if (accessToken is null)
{
throw new GoogleHomeGraphAuthException($"Received malformed access token");
}
var accessToken = JsonConvert.DeserializeObject<AccessTokenResponse>(content) ?? throw new GoogleHomeGraphAuthException($"Received malformed access token");

_log.LogDebug("Received access token");

Expand Down

0 comments on commit f45b883

Please sign in to comment.