Skip to content

Commit

Permalink
feat(vehicle): get & set charge limit (#161)
Browse files Browse the repository at this point in the history
  • Loading branch information
EvanPeterson1324 authored Apr 11, 2023
1 parent 230e41e commit 0b18b9c
Show file tree
Hide file tree
Showing 7 changed files with 466 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,6 @@ Package Control.cache/
Package Control.ca-certs/
bh_unicode_properties.cache
GitHub.sublime-settings

## env
.env
61 changes: 61 additions & 0 deletions doc/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ the following fields :</p>
<dd></dd>
<dt><a href="#Permissions">Permissions</a> : <code>Object</code></dt>
<dd></dd>
<dt><a href="#ChargeLimit">ChargeLimit</a></dt>
<dd></dd>
<dt><a href="#WebhookSubscription">WebhookSubscription</a> : <code>Object</code></dt>
<dd></dd>
<dt><a href="#Batch">Batch</a> : <code>Object</code></dt>
Expand Down Expand Up @@ -549,6 +551,8 @@ Initializes a new Service object to make requests to the Smartcar API.
* [Vehicle](#Vehicle)
* [new Vehicle(id, token, [options])](#new_Vehicle_new)
* [.permissions([paging])](#Vehicle+permissions)[<code>Permissions</code>](#Permissions)
* [.getChargeLimit()](#Vehicle+getChargeLimit)[<code>ChargeLimit</code>](#ChargeLimit)
* [.setChargeLimit(limit)](#Vehicle+setChargeLimit)[<code>ChargeLimit</code>](#ChargeLimit)
* [.subscribe(webhookId)](#Vehicle+subscribe) ⇒ <code>Object</code>
* [.unsubscribe(amt, webhookId)](#Vehicle+unsubscribe)[<code>Meta</code>](#Meta)
* [.batch(paths)](#Vehicle+batch)[<code>Batch</code>](#Batch)
Expand Down Expand Up @@ -603,6 +607,53 @@ Fetch the list of permissions that this application has been granted
| [paging.limit] | <code>String</code> | number of permissions to return |
| [options.offset] | <code>Object</code> | The current start index of the returned list of elements. |

<a name="Vehicle+getChargeLimit"></a>

### vehicle.getChargeLimit() ⇒ [<code>ChargeLimit</code>](#ChargeLimit)
Fetch the charge limit for an electric vehicle

**Kind**: instance method of [<code>Vehicle</code>](#Vehicle)
**Throws**:

- [<code>SmartcarError</code>](#SmartcarError) - an instance of SmartcarError.
See the [errors section](https://github.com/smartcar/node-sdk/tree/master/doc#errors)
for all possible errors.

**Example**
```js
{
limit: .7,
meta: {
requestId: '26c14915-0c26-43c5-8e42-9edfc2a66a0f',
}
}
```
<a name="Vehicle+setChargeLimit"></a>

### vehicle.setChargeLimit(limit) ⇒ [<code>ChargeLimit</code>](#ChargeLimit)
Set the charge limit for an electric vehicle.

**Kind**: instance method of [<code>Vehicle</code>](#Vehicle)
**Throws**:

- [<code>SmartcarError</code>](#SmartcarError) - an instance of SmartcarError.
See the [errors section](https://github.com/smartcar/node-sdk/tree/master/doc#errors)
for all possible errors.


| Param | Type | Description |
| --- | --- | --- |
| limit | <code>number</code> | a number between 0 and 1 |

**Example**
```js
{
status: string,
meta: {
requestId: '26c14915-0c26-43c5-8e42-9edfc2a66a0f',
}
}
```
<a name="Vehicle+subscribe"></a>

### vehicle.subscribe(webhookId) ⇒ <code>Object</code>
Expand Down Expand Up @@ -935,6 +986,16 @@ the following fields :
}
}
```
<a name="ChargeLimit"></a>

## ChargeLimit
**Kind**: global typedef
**Properties**

| Name | Type | Description |
| --- | --- | --- |
| limit | <code>number</code> | the charge limit expressed as a decimal value between 0 and 1. |

<a name="WebhookSubscription"></a>

## WebhookSubscription : <code>Object</code>
Expand Down
67 changes: 66 additions & 1 deletion lib/vehicle.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ _.forEach(METHODS_MAP, (attributes, methodName) => {
* @param {Object} [paging]
* @param {String} [paging.limit] - number of permissions to return
* @param {Object} [options.offset] - The current start index of the returned list of elements.
* @return {Permissions}
* @returns {Permissions}
* @throws {SmartcarError} - an instance of SmartcarError.
* See the [errors section](https://github.com/smartcar/node-sdk/tree/master/doc#errors)
* for all possible errors.
Expand All @@ -139,6 +139,71 @@ Vehicle.prototype.permissions = async function(paging = {}) {
return response;
};

/**
* @typedef ChargeLimit
* @property {number} limit - the charge limit expressed as a decimal value between 0 and 1.
*/

/**
* Fetch the charge limit for an electric vehicle
*
* @method
* @returns {ChargeLimit}
* @throws {SmartcarError} - an instance of SmartcarError.
* See the [errors section](https://github.com/smartcar/node-sdk/tree/master/doc#errors)
* for all possible errors.
*
* @example
* {
* limit: .7,
* meta: {
* requestId: '26c14915-0c26-43c5-8e42-9edfc2a66a0f',
* }
* }
*/

Vehicle.prototype.getChargeLimit = async function() {
const response = await this.service.request(
'get',
'charge/limit',
);

return response;
};

/**
* Set the charge limit for an electric vehicle.
*
* @method
* @param {number} limit - a number between 0 and 1
* @returns {ChargeLimit}
* @throws {SmartcarError} - an instance of SmartcarError.
* See the [errors section](https://github.com/smartcar/node-sdk/tree/master/doc#errors)
* for all possible errors.
*
* @example
* {
* status: string,
* meta: {
* requestId: '26c14915-0c26-43c5-8e42-9edfc2a66a0f',
* }
* }
*/
Vehicle.prototype.setChargeLimit = async function(limit) {

const body = {
limit: String(limit),
};

const response = await this.service.request(
'post',
'charge/limit',
{body},
);

return response;
};

/**
* @type {Object}
* @typedef WebhookSubscription
Expand Down
Loading

0 comments on commit 0b18b9c

Please sign in to comment.