Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Checks #233

Merged
merged 7 commits into from
Jan 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,053 changes: 679 additions & 374 deletions devices/baseDevice.js

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions devices/device.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@
<label style="width:auto" for="node-input-passthru"><i class="fa fa-arrow-right"></i> <span data-i18n="device.label.passthru"></span></label>
<input type="checkbox" checked id="node-input-passthru" style="display:inline-block; width:auto; vertical-align:top;">
</div>

<div class="form-row">
<label style="width:auto" for="node-input-persistent_state"><i class="fa fa-arrow-right"></i> <span data-i18n="device.label.persistent_state"></span></label>
<input type="checkbox" checked id="node-input-persistent_state" style="display:inline-block; width:auto; vertical-align:top;">
</div>

<div class="form-row" id="device_type">
<label style="width:auto" for="node-input-device_type"><i class="fa fa-tag"></i> <span data-i18n="device.label.device_type"></span></label>
Expand Down Expand Up @@ -2201,6 +2206,9 @@
passthru: {
value: false, required: false
},
persistent_state: {
value: false, required: false
},
trait_scene: {
value: false, required: false
},
Expand Down
6 changes: 3 additions & 3 deletions devices/locales/en-US/device.html
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,11 @@ <h4>Node Properties - Node-RED Settings</h4>

<p><code>Pass Through</code> If enabled, incoming messages will be passed onto the output. Be careful with this setting.</p>

<p><code>Language</code> the spoken language used with the Google Smart Home.</p>
<p><code>Persistent state</code> If enabled, the updated state will be included in the set_state message.</p>

<p><code>Show trait</code> choose to show the selected, recommended or all traits.</p>
<p><code>Show trait</code> Choose to show the selected, recommended or all traits.</p>

<p><code>Advanced settings</code> shows the advanced settings. Don't modify them unless You know what you are doing.</p>
<p><code>Advanced settings</code> Shows the advanced settings. Don't modify them unless You know what you are doing.</p>

