Skip to content

Commit

Permalink
Merge branch 'master' of github.com:SondreNjaastad/node-red-contrib-b…
Browse files Browse the repository at this point in the history
…luelinky
  • Loading branch information
Hacksore committed May 10, 2021
2 parents 12f891f + 5bd52b5 commit 48954bb
Show file tree
Hide file tree
Showing 2 changed files with 281 additions and 6 deletions.
151 changes: 147 additions & 4 deletions bluelinky.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,74 @@
});
</script>

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

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

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

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

<script type="text/javascript">
RED.nodes.registerType('start-car', {
category: 'bluelinky',
Expand Down Expand Up @@ -246,6 +314,83 @@
<p>Get the full status of the configured vehicle, always unparsed</p>
</script>

<script type="text/html" data-template-name="get-monthlyreport">
<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-monthlyreport">
<p>[EU] Gets a report of last month</p>
</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>
<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-tripinfo">
<p>[EU] Gets info about the trips of a day, required config as msg.payload:</p>
<p>If day is omitted, you are getting a summary of the month</p>
<p>If month and year are also omitted, summary of this month</p>
for example:
<pre>
{ "year": 2021, "month": 3 }
or
{ "year": 2021, "month": 3, "day": 24}
</pre>
</script>

<script type="text/html" data-template-name="set-navigation">
<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="set-navigation">
<p>For EVs:</p>
<p>Sets your navigation to max three waypoints, required config as msg.payload:</p>
<p></p>
</script>

<script type="text/html" data-template-name="set-chargetargets">
<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="set-chargetargets">
<p>[EU][EV] Sets your charge targets, required config as msg.payload:</p>
<p></p>
<pre>
{
"fast": number;
"slow": number;
}
</pre>
</script>

<script type="text/html" data-template-name="start-car">
<div class="form-row">
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
Expand All @@ -269,8 +414,7 @@
defrost?: boolean | string;
heating1?: boolean | string;
}
</pre
>
</pre>
<br />
<p>For EVs:</p>
<p>Starts your climate, required config as msg.payload:</p>
Expand All @@ -282,8 +426,7 @@
temperature: number;
unit: string;
}
</pre
>
</pre>
</script>

<script type="text/html" data-template-name="stop-car">
Expand Down
136 changes: 134 additions & 2 deletions bluelinky.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ module.exports = function (RED) {
if (!this.connected) {
return null;
}
await client.getVehicles();
const car = await client.getVehicle(this.bluelinkyConfig.vin);
const result = await car.start(msg.payload);
node.send({
Expand Down Expand Up @@ -277,6 +278,7 @@ module.exports = function (RED) {
if (!this.connected) {
return null;
}
await client.getVehicles();
const car = await client.getVehicle(this.bluelinkyConfig.vin);
const result = await car.stop(msg.payload);
node.send({
Expand Down Expand Up @@ -307,8 +309,134 @@ module.exports = function (RED) {
if (!this.connected) {
return null;
}
let car = await client.getVehicle(this.bluelinkyConfig.vin);
let result = await car.lock();
const car = await client.getVehicle(this.bluelinkyConfig.vin);
const result = await car.lock();
node.send({
payload: result,
});
} catch (err) {
node.send({
payload: err,
});
}
});
}

function SetChargeTargets(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.setChargeTargets(msg.payload);
node.send({
payload: result,
});
} catch (err) {
node.send({
payload: err,
});
}
});
}

function SetNavigation(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.setNavigation(msg.payload);
node.send({
payload: result,
});
} catch (err) {
node.send({
payload: err,
});
}
});
}

function GetMonthlyReport(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.monthlyReport();
node.send({
payload: result,
});
} catch (err) {
node.send({
payload: err,
});
}
});
}

function GetTripInfo(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.tripInfo(msg.payload);
node.send({
payload: result,
});
Expand Down Expand Up @@ -373,4 +501,8 @@ module.exports = function (RED) {
RED.nodes.registerType('stop-car', Stop);
RED.nodes.registerType('start-charge', StartCharge);
RED.nodes.registerType('stop-charge', StopCharge);
RED.nodes.registerType('set-chargetargets', SetChargeTargets);
RED.nodes.registerType('set-navigation', SetNavigation);
RED.nodes.registerType('get-monthlyreport', GetMonthlyReport);
RED.nodes.registerType('get-tripinfo', GetTripInfo);
};

0 comments on commit 48954bb

Please sign in to comment.