Skip to content

Commit

Permalink
Implemented HVAC functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
Frankenslag committed Aug 18, 2021
1 parent 60393df commit 4d25804
Show file tree
Hide file tree
Showing 6 changed files with 190 additions and 3 deletions.
28 changes: 28 additions & 0 deletions MazdaApiLib/MazdaApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,34 @@ public MazdaApiClient(string emailAddress, string password, string region, HttpC
}
}

/// <summary>
/// Update the HVAC settings for a given vehicle.
/// </summary>
/// <param name="internalVin">The internal vehicle identity number for the vehicle which can be found with calls to methods that return vehicles</param>
/// <param name="hvacSettings">An HvacSetting object containing the values to be updated</param>
public void SetHvacSettings(string internalVin, HvacSettings hvacSettings) => SetHvacSettingsAsync(internalVin, hvacSettings).Wait();

/// <summary>
/// Update the HVAC settings for a given vehicle asynchronously.
/// </summary>
/// <param name="internalVin">The internal vehicle identity number for the vehicle which can be found with calls to methods that return vehicles</param>
/// <param name="hvacSettings">An HvacSetting object containing the values to be updated</param>
public Task SetHvacSettingsAsync(string internalVin, HvacSettings hvacSettings) => _controller.SetHvacSettingsAsync(internalVin, hvacSettings);

/// <summary>
/// Get the HVAC settings for a given vehicle asynchronously.
/// </summary>
/// <param name="internalVin">The internal vehicle identity number for the vehicle which can be found with calls to methods that return vehicles</param>
/// <returns>An HvacSettings object containing the HVAC settings</returns>
public HvacSettings GetHvacSettings(string internalVin) => GetHvacSettingsAsync(internalVin).GetAwaiter().GetResult();

/// <summary>
/// Get the HVAC settings for a given vehicle asynchronously.
/// </summary>
/// <param name="internalVin">The internal vehicle identity number for the vehicle which can be found with calls to methods that return vehicles</param>
/// <returns>An HvacSettings object containing the HVAC settings</returns>
public Task<HvacSettings> GetHvacSettingsAsync(string internalVin) => _controller.GetHvacSettingsAsync(internalVin);

/// <summary>
/// Get the remote permissions for a given vehicle.
/// </summary>
Expand Down
20 changes: 20 additions & 0 deletions MazdaApiLib/MazdaApiController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,25 @@ public async Task<string> GetVehicleStatusAsync(string internalVin)
throw new MazdaApiException("Failed to get vehicle status");
}

public async Task SetHvacSettingsAsync(string internalVin, HvacSettings hvacSettings)
{
ApiResult result = JsonConvert.DeserializeObject<ApiResult>(await _connection.ApiRequestAsync(HttpMethod.Post, "/remoteServices/updateHVACSetting/v4", $"{{\"internaluserid\": \"__INTERNAL_ID__\", \"internalvin\": {internalVin}, \"hvacsettings\": {JsonConvert.SerializeObject(hvacSettings)}}}", true, true));

if ((result?.ResultCode ?? string.Empty) != "200S00")
{
throw new MazdaApiException("Failed to update hvac settings");
}
}

public async Task<HvacSettings> GetHvacSettingsAsync(string vin)
{
ApiResult result = JsonConvert.DeserializeObject<ApiResult>(await _connection.ApiRequestAsync(HttpMethod.Post, "/remoteServices/getHVACSetting/v4", $"{{\"internaluserid\": \"__INTERNAL_ID__\", \"vin\": \"{vin}\"}}", true, true));

if ((result?.ResultCode ?? string.Empty) == "200S00") return result?.HvacSettings;

throw new MazdaApiException("Failed to get hvac settings");
}

