diff --git a/src/.editorconfig b/src/.editorconfig
index 042caa1..587aca1 100644
--- a/src/.editorconfig
+++ b/src/.editorconfig
@@ -11,3 +11,14 @@ dotnet_naming_symbols.any_async_methods.required_modifiers = async
dotnet_naming_style.end_in_async.required_suffix = Async
dotnet_naming_style.end_in_async.capitalization = pascal_case
+
+[*.cs]
+
+# SA1101: Prefix local calls with this
+dotnet_diagnostic.SA1101.severity = none
+
+# SA1309: Field names should not begin with underscore
+dotnet_diagnostic.SA1309.severity = none
+
+# SA1503: Braces should not be omitted
+dotnet_diagnostic.SA1503.severity = none
diff --git a/src/Tesla.NET/Models/IChargeState.cs b/src/Tesla.NET/Models/IChargeState.cs
index 67eb26c..da029d7 100644
--- a/src/Tesla.NET/Models/IChargeState.cs
+++ b/src/Tesla.NET/Models/IChargeState.cs
@@ -15,19 +15,19 @@ public interface IChargeState : IState
/// Gets the charging state of a .
///
[JsonProperty("charging_state")]
- string ChargingState { get; }
+ string? ChargingState { get; }
///
/// Gets the type of fast charging.
///
[JsonProperty("fast_charger_type")]
- string FastChargerType { get; }
+ string? FastChargerType { get; }
///
/// Gets the brand of fast charging.
///
[JsonProperty("fast_charger_brand")]
- string FastChargerBrand { get; }
+ string? FastChargerBrand { get; }
///
/// Gets the charge limit .
@@ -171,7 +171,7 @@ public interface IChargeState : IState
/// Gets the type of the charge cable connected to a .
///
[JsonProperty("conn_charge_cable")]
- string ConnChargeCable { get; }
+ string? ConnChargeCable { get; }
///
/// Gets the schedule charging start time of a .
@@ -213,7 +213,7 @@ public interface IChargeState : IState
/// Gets the charge port latch of a .
///
[JsonProperty("charge_port_latch")]
- string ChargePortLatch { get; }
+ string? ChargePortLatch { get; }
///
/// Gets the charge current request of a .
diff --git a/src/Tesla.NET/Models/IDriveState.cs b/src/Tesla.NET/Models/IDriveState.cs
index c8fdd47..488305e 100644
--- a/src/Tesla.NET/Models/IDriveState.cs
+++ b/src/Tesla.NET/Models/IDriveState.cs
@@ -15,13 +15,13 @@ public interface IDriveState : IState
/// Gets the shift state of a .
///
[JsonProperty("shift_state")]
- string ShiftState { get; }
+ string? ShiftState { get; }
///
/// Gets the speed .
///
[JsonProperty("speed")]
- string Speed { get; }
+ string? Speed { get; }
///
/// Gets the power .
diff --git a/src/Tesla.NET/Models/IMessageResponse.Generic.cs b/src/Tesla.NET/Models/IMessageResponse.Generic.cs
index d7baa7d..8fe999a 100644
--- a/src/Tesla.NET/Models/IMessageResponse.Generic.cs
+++ b/src/Tesla.NET/Models/IMessageResponse.Generic.cs
@@ -15,6 +15,6 @@ public interface IMessageResponse : IMessageResponse
///
/// Gets the object.
///
- TData Data { get; }
+ TData? Data { get; }
}
}
diff --git a/src/Tesla.NET/Models/IMessageResponse.cs b/src/Tesla.NET/Models/IMessageResponse.cs
index fb14200..9740872 100644
--- a/src/Tesla.NET/Models/IMessageResponse.cs
+++ b/src/Tesla.NET/Models/IMessageResponse.cs
@@ -20,7 +20,7 @@ public interface IMessageResponse
///
/// Gets the raw JSON of the .
///
- JObject RawJson { get; }
+ JObject? RawJson { get; }
///
/// Gets the raw JSON of the .
diff --git a/src/Tesla.NET/Models/IVehicle.cs b/src/Tesla.NET/Models/IVehicle.cs
index 57feb13..c81c9f3 100644
--- a/src/Tesla.NET/Models/IVehicle.cs
+++ b/src/Tesla.NET/Models/IVehicle.cs
@@ -27,25 +27,25 @@ public interface IVehicle
/// Gets the VIN (vehicle identification number) of the .
///
[JsonProperty("vin")]
- string Vin { get; }
+ string? Vin { get; }
///
/// Gets the display name of the .
///
[JsonProperty("display_name")]
- string DisplayName { get; }
+ string? DisplayName { get; }
///
/// Gets the option codes of the .
///
[JsonProperty("option_codes")]
- string OptionCodes { get; }
+ string? OptionCodes { get; }
///
/// Gets the color of the .
///
[JsonProperty("color")]
- string Color { get; }
+ string? Color { get; }
///
/// Gets the tokens of the .
@@ -57,13 +57,13 @@ public interface IVehicle
/// Gets the state of the .
///
[JsonProperty("state")]
- string State { get; }
+ string? State { get; }
///
/// Gets the in service state of the .
///
[JsonProperty("in_service")]
- string InService { get; }
+ string? InService { get; }
///
/// Gets a value indicating whether remote start is enabled for the .
@@ -87,12 +87,12 @@ public interface IVehicle
/// Gets the of the .
///
[JsonProperty("backseat_token")]
- string BackseatToken { get; }
+ string? BackseatToken { get; }
///
/// Gets the of the .
///
[JsonProperty("backseat_token_updated_at")]
- string BackseatTokenUpdatedAt { get; }
+ string? BackseatTokenUpdatedAt { get; }
}
}
diff --git a/src/Tesla.NET/Models/IVehicleState.cs b/src/Tesla.NET/Models/IVehicleState.cs
index 56e2963..ba3139f 100644
--- a/src/Tesla.NET/Models/IVehicleState.cs
+++ b/src/Tesla.NET/Models/IVehicleState.cs
@@ -21,19 +21,19 @@ public interface IVehicleState : IState
/// Gets the state of auto-park.
///
[JsonProperty("autopark_state")]
- string AutoparkState { get; }
+ string? AutoparkState { get; }
///
/// Gets the state of V2 auto-park.
///
[JsonProperty("autopark_state_v2")]
- string AutoparkStateV2 { get; }
+ string? AutoparkStateV2 { get; }
///
/// Gets the style of auto-park.
///
[JsonProperty("autopark_style")]
- string AutoparkStyle { get; }
+ string? AutoparkStyle { get; }
///
/// Gets a value indicating whether the Calendar is supported.
@@ -45,7 +45,7 @@ public interface IVehicleState : IState
/// Gets the car firmware version.
///
[JsonProperty("car_version")]
- string CarVersion { get; }
+ string? CarVersion { get; }
///
/// Gets the state of the center display.
@@ -81,7 +81,7 @@ public interface IVehicleState : IState
/// Gets the last auto-park error.
///
[JsonProperty("last_autopark_error")]
- string LastAutoparkError { get; }
+ string? LastAutoparkError { get; }
///
/// Gets a value indicating whether the car is locked.
@@ -147,7 +147,7 @@ public interface IVehicleState : IState
/// Gets the state of the sunroof.
///
[JsonProperty("sun_roof_state")]
- string SunRoofState { get; }
+ string? SunRoofState { get; }
///
/// Gets a value indicating whether valet mode is enabled.
@@ -165,6 +165,6 @@ public interface IVehicleState : IState
/// Gets the name of the .
///
[JsonProperty("vehicle_name")]
- string VehicleName { get; }
+ string? VehicleName { get; }
}
}
diff --git a/src/Tesla.NET/Models/Internal/ChargeState.cs b/src/Tesla.NET/Models/Internal/ChargeState.cs
index 58bf004..803b063 100644
--- a/src/Tesla.NET/Models/Internal/ChargeState.cs
+++ b/src/Tesla.NET/Models/Internal/ChargeState.cs
@@ -58,9 +58,9 @@ public class ChargeState : IChargeState
/// The .
/// The .
public ChargeState(
- string chargingState = null,
- string fastChargerType = null,
- string fastChargerBrand = null,
+ string? chargingState = null,
+ string? fastChargerType = null,
+ string? fastChargerBrand = null,
long? chargeLimitSoc = null,
long? chargeLimitSocStd = null,
long? chargeLimitSocMin = null,
@@ -84,13 +84,13 @@ public ChargeState(
bool? tripCharging = null,
long? chargeRate = null,
bool? chargePortDoorOpen = null,
- string connChargeCable = null,
+ string? connChargeCable = null,
long? scheduledChargingStartTime = null,
bool? scheduledChargingPending = null,
bool? userChargeEnableRequest = null,
bool? chargeEnableRequest = null,
int? chargerPhases = null,
- string chargePortLatch = null,
+ string? chargePortLatch = null,
long? chargeCurrentRequest = null,
long? chargeCurrentRequestMax = null,
bool? managedChargingActive = null,
@@ -146,17 +146,17 @@ public ChargeState(
///
/// Gets the charging state of a .
///
- public string ChargingState { get; }
+ public string? ChargingState { get; }
///
/// Gets the type of fast charging.
///
- public string FastChargerType { get; }
+ public string? FastChargerType { get; }
///
/// Gets the brand of fast charging.
///
- public string FastChargerBrand { get; }
+ public string? FastChargerBrand { get; }
///
/// Gets the charge limit .
@@ -276,7 +276,7 @@ public ChargeState(
///
/// Gets the type of the charge cable connected to a .
///
- public string ConnChargeCable { get; }
+ public string? ConnChargeCable { get; }
///
/// Gets the schedule charging start time of a .
@@ -311,7 +311,7 @@ public ChargeState(
///
/// Gets the charge port latch of a .
///
- public string ChargePortLatch { get; }
+ public string? ChargePortLatch { get; }
///
/// Gets the charge current request of a .
diff --git a/src/Tesla.NET/Models/Internal/DriveState.cs b/src/Tesla.NET/Models/Internal/DriveState.cs
index 9d8104b..99a0e1f 100644
--- a/src/Tesla.NET/Models/Internal/DriveState.cs
+++ b/src/Tesla.NET/Models/Internal/DriveState.cs
@@ -24,8 +24,8 @@ public class DriveState : IDriveState
/// The .
/// The .
public DriveState(
- string shiftState = null,
- string speed = null,
+ string? shiftState = null,
+ string? speed = null,
long power = 0L,
double latitude = 0D,
double longitude = 0D,
@@ -46,12 +46,12 @@ public DriveState(
///
/// Gets the shift state of a .
///
- public string ShiftState { get; }
+ public string? ShiftState { get; }
///
/// Gets the speed .
///
- public string Speed { get; }
+ public string? Speed { get; }
///
/// Gets the power .
diff --git a/src/Tesla.NET/Models/Internal/MessageResponse.cs b/src/Tesla.NET/Models/Internal/MessageResponse.cs
index 0da1912..d7207ed 100644
--- a/src/Tesla.NET/Models/Internal/MessageResponse.cs
+++ b/src/Tesla.NET/Models/Internal/MessageResponse.cs
@@ -17,7 +17,7 @@ namespace Tesla.NET.Models.Internal
public class MessageResponse : IMessageResponse
where TData : class
{
- private readonly JObject _rawJson;
+ private readonly JObject? _rawJson;
///
/// Initializes a new instance of the class.
@@ -25,7 +25,7 @@ public class MessageResponse : IMessageResponse
/// The .
/// The raw JSON of the .
/// The object.
- public MessageResponse(HttpStatusCode httpStatusCode, JObject rawJson = null, TData data = null)
+ public MessageResponse(HttpStatusCode httpStatusCode, JObject? rawJson = null, TData? data = null)
{
HttpStatusCode = httpStatusCode;
_rawJson = rawJson;
@@ -40,7 +40,7 @@ public MessageResponse(HttpStatusCode httpStatusCode, JObject rawJson = null, TD
///
/// Gets the raw JSON of the .
///
- public JObject RawJson => (JObject)_rawJson?.DeepClone();
+ public JObject? RawJson => (JObject?)_rawJson?.DeepClone();
///
/// Gets the raw JSON of the .
@@ -50,7 +50,7 @@ public MessageResponse(HttpStatusCode httpStatusCode, JObject rawJson = null, TD
///
/// Gets the object.
///
- public TData Data { get; }
+ public TData? Data { get; }
private string DebuggerDisplay => $"{GetType().Name}: {HttpStatusCode:G}";
}
diff --git a/src/Tesla.NET/Models/Internal/ResponseDataWrapper.cs b/src/Tesla.NET/Models/Internal/ResponseDataWrapper.cs
index 9a9a38f..f0f9df7 100644
--- a/src/Tesla.NET/Models/Internal/ResponseDataWrapper.cs
+++ b/src/Tesla.NET/Models/Internal/ResponseDataWrapper.cs
@@ -17,7 +17,7 @@ public class ResponseDataWrapper : IResponseDataWrapper
/// Initializes a new instance of the class.
///
/// The object.
- public ResponseDataWrapper(TResponse response = default)
+ public ResponseDataWrapper(TResponse response)
{
Response = response;
}
diff --git a/src/Tesla.NET/Models/Internal/Vehicle.cs b/src/Tesla.NET/Models/Internal/Vehicle.cs
index 410828a..02b647c 100644
--- a/src/Tesla.NET/Models/Internal/Vehicle.cs
+++ b/src/Tesla.NET/Models/Internal/Vehicle.cs
@@ -3,6 +3,7 @@
namespace Tesla.NET.Models.Internal
{
+ using System;
using System.Collections.Generic;
using System.Diagnostics;
@@ -12,7 +13,7 @@ namespace Tesla.NET.Models.Internal
[DebuggerDisplay("{DebuggerDisplay,nq}")]
public class Vehicle : IVehicle
{
- private static readonly string[] EmptyTokens = { };
+ private static readonly string[] EmptyTokens = Array.Empty();
///
/// Initializes a new instance of the class.
@@ -34,18 +35,18 @@ public class Vehicle : IVehicle
public Vehicle(
long id = 0,
long vehicleId = 0,
- string vin = null,
- string displayName = null,
- string optionCodes = null,
- string color = null,
- IReadOnlyCollection tokens = null,
- string state = null,
- string inService = null,
+ string? vin = null,
+ string? displayName = null,
+ string? optionCodes = null,
+ string? color = null,
+ IReadOnlyCollection? tokens = null,
+ string? state = null,
+ string? inService = null,
bool remoteStartEnabled = false,
bool calendarEnabled = false,
bool notificationsEnabled = false,
- string backseatToken = null,
- string backseatTokenUpdatedAt = null)
+ string? backseatToken = null,
+ string? backseatTokenUpdatedAt = null)
{
Id = id;
VehicleId = vehicleId;
@@ -76,22 +77,22 @@ public Vehicle(
///
/// Gets the VIN (vehicle identification number) of the .
///
- public string Vin { get; }
+ public string? Vin { get; }
///
/// Gets the display name of the .
///
- public string DisplayName { get; }
+ public string? DisplayName { get; }
///
/// Gets the option codes of the .
///
- public string OptionCodes { get; }
+ public string? OptionCodes { get; }
///
/// Gets the color of the .
///
- public string Color { get; }
+ public string? Color { get; }
///
/// Gets the tokens of the .
@@ -101,12 +102,12 @@ public Vehicle(
///
/// Gets the state of the .
///
- public string State { get; }
+ public string? State { get; }
///
/// Gets the in service state of the .
///
- public string InService { get; }
+ public string? InService { get; }
///
/// Gets a value indicating whether remote start is enabled for the .
@@ -126,12 +127,12 @@ public Vehicle(
///
/// Gets the of the .
///
- public string BackseatToken { get; }
+ public string? BackseatToken { get; }
///
/// Gets the of the .
///
- public string BackseatTokenUpdatedAt { get; }
+ public string? BackseatTokenUpdatedAt { get; }
private string DebuggerDisplay => $"{GetType().Name}: {DisplayName} VIN={Vin}";
}
diff --git a/src/Tesla.NET/Models/Internal/VehicleState.cs b/src/Tesla.NET/Models/Internal/VehicleState.cs
index 0b89cfc..17885a1 100644
--- a/src/Tesla.NET/Models/Internal/VehicleState.cs
+++ b/src/Tesla.NET/Models/Internal/VehicleState.cs
@@ -44,17 +44,17 @@ public class VehicleState : IVehicleState
/// The .
public VehicleState(
long apiVersion = default,
- string autoparkState = default,
- string autoparkStateV2 = default,
- string autoparkStyle = default,
+ string? autoparkState = default,
+ string? autoparkStateV2 = default,
+ string? autoparkStyle = default,
bool calendarSupported = default,
- string carVersion = default,
+ string? carVersion = default,
long centerDisplayState = default,
long df = default,
long dr = default,
long ft = default,
bool homelinkNearby = default,
- string lastAutoparkError = default,
+ string? lastAutoparkError = default,
bool locked = default,
bool notificationsSupported = default,
double odometer = default,
@@ -65,11 +65,11 @@ public VehicleState(
bool remoteStartSupported = default,
long rt = default,
long? sunRoofPercentOpen = default,
- string sunRoofState = default,
+ string? sunRoofState = default,
long timestamp = default,
bool valetMode = default,
bool valetPinNeeded = default,
- string vehicleName = default)
+ string? vehicleName = default)
{
ApiVersion = apiVersion;
AutoparkState = autoparkState ?? string.Empty;
@@ -108,17 +108,17 @@ public VehicleState(
///
/// Gets the state of auto-park.
///
- public string AutoparkState { get; }
+ public string? AutoparkState { get; }
///
/// Gets the state of V2 auto-park.
///
- public string AutoparkStateV2 { get; }
+ public string? AutoparkStateV2 { get; }
///
/// Gets the style of auto-park.
///
- public string AutoparkStyle { get; }
+ public string? AutoparkStyle { get; }
///
/// Gets a value indicating whether the Calendar is supported.
@@ -128,7 +128,7 @@ public VehicleState(
///
/// Gets the car firmware version.
///
- public string CarVersion { get; }
+ public string? CarVersion { get; }
///
/// Gets the state of the center display.
@@ -158,7 +158,7 @@ public VehicleState(
///
/// Gets the last auto-park error.
///
- public string LastAutoparkError { get; }
+ public string? LastAutoparkError { get; }
///
/// Gets a value indicating whether the car is locked.
@@ -213,7 +213,7 @@ public VehicleState(
///
/// Gets the state of the sunroof.
///
- public string SunRoofState { get; }
+ public string? SunRoofState { get; }
///
/// Gets the millisecond Epoch timestamp when the was captured.
@@ -238,7 +238,7 @@ public VehicleState(
///
/// Gets the name of the .
///
- public string VehicleName { get; }
+ public string? VehicleName { get; }
private string DebuggerDisplay => $"{GetType().Name}: {VehicleName} {CarVersion} @ {TimestampUtc:R}";
}
diff --git a/src/Tesla.NET/Properties/AssemblyInfo.cs b/src/Tesla.NET/Properties/AssemblyInfo.cs
index 589d654..50ce6c6 100644
--- a/src/Tesla.NET/Properties/AssemblyInfo.cs
+++ b/src/Tesla.NET/Properties/AssemblyInfo.cs
@@ -7,17 +7,13 @@
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
-#if NET45
-[assembly: AssemblyTitle("Tesla.NET .NET Framework")]
-#else
-[assembly: AssemblyTitle("Tesla.NET .NET Standard")]
-#endif
+[assembly: AssemblyTitle("Tesla.NET")]
[assembly: AssemblyDescription("A .NET client library for the Tesla Owner API.")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Tesla.NET")]
-[assembly: AssemblyCopyright("Copyright © 2018 James Skimming")]
+[assembly: AssemblyCopyright("Copyright © 2018-2021 James Skimming")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
diff --git a/src/Tesla.NET/Requests/HttpClientExtensions.cs b/src/Tesla.NET/Requests/HttpClientExtensions.cs
index fc0bb28..d8608c0 100644
--- a/src/Tesla.NET/Requests/HttpClientExtensions.cs
+++ b/src/Tesla.NET/Requests/HttpClientExtensions.cs
@@ -5,6 +5,7 @@ namespace Tesla.NET.Requests
{
using System;
using System.Collections.Generic;
+ using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Net;
@@ -57,20 +58,20 @@ public static Task> RequestAccessTokenAsy
throw new ArgumentNullException(nameof(password));
Uri requestUri = new Uri(baseUri, "oauth/token");
- IEnumerable> parameters = GetRequestAccessTokenParameters();
+ IEnumerable> parameters = GetRequestAccessTokenParameters();
return
client
.PostFormAsync(requestUri, parameters, cancellationToken: cancellationToken)
.ReadJsonAsAsync(cancellationToken);
- IEnumerable> GetRequestAccessTokenParameters()
+ IEnumerable> GetRequestAccessTokenParameters()
{
- yield return new KeyValuePair("grant_type", "password");
- yield return new KeyValuePair("client_id", clientId);
- yield return new KeyValuePair("client_secret", clientSecret);
- yield return new KeyValuePair("email", email);
- yield return new KeyValuePair("password", password);
+ yield return new KeyValuePair("grant_type", "password");
+ yield return new KeyValuePair("client_id", clientId);
+ yield return new KeyValuePair("client_secret", clientSecret);
+ yield return new KeyValuePair("email", email);
+ yield return new KeyValuePair("password", password);
}
}
@@ -105,19 +106,19 @@ public static Task> RefreshAccessTokenAsy
throw new ArgumentNullException(nameof(refreshToken));
Uri requestUri = new Uri(baseUri, "oauth/token");
- IEnumerable> parameters = GetRefreshAccessTokenParameters();
+ IEnumerable> parameters = GetRefreshAccessTokenParameters();
return
client
.PostFormAsync(requestUri, parameters, cancellationToken: cancellationToken)
.ReadJsonAsAsync(cancellationToken);
- IEnumerable> GetRefreshAccessTokenParameters()
+ IEnumerable> GetRefreshAccessTokenParameters()
{
- yield return new KeyValuePair("grant_type", "refresh_token");
- yield return new KeyValuePair("client_id", clientId);
- yield return new KeyValuePair("client_secret", clientSecret);
- yield return new KeyValuePair("refresh_token", refreshToken);
+ yield return new KeyValuePair("grant_type", "refresh_token");
+ yield return new KeyValuePair("client_id", clientId);
+ yield return new KeyValuePair("client_secret", clientSecret);
+ yield return new KeyValuePair("refresh_token", refreshToken);
}
}
@@ -145,16 +146,16 @@ public static Task> RevokeAccessTokenAsync(
Uri requestUri = new Uri(baseUri, "oauth/revoke");
- IEnumerable> parameters = GetRevokeAccessTokenParameters();
+ IEnumerable> parameters = GetRevokeAccessTokenParameters();
return
client
.PostFormAsync(requestUri, parameters, accessToken, cancellationToken)
.ReadJsonAsAsync