forked from cakebake/node-red-contrib-alexa-remote-cakebaked
-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathalexa-remote-init.html
130 lines (126 loc) · 6.04 KB
/
alexa-remote-init.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<script type="text/x-red" data-template-name="alexa-remote-init">
<div class="form-row">
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Optional">
</div>
<div class="form-row">
<label for="node-input-account"><i class="fa fa-amazon"></i> Account</label>
<input id="node-input-account">
</div>
<div class="form-row">
<label for="node-input-option"><i class="fa fa-question-circle"></i> Option</label>
<select id="node-input-option" style="width: 70%;">
<option value="initialise">Initialise</option>
<option value="fresh">Fresh Authentication</option>
<option value="refresh">Refresh Cookie</option>
<option value="update">Update Cached State</option>
<option value="reset">Reset</option>
<option value="interval">Interval Info</option>
</select>
</div>
</script>
<script type="text/x-red" data-help-name="alexa-remote-init">
<style>
table, th, td {
border-collapse: collapse;
border: 1px solid rgb(204, 204, 204);
padding: 4px 8px;
}
</style>
<p>This node is for manual control of Account Node intialisation.
The associated Account Node should have <em>Auto Init</em> turned off to use this node.</p>
<hr>
<h3><strong>Inputs</strong></h3>
<ul>
<li><strong>payload</strong>
<ul>
<li>with the <em>Initialise</em> option the payload can be the previous authentication result, enabling
automatic initialisation without the <em>File Path</em> setting (only in Proxy Auth Mode)</li>
</ul>
</li>
</ul>
<hr>
<h3><strong>Outputs</strong></h3>
<ul>
<li><strong>payload</strong>
<ul>
<li>with the <em>Initialise</em> option this is the authentication result that can be fed back into an Init
node for automatic initialisation (only in Proxy Auth Mode)</li>
</ul>
</li>
</ul>
<hr>
<h3><strong>Info</strong></h3>
<p>Instead of saving the the Authentication result to a file specified in the Account Config Node you can also manually
initialise the Account and save the Authentication result however you want. Here is an example of how you can do
that:</p>
<pre><code><div>[{"id":"bf44407a.c20d4","type":"alexa-remote-init","z":"c0bfc064.e8d26","name":"","account":"","option":"initialise","x":260,"y":2800,"wires":[["123e6678.5acbaa"]]},{"id":"c7f04444.fed188","type":"inject","z":"c0bfc064.e8d26","name":"","topic":"","payload":"alexa","payloadType":"flow","repeat":"","crontab":"00 12 * * 3,4,0","once":false,"onceDelay":0.1,"x":110,"y":2800,"wires":[["bf44407a.c20d4"]]},{"id":"123e6678.5acbaa","type":"change","z":"c0bfc064.e8d26","name":"","rules":[{"t":"set","p":"alexa","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":420,"y":2800,"wires":[[]]}]
</div></code></pre>
<hr>
<h3><strong>References</strong></h3>
<ul>
<li><a href="https://npmjs.com/package/node-red-contrib-alexa-remote2">npm</a> - the nodes npm repository</li>
<li><a href="https://github.com/586837r/node-red-contrib-alexa-remote2">GitHub</a> - the nodes GitHub repository
</li>
</ul>
</script>
<script type="text/javascript">
RED.nodes.registerType('alexa-remote-init', {
category: 'alexa',
color: '#6fbad8',
defaults: {
name: { value: '' },
account: { value: '', type: 'alexa-remote-account', required: true },
option: { value: 'initialise', required: true },
},
inputs: 1,
outputs: 1,
icon: 'alexa-remote-icon.png',
paletteLabel: 'Alexa Init',
label: function () {
if(this.name) return this.name;
switch(this.option) {
case 'initialise': return 'Initialise';
case 'fresh': return 'Fresh Authentication';
case 'refresh': return 'Refresh Cookie';
case 'update': return 'Update Cached State';
case 'reset': return 'Reset';
case 'interval': return 'Interval Info';
default: return 'Alexa Init';
}
},
labelStyle: function () {
return this.name ? "node_label_italic" : "";
},
/*
button: {
enabled: function() {
return !this.changed;
}
onclick: function() {
if (this.changed) {
return RED.notify(RED._("notification.warning", {message:RED._("notification.warnings.undeployedChanges")}),"warning");
}
$.ajax({
url: "alexa-remote-init/"+this.id,
type:"POST",
success: function(resp) {
RED.notify("Alexa Init Requested","success");
},
error: function(jqXHR,textStatus,errorThrown) {
if (jqXHR.status == 404) {
RED.notify(node._("common.notification.error",{message:node._("common.notification.errors.not-deployed")}),"error");
} else if (jqXHR.status == 500) {
RED.notify(node._("common.notification.error",{message:node._("inject.errors.failed")}),"error");
} else if (jqXHR.status == 0) {
RED.notify(node._("common.notification.error",{message:node._("common.notification.errors.no-response")}),"error");
} else {
RED.notify(node._("common.notification.error",{message:node._("common.notification.errors.unexpected",{status:jqXHR.status,message:textStatus})}),"error");
}
}
});
}
}
*/
});
</script>