public async Task<string> GetRemotePermissionsAsync(string vin)
{
ApiResult result = JsonConvert.DeserializeObject<ApiResult>(await _connection.ApiRequestAsync(HttpMethod.Post, "/remoteServices/getRemoteControlPermission/v4", $"{{\"internaluserid\": \"__INTERNAL_ID__\", \"vin\": \"{vin}\"}}", true, true));
Expand Down Expand Up @@ -124,6 +143,7 @@ public async Task<string> GetNicknameAsync(string vin)
private class ApiResult
{
public string ResultCode { get; set; }
public HvacSettings HvacSettings { get; set; }
public string AvailableService { get; set; }
public string CarlineDesc { get; set; }
public object RemoteControl { get; set; }
Expand Down
6 changes: 3 additions & 3 deletions MazdaApiLib/MazdaApiLib.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
<PackageLicenseExpression></PackageLicenseExpression>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<AssemblyVersion>0.3.0.0</AssemblyVersion>
<FileVersion>0.3.0.0</FileVersion>
<Version>0.3.0</Version>
<AssemblyVersion>0.4.0.0</AssemblyVersion>
<FileVersion>0.4.0.0</FileVersion>
<Version>0.4.0</Version>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
Expand Down
28 changes: 28 additions & 0 deletions MazdaApiLib/MazdaApiLib.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 49 additions & 0 deletions MazdaApiLib/Model/HvacSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//
// HvacSettings.cs
//
// MIT License
//
// Copyright (c) 2021 Andrew Gould
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//

using Newtonsoft.Json;

namespace WingandPrayer.MazdaApi.Model
{
public enum TemperatureType
{
Celsius = 1,
Farenheit = 2
}

public class HvacSettings
{
[JsonConverter(typeof(BoolConverter))]
public bool FrontDefroster { get; set; }

[JsonConverter(typeof(BoolConverter))]
public bool RearDefogger { get; set; }

public double Temperature { get; set; }

public TemperatureType TemperatureType { get; set; }
}
}
62 changes: 62 additions & 0 deletions MazdaApiLib/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,40 @@ An EvVehicleStatus
| ---- | ---- | ----------- |
| internalVin | [System.String](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.String 'System.String') | The internal vehicle identity number for the vehicle which can be found with calls to methods that return vehicles |

<a name='M-WingandPrayer-MazdaApi-MazdaApiClient-GetHvacSettings-System-String-'></a>
### GetHvacSettings(internalVin) `method`

##### Summary

Get the HVAC settings for a given vehicle asynchronously.

##### Returns

An HvacSettings object containing the HVAC settings

##### Parameters

| Name | Type | Description |
| ---- | ---- | ----------- |
| internalVin | [System.String](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.String 'System.String') | The internal vehicle identity number for the vehicle which can be found with calls to methods that return vehicles |

<a name='M-WingandPrayer-MazdaApi-MazdaApiClient-GetHvacSettingsAsync-System-String-'></a>
### GetHvacSettingsAsync(internalVin) `method`

##### Summary

Get the HVAC settings for a given vehicle asynchronously.

##### Returns

An HvacSettings object containing the HVAC settings

##### Parameters

| Name | Type | Description |
| ---- | ---- | ----------- |
| internalVin | [System.String](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.String 'System.String') | The internal vehicle identity number for the vehicle which can be found with calls to methods that return vehicles |

<a name='M-WingandPrayer-MazdaApi-MazdaApiClient-GetRawVehicleStatus-System-String-'></a>
### GetRawVehicleStatus(internalVin) `method`

Expand Down Expand Up @@ -358,6 +392,34 @@ Locks the doors of the vehicle asynchronously.
| ---- | ---- | ----------- |
| internalVin | [System.String](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.String 'System.String') | The internal vehicle identity number for the vehicle which can be found with calls to methods that return vehicles |

<a name='M-WingandPrayer-MazdaApi-MazdaApiClient-SetHvacSettings-System-String,WingandPrayer-MazdaApi-Model-HvacSettings-'></a>
### SetHvacSettings(internalVin,hvacSettings) `method`

##### Summary

Update the HVAC settings for a given vehicle.

##### Parameters

| Name | Type | Description |
| ---- | ---- | ----------- |
| internalVin | [System.String](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.String 'System.String') | The internal vehicle identity number for the vehicle which can be found with calls to methods that return vehicles |
| hvacSettings | [WingandPrayer.MazdaApi.Model.HvacSettings](#T-WingandPrayer-MazdaApi-Model-HvacSettings 'WingandPrayer.MazdaApi.Model.HvacSettings') | An HvacSetting object containing the values to be updated |

<a name='M-WingandPrayer-MazdaApi-MazdaApiClient-SetHvacSettingsAsync-System-String,WingandPrayer-MazdaApi-Model-HvacSettings-'></a>
### SetHvacSettingsAsync(internalVin,hvacSettings) `method`

##### Summary

Update the HVAC settings for a given vehicle asynchronously.

##### Parameters

| Name | Type | Description |
| ---- | ---- | ----------- |
| internalVin | [System.String](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.String 'System.String') | The internal vehicle identity number for the vehicle which can be found with calls to methods that return vehicles |
| hvacSettings | [WingandPrayer.MazdaApi.Model.HvacSettings](#T-WingandPrayer-MazdaApi-Model-HvacSettings 'WingandPrayer.MazdaApi.Model.HvacSettings') | An HvacSetting object containing the values to be updated |

<a name='M-WingandPrayer-MazdaApi-MazdaApiClient-TurnOffHazzardLights-System-String-'></a>
### TurnOffHazzardLights(internalVin) `method`

Expand Down

0 comments on commit 4d25804

Please sign in to comment.