UNPKG

node-red-contrib-smartnora

Version:

Google Smart Home integration via Smart Nora https://smart-nora.eu/

258 lines (256 loc) 11.4 kB
<script type="text/javascript"> RED.nodes.registerType('noraf-openclose', { category: 'nora', color: 'rgb(235, 227, 141)', icon: 'assistant.png', defaults: { devicename: { value: 'Open/Close Device', required: true, }, roomhint: { value: '' }, name: { value: '' }, directions: { value: '', }, openclosetype: { required: true, value: 'DOOR', }, passthru: { value: false, }, errorifstateunchaged: { value: false, }, discrete: { value: true, }, lockunlock: { value: false, }, commandonly: { value: false, }, queryonly: { value: false, }, nora: { type: 'noraf-config', required: true }, topic: { value: '' }, openvalue: { value: true, required: true, validate: (RED.validators.hasOwnProperty('typedInput') ? RED.validators.typedInput( 'openvalueType') : function (v) { return true }) }, openvalueType: { value: 'bool' }, closevalue: { value: false, required: true, validate: (RED.validators.hasOwnProperty('typedInput') ? RED.validators.typedInput( 'closevalueType') : function (v) { return true }) }, closevalueType: { value: 'bool' }, twofactor: { value: 'off', }, twofactorpin: { value: '' }, filter: { value: false, }, }, inputs: 1, outputs: 1, paletteLabel: 'open/close', label: function () { return this.name || this.devicename || 'open/close'; }, oneditprepare: function () { var availableDirections = ['UP', 'DOWN', 'LEFT', 'RIGHT', 'IN', 'OUT']; var row; var directions = this.directions && this.directions.split(',') || []; availableDirections.forEach(function (direction, index) { var rowIndex = Math.floor(index / 3); if (index % 3 === 0) { $('#directions-container').append( '<div class="directions-row" directions-row-index="' + rowIndex + '"></div>' ); } $('[directions-row-index=' + rowIndex + ']').append( '<div class="directions-item">' + '<input type="checkbox" ' + (directions.indexOf(direction) >= 0 ? 'checked ' : '') + (direction === 'off' ? 'disabled ' : '') + 'class="open-close-direction" data-direction="' + direction + '" id="direction-' + direction + '">' + '<label for="direction-' + direction + '">' + direction.substring(0, 1) + direction.substring(1).toLowerCase() + '</label>' + '</div>' ); }); $('.open-close-direction, #node-input-discrete, #node-input-lockunlock').on('change', function () { var showPredefinedValues = $('.open-close-direction:checked').length === 0 && $('#node-input-discrete').is(':checked') && !$('#node-input-lockunlock').is(':checked'); if (showPredefinedValues) { $('.openclose-value').show(); } else { $('.openclose-value').hide(); } }); $('#node-input-openvalue').typedInput({ default: 'bool', typeField: $("#node-input-openvalueType"), types: ['str', 'num', 'bool', 'json', 'bin', 'date'] }); $('#node-input-closevalue').typedInput({ default: 'bool', typeField: $("#node-input-closevalueType"), types: ['str', 'num', 'bool', 'json', 'bin', 'date'] }); $('#node-input-twofactor').change(function () { if ($(this).val() === 'pin') { $('#node-twofactor-pin').show(); } else { $('#node-twofactor-pin').hide(); } }); }, oneditsave: function () { var directions = []; $('.open-close-direction:checked').each(function () { directions.push($(this).attr('data-direction')); }); this.directions = directions.join(','); }, }); </script> <script type="text/x-red" data-template-name="noraf-openclose"> <style> .directions-row { display: flex; flex-direction:row; } .directions-item { display:flex; flex-direction:row; } #directions-container { display:flex; flex-direction:column; } </style> <div class="form-row"> <label for="node-input-nora"><i class="fa fa-table"></i> Config</label> <input type="text" id="node-input-nora"> </div> <div class="form-row"> <label for="node-input-devicename"><i class="fa fa-i-cursor"></i> Device Name</label> <input type="text" id="node-input-devicename"> </div> <div class="form-row"> <label for="node-input-openclosetype"><i class="fa fa-question-sign"></i> Type</label> <select id="node-input-openclosetype"> <option value="CLOSET">Closet</option> <option value="AWNING">Awning</option> <option value="CURTAIN">Curtain</option> <option value="DOOR">Door</option> <option value="DRAWER">Drawer</option> <option value="BLINDS">Blinds</option> <option value="GARAGE">Garage</option> <option value="GATE">Gate</option> <option value="PERGOLA">Pergola</option> <option value="SHUTTER">Shutter</option> <option value="VALVE">Valve</option> <option value="WINDOW">Window</option> </select> </div> <div class="form-row d-flex flex-column"> <label style="width:100%"><i class="fa fa-cog"></i> Supported <a style="text-decoration: underline;" target="_blank" href="https://developers.google.com/assistant/smarthome/traits/openclose#device-states">Open/Close directions</a> (default: all unchecked). Will be used as a message topic on input/receive msg</label> <div id="directions-container"></div> </div> <div class="form-row"> <label style="width:auto" for="node-input-passthru"><i class="fa fa-arrow-right"></i> If <code>msg</code> arrives on input, pass through to output: </label> <input type="checkbox" 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-filter"><i class="fa fa-filter"></i> Ignore input messages that don't match the <code>topic</code> value: </label> <input type="checkbox" id="node-input-filter" style="display:inline-block; width:auto; vertical-align:top;"> </div> <div class="form-row"> <label style="width:auto" for="node-input-errorifstateunchaged"><i class="fa fa-exclamation-triangle"></i> Warn user if already open/closed: </label> <input type="checkbox" id="node-input-errorifstateunchaged" style="display:inline-block; width:auto; vertical-align:top;"> </div> <div class="form-row"> <label style="width:auto" for="node-input-discrete"><i class="fa fa-arrow-right"></i> Discrete only open/close: </label> <input type="checkbox" id="node-input-discrete" style="display:inline-block; width:auto; vertical-align:top;"> </div> <div class="form-row"> <label style="width:auto" for="node-input-commandonly"><i class="fa fa-exchange"></i> Can only handle commands: </label> <input type="checkbox" id="node-input-commandonly" style="display:inline-block; width:auto; vertical-align:top;"> </div> <div class="form-row"> <label style="width:auto" for="node-input-queryonly"><i class="fa fa-exchange"></i> Can only respond to queries (sensor): </label> <input type="checkbox" id="node-input-queryonly" style="display:inline-block; width:auto; vertical-align:top;"> </div> <div class="form-row openclose-value"> <label for="node-input-openvalue" style="padding-left:10px; margin-right:-10px">Open Payload</label> <input type="text" id="node-input-openvalue" style="width:70%"> <input type="hidden" id="node-input-openvalueType"> </div> <div class="form-row openclose-value"> <label for="node-input-closevalue" style="padding-left:10px; margin-right:-10px">Close Payload</label> <input type="text" id="node-input-closevalue" style="width:70%"> <input type="hidden" id="node-input-closevalueType"> </div> <div class="form-row"> <label style="width:auto" for="node-input-lockunlock"><i class="fa fa-lock"></i> Support <a style="text-decoration: underline;" target="_blank" href="https://developers.google.com/assistant/smarthome/traits/lockunlock">Lock/Unlock</a>: </label> <input type="checkbox" id="node-input-lockunlock" style="display:inline-block; width:auto; vertical-align:top;"> </div> <div class="form-row"> <label for="node-input-roomhint"><i class="fa fa-i-cursor"></i> Room Hint </label> <input type="text" id="node-input-roomhint"> </div> <div class="form-row"> <label for="node-input-twofactor"><i class="fa fa-question-sign"></i> Two Factor</label> <select id="node-input-twofactor"> <option value="off">None</option> <option value="ack">Acknowledge</option> <option value="pin">Pin</option> </select> </div> <div id="node-twofactor-pin" class="form-row"> <label for="node-input-twofactorpin"><i class="fa fa-code"></i> Pin</label> <input type="text" id="node-input-twofactorpin"> </div> <div class="form-row"> <label for="node-input-topic" style="padding-left:15px; margin-right:-15px">Topic</label> <input type="text" id="node-input-topic" style="width:70%"> </div> <div class="form-row"> <label for="node-input-name"><i class="fa fa-tag"></i> Name</label> <input type="text" id="node-input-name"> </div> </script> <script type="text/x-red" data-help-name="noraf-openclose"> <p> <a href="https://github.com/andrei-tatar/node-red-contrib-smartnora/blob/master/doc/nodes/openclose/README.md">https://github.com/andrei-tatar/node-red-contrib-smartnora/blob/master/doc/nodes/openclose/README.md</a> </p> </script>