UNPKG

node-red-contrib-dyson-purelink

Version:
110 lines (100 loc) 4.15 kB
<script type="text/javascript"> let node = this; RED .nodes .registerType('dyson-config', { category: 'config', defaults: { username: { value: "" }, password: { value: "" }, otp: { value: "" }, country: { value: "" } }, label: function () { if (this.name) { return this.name; } return "Config"; }, oneditprepare() { const node = this; $("#node-config-input-password").change(() => { node.password = $("#node-config-input-password").val() }) $("#node-config-input-country").change(() => { node.country = $("#node-config-input-country").val() }) $("#node-config-input-username").change(() => { node.username = $("#node-config-input-username").val() }) $("#node-config-input-otp").change(() => { node.otp = $("#node-config-input-otp").val() }) $("#authenticate").click(function (event) { event.preventDefault(); $.post('dyson/authenticate', { username: node.username, password: node.password, country: node.country }, function (data) { $("#node-config-input-otp").val('') }); }); $("#verify").click(function (event) { event.preventDefault(); $.post('dyson/verify', { username: node.username, password: node.password, country: node.country, otp: node.otp }, function (data) { }); }); } }); </script> <script type="text/x-red" data-template-name="dyson-config"> <div class="form-row"> <label for="node-config-input-username" style="width:160px !important"> <i class="fa fa-user"></i> <span>E-Mail:</span></label> <input type="text" id="node-config-input-username" placeholder="" style="width:280px !important"> </div> <div class="form-row"> <label for="node-config-input-password" style="width:160px !important"> <i class="fa fa-key"></i> <span>Password:</span></label> <input type="password" id="node-config-input-password" placeholder="" style="width:280px !important"> </div> <div class="form-row"> <label for="node-config-input-country" style="width:160px !important"> <i class="fa fa-flag"></i> <span>Country:</span></label> <input type="text" id="node-config-input-country" placeholder="US" style="width:280px !important"> </div> <div class="form-row"> <button id="authenticate">authenticate to get otp</button> </div> <div class="form-tips"> <i class="fa fa-exclamation"></i> <b>IMPORTANT:</b> Open the Dyson App on your phone <b>before</b> authenticating. </div> <div class="form-row"> <label for="node-config-input-otp" style="width:160px !important"> <i class="fa fa-key"></i> <span>one time password (otp code via e-Mail):</span></label> <input type="text" id="node-config-input-otp" placeholder="" style="width:280px !important"> </div> <div class="form-row"> <button id="verify">verify</button> </div> <div class="form-tips"> <i class="fa fa-exclamation"></i> <b>IMPORTANT:</b> Deploy the node, <b>before</b> searching for devices. </div> </script> <script type="text/x-red" data-help-name="dyson-config"> <p>Configuration</p> - E-Mail: dyson E-Mail - Password: dyson Password - Country: Country-Code (US,DE,AT,GB,...) </script>