Skip to content

Commit

Permalink
Fixed all Solution warnings and messages
Browse files Browse the repository at this point in the history
  • Loading branch information
hagronnestad committed Sep 14, 2023
1 parent cb4a043 commit d624b5f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
8 changes: 4 additions & 4 deletions Dirigera.Lib/Dirigera.Lib/Api/ApiClient.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Dirigera.Lib.Api.Dto;
using Dirigera.Lib.Api.Dto;
using Dirigera.Lib.Api.Dto.Base;
using System.Net;
using System.Net.Http.Headers;
Expand All @@ -14,7 +14,7 @@ internal class ApiClient
private const string PKCE_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~";

private readonly string _ip;
private string _apiBaseUrl;
private readonly string _apiBaseUrl;
private string? _authToken;

public string? AuthToken
Expand All @@ -29,7 +29,7 @@ public string? AuthToken
}
}

private HttpClient _httpClient;
private readonly HttpClient _httpClient;

public ApiClient(string ip, string? authToken = null)
{
Expand Down Expand Up @@ -81,7 +81,7 @@ public async Task<bool> CheckAuthToken()
return res;
}

public async Task<T> GetDevice<T>(string id)
public async Task<T?> GetDevice<T>(string id)
{
string url = $"{_apiBaseUrl}/devices/{id}";
var res = await _httpClient.GetFromJsonAsync<T>(url);
Expand Down
27 changes: 14 additions & 13 deletions Dirigera.Lib/Dirigera.Lib/DirigeraManager.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Dirigera.Lib.Api;
using Dirigera.Lib.Api;
using Dirigera.Lib.Api.Dto.Base;
using Dirigera.Lib.Constants;
using Dirigera.Lib.Devices;
Expand Down Expand Up @@ -71,19 +71,14 @@ private async Task GetDevices()

private Device CreateDeviceByType(DeviceDto dto)
{
switch (dto.DeviceType)
return dto.DeviceType switch
{
case DeviceType.LIGHT:
return new Light(this, dto);
case DeviceType.BLINDS:
return new Blind(this, dto);
case DeviceType.OUTLET:
return new Outlet(this, dto);
case DeviceType.ENVIRONMENT_SENSORS:
return new EnvironmentSensor(this, dto);
default:
return new Device(this, dto);
}
DeviceType.LIGHT => new Light(this, dto),
DeviceType.BLINDS => new Blind(this, dto),
DeviceType.OUTLET => new Outlet(this, dto),
DeviceType.ENVIRONMENT_SENSORS => new EnvironmentSensor(this, dto),
_ => new Device(this, dto),
};
}

private async Task GetRooms()
Expand All @@ -99,6 +94,7 @@ private async Task GetRooms()

public async Task SetLightState(Light light, bool state)
{
if (light is null || light.Id is null) return;
await _apiClient.PatchAttributes(light.Id, new Dictionary<string, object>()
{
{ "isOn", state }
Expand All @@ -107,6 +103,7 @@ public async Task SetLightState(Light light, bool state)

public async Task SetLightDimmer(Light light, int dimmer)
{
if (light is null || light.Id is null) return;
await _apiClient.PatchAttributes(light.Id, new Dictionary<string, object>()
{
{ "lightLevel", dimmer }
Expand All @@ -115,6 +112,7 @@ public async Task SetLightDimmer(Light light, int dimmer)

public async Task SetLightColorTemperature(Light light, int colorTemperature)
{
if (light is null || light.Id is null) return;
await _apiClient.PatchAttributes(light.Id, new Dictionary<string, object>()
{
{ "colorTemperature", colorTemperature }
Expand All @@ -123,6 +121,7 @@ public async Task SetLightColorTemperature(Light light, int colorTemperature)

public async Task SetLightColor(Light light, double hue, double saturation)
{
if (light is null || light.Id is null) return;
await _apiClient.PatchAttributes(light.Id, new Dictionary<string, object>()
{
{ "colorHue", hue },
Expand Down Expand Up @@ -188,6 +187,7 @@ public async Task SetBlind(Room room, int level)

public async Task SetBlind(Blind blind, int level)
{
if (blind is null || blind.Id is null) return;
await _apiClient.PatchAttributes(blind.Id, new Dictionary<string, object>()
{
{ "blindsTargetLevel", level }
Expand All @@ -196,6 +196,7 @@ public async Task SetBlind(Blind blind, int level)

public async Task SetOutlet(Outlet outlet, bool state)
{
if (outlet is null || outlet.Id is null) return;
await _apiClient.PatchAttributes(outlet.Id, new Dictionary<string, object>()
{
{ "isOn", state }
Expand Down

0 comments on commit d624b5f

Please sign in to comment.