<h4>Input Message</h4>
<p>If the <code>msg.topic</code> is one of the device states name the <code>msg.payload</code> must be the new value telling the new state of the device.</p>
Expand Down
3 changes: 2 additions & 1 deletion devices/locales/en-US/device.json
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,8 @@
"no_challenge": "No challenge",
"ackNeeded": "Ack needed",
"pinNeeded": "PIN needed",
"pin": "PIN"
"pin": "PIN",
"persistent_state": "Persistent state"
},
"placeholder": {
"name": "Name",
Expand Down
6 changes: 3 additions & 3 deletions devices/locales/it-IT/device.html
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,11 @@ <h4>Node Properties - Node-RED Settings</h4>

<p><code>Pass Through</code> If enabled, incoming messages will be passed onto the output. Be careful with this setting.</p>

<p><code>Language</code> the spoken language used with the Google Smart Home.</p>
<p><code>Persistent state</code> If enabled, the updated state will be included in the set_state message.</p>

<p><code>Show trait</code> choose to show the selected, recommended or all traits.</p>
<p><code>Show trait</code> Choose to show the selected, recommended or all traits.</p>

<p><code>Advanced settings</code> shows the advanced settings. Don't modify them unless You know what you are doing.</p>
<p><code>Advanced settings</code> Shows the advanced settings. Don't modify them unless You know what you are doing.</p>

<h4>Input Message</h4>
<p>If the <code>msg.topic</code> is one of the device states name the <code>msg.payload</code> must be the new value telling the new state of the device.</p>
Expand Down
3 changes: 2 additions & 1 deletion devices/locales/it-IT/device.json
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,8 @@
"no_challenge": "Nessuna",
"ackNeeded": "Si/No",
"pinNeeded": "PIN",
"pin": "PIN"
"pin": "PIN",
"persistent_state": "Stato persistente"
},
"placeholder": {
"name": "Nome",
Expand Down
33 changes: 25 additions & 8 deletions google-smarthome.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,33 +269,50 @@ module.exports = function(RED) {
this.onInput = function (msg) {
RED.log.debug("MgmtNode(input)");

let topicArr = msg.topic.split(node.topicDelim);
let topicArr = (msg.topic || '').split(node.topicDelim);
let topic = topicArr[topicArr.length - 1]; // get last part of topic
const topic_upper = topic.toUpperCase();

RED.log.debug("MgmtNode(input): topic = " + topic);

try {
if (topic.toUpperCase() === 'RESTART_SERVER') {
if (topic_upper === 'RESTART_SERVER') {
RED.log.debug("MgmtNode(input): RESTART_SERVER");

this.clientConn.app.Restart(RED.httpNode || RED.httpAdmin);
} else if (topic.toUpperCase() === 'REPORT_STATE') {
} else if (topic_upper === 'REPORT_STATE') {
RED.log.debug("MgmtNode(input): REPORT_STATE");

this.clientConn.app.ReportAllStates();
} else if (topic.toUpperCase() === 'REQUEST_SYNC') {
} else if (topic_upper === 'REQUEST_SYNC') {
RED.log.debug("MgmtNode(input): REQUEST_SYNC");

this.clientConn.app.RequestSync();
} else if (topic.toUpperCase() === 'GET_STATE') {
let states = this.clientConn.app.getStates();
} else if (topic_upper === 'GET_STATE' || topic_upper === 'GETSTATE') {
let onlyPersistent = false;
let useNames = false;
let deviceIds = undefined;
if (typeof msg.payload === 'boolean') {
onlyPersistent = msg.payload;
} else if (typeof msg.payload === 'string') {
deviceIds = [ msg.payload ];
} else if (typeof msg.payload === 'object') {
onlyPersistent = msg.payload.onlyPersistent || false;
useNames = msg.payload.useNames || false;
if (typeof msg.payload.devices === 'string') {
deviceIds = [ msg.payload.devices ];
} else if (Array.isArray(msg.payload.devices)) {
deviceIds = msg.payload.devices;
}
}
let states = this.clientConn.app.getStates(deviceIds, onlyPersistent, useNames, RED);
if (states) {
this.send({
topic: topic,
payload: states
});
}
} else if (topic.toUpperCase() === 'SET_STATE') {
} else if (topic_upper === 'SET_STATE' || topic_upper === 'SETSTATE') {
if (typeof msg.payload === 'object') {
this.clientConn.app.setStates(msg.payload);
}
Expand All @@ -306,7 +323,7 @@ module.exports = function(RED) {
};

this.sendSetState = function () {
let states = this.clientConn.app.getStates();
let states = this.clientConn.app.getStates(undefined, true, false, RED);
if (states) {
this.send({
topic: 'set_state',
Expand Down
15 changes: 13 additions & 2 deletions lib/Devices.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ class Devices {
//
//
//
getStates(deviceIds) {
getStates(deviceIds, onlyPersistent, useNames, RED) {
this.debug('Device:getStates(): deviceIds = ' + JSON.stringify(deviceIds));

if (!deviceIds || !Object.keys(deviceIds).length) {
Expand All @@ -279,7 +279,18 @@ class Devices {
if (!deviceIds) {
Object.keys(me._devices).forEach(function (deviceId) {
if (me._devices.hasOwnProperty(deviceId)) {
states[deviceId] = me._devices[deviceId].states;
let include = true;
let key = deviceId;
if (onlyPersistent === true || useNames === true) {
let node = RED.nodes.getNode(deviceId);
include = node.persistent_state;
if (useNames === true) {
key = node.name;
}
}
if (include) {
states[key] = me._devices[deviceId].states;
}
}
});
} else {
Expand Down
2 changes: 1 addition & 1 deletion locales/en-US/google-smarthome.html
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ <h4>Input Messages</h4>
<dt>topic
<span class="property-type">string</span>
</dt>
<dd>A topic of <code>get_state</code> requests to send to the output the state of all Google devices. <code>msg.payload</code> is not used for anything.</dd>
<dd>A topic of <code>get_state</code> requests to send to the output the state of all Google devices, if the <code>msg.payload</code> is not true, otherwise sends to the output the state of all Google devices with the "Persistent State" enabled.</dd>
</dl>

<p>If <code>msg.topic</code> is <code>set_state</code> the node updates the Google devices states with the states contained on the <code>msg.payload</code>.</p>
Expand Down
2 changes: 1 addition & 1 deletion locales/it_IT/google-smarthome.html
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ <h4>Messaggi in ingresso</h4>
<dt>topic
<span class="property-type">stringa</span>
</dt>
<dd>Se un messaggio con topic <code>get_state</code> è ricevuto, il nodo invierà un messaggio in uscita con lo stato di tutti i dispositivi. <code>msg.payload</code> non è usato.</dd>
<dd>Se un messaggio con topic <code>get_state</code> è ricevuto, il nodo invierà un messaggio in uscita con lo stato di tutti i dispositivi, se <code>msg.payload</code> non è valorizzato a true, altrimenti il nodo invierà un messaggio in uscita con lo stato di tutti i dispositivi che hanno il campo "Stato persistente" abilitato.</dd>
</dl>

<p>Se il <code>msg.topic</code> è <code>set_state</code>, il nodo aggiorna lo stato di tutti i dispositivi con lo stato contenuto nel <code>msg.payload</code>. Questo messaggio può essere usato per salvare su un dispositivo di memorizzazione lo stato di tutti i dispositivi.</p>
Expand Down
Loading