Skip to content

Commit

Permalink
Merge pull request #67 from PierreLevres/newEUnodes
Browse files Browse the repository at this point in the history
  • Loading branch information
Hacksore authored Mar 2, 2022
2 parents 56bd0af + 66425b8 commit bea4734
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 5 deletions.
44 changes: 40 additions & 4 deletions bluelinky.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,23 @@
});
</script>

<script type="text/javascript">
RED.nodes.registerType('get-drivehistory', {
category: 'bluelinky',
color: '#3FADB5',
defaults: {
name: { value: 'DriveHistory' },
bluelinky: { value: 'Bluelinky config', type: 'bluelinky' },
},
inputs: 1,
outputs: 1,
icon: 'bluelinky.png',
label: function () {
return this.name || 'get-drivehistory';
},
});
</script>

<script type="text/javascript">
RED.nodes.registerType('get-monthlyreport', {
category: 'bluelinky',
Expand Down Expand Up @@ -310,6 +327,7 @@
<input type="text" id="node-input-bluelinky" placeholder="Name" />
</div>
</script>

<script type="text/html" data-help-name="car-fullstatus">
<p>Get the full status of the configured vehicle, always unparsed</p>
</script>
Expand All @@ -329,6 +347,27 @@
<p>[EU] Gets a report of last month</p>
</script>

<script type="text/html" data-template-name="get-drivehistory">
<div class="form-row">
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name" />
</div>
<div class="form-row">
<label for="node-input-bluelinky"><i class="icon-tag"></i> Config</label>
<input type="text" id="node-input-bluelinky" placeholder="Name" />
</div>
</script>

<script type="text/html" data-help-name="get-drivehistory">
<p>[EU] Gets info about the energy consumption in a timeperiod, required config as msg.payload:</p>
<p>0 = day, 1 = month, 2 = all</p>
<p>If omitted, day is used.</p>
for example:
<pre>
msg.payload = 0
</pre>
</script>

<script type="text/html" data-template-name="get-tripinfo">
<div class="form-row">
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
Expand Down Expand Up @@ -384,10 +423,7 @@
<p>[EU][EV] Sets your charge targets, required config as msg.payload:</p>
<p></p>
<pre>
{
"fast": number;
"slow": number;
}
{"fast": number, "slow": number}
</pre>
</script>

Expand Down
33 changes: 33 additions & 0 deletions bluelinky.js
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,38 @@ module.exports = function (RED) {
});
}

function GetDriveHistory(config) {
RED.nodes.createNode(this, config);
this.bluelinkyConfig = RED.nodes.getNode(config.bluelinky);
this.status(this.bluelinkyConfig.status);
this.connected = false;
const node = this;

State.on('changed', (statusObject) => {
this.status(statusObject);
if (statusObject.text === 'Ready') {
this.connected = true;
}
});
node.on('input', async function (msg) {
try {
if (!this.connected) {
return null;
}
await client.getVehicles();
const car = await client.getVehicle(this.bluelinkyConfig.vin);
const result = await car.driveHistory(msg.payload);
node.send({
payload: result,
});
} catch (err) {
node.send({
payload: err,
});
}
});
}

function Login(config) {
RED.nodes.createNode(this, config);
this.bluelinkyConfig = RED.nodes.getNode(config.bluelinky);
Expand Down Expand Up @@ -505,4 +537,5 @@ module.exports = function (RED) {
RED.nodes.registerType('set-navigation', SetNavigation);
RED.nodes.registerType('get-monthlyreport', GetMonthlyReport);
RED.nodes.registerType('get-tripinfo', GetTripInfo);
RED.nodes.registerType('get-drivehistory', GetDriveHistory);
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-red-contrib-bluelinky",
"version": "0.0.27",
"version": "0.0.28",
"description": "A Node Red Library for BlueLinky, a Hyundai and Kia 3rd-party wrapper",
"main": "bluelinky.js",
"scripts": {
Expand Down

0 comments on commit bea4734

Please sign in to comment.