UNPKG

node-red-contrib-grocy

Version:
113 lines (101 loc) 4.07 kB
<script type="text/javascript"> RED.nodes.registerType('grocy-batteries', { category: 'Grocy', color: '#73C5FF', defaults: { name: { value: "" }, server: { type: "grocy-config", required: true }, operation: { value: "getBatteries", required: true } }, inputs: 1, outputs: 1, icon: "grocy.svg", label: function () { return this.name || "Grocy Batteries"; }, paletteLabel: "Batteries", oneditprepare: function () { const node = this; // Battery operations const operations = [ { value: "getBatteries", label: "Get Batteries" }, { value: "getBatteryDetails", label: "Get Battery Details" }, { value: "chargeBattery", label: "Charge Battery" }, { value: "addBattery", label: "Add Battery" }, { value: "editBattery", label: "Edit Battery" }, { value: "deleteBattery", label: "Delete Battery" } ]; // Populate operation dropdown const $operationField = $('#node-input-operation'); operations.forEach(op => { $operationField.append($('<option>').val(op.value).text(op.label)); }); // Set current value $operationField.val(node.operation); } }); </script> <script type="text/html" data-template-name="grocy-batteries"> <div class="form-row"> <label for="node-input-name"><i class="fa fa-tag"></i> Name</label> <input type="text" id="node-input-name" placeholder="Name"> </div> <div class="form-row"> <label for="node-input-server"><i class="fa fa-server"></i> Server</label> <input type="text" id="node-input-server"> </div> <div class="form-row"> <label for="node-input-operation"><i class="fa fa-wrench"></i> Operation</label> <select id="node-input-operation"></select> </div> </script> <script type="text/html" data-help-name="grocy-batteries"> <p>A node to interact with Grocy batteries management.</p> <h3>Inputs</h3> <dl class="message-properties"> <dt>payload <span class="property-type">object</span></dt> <dd>The parameters required for the battery operation</dd> <dt>operation <span class="property-type">string</span></dt> <dd>(Optional) Override the operation specified in the node configuration</dd> <dt>options <span class="property-type">object</span></dt> <dd>(Optional) Additional options for certain operations like filters and sorting</dd> </dl> <h3>Outputs</h3> <dl class="message-properties"> <dt>payload <span class="property-type">object</span></dt> <dd>The result of the Grocy battery operation</dd> </dl> <h3>Details</h3> <p>This node provides access to Grocy's battery management functions, allowing you to track battery charging cycles.</p> <h4>Available Operations:</h4> <ul> <li><b>getBatteries</b> - Get all batteries</li> <li><b>getBatteryDetails</b> - Get details of a specific battery (requires batteryId)</li> <li><b>chargeBattery</b> - Log a battery charge (requires batteryId)</li> <li><b>addBattery</b> - Add a new battery (requires at least a name)</li> <li><b>editBattery</b> - Edit an existing battery (requires id)</li> <li><b>deleteBattery</b> - Delete a battery (requires id)</li> </ul> <h4>Example Usage:</h4> <p>To log a battery charge:</p> <pre> msg.payload = { batteryId: 1, data: { tracked_time: "2023-05-15 14:00:00" } }; return msg; </pre> <p>To add a new battery:</p> <pre> msg.payload = { name: "Living Room Remote", description: "TV remote control batteries", used_in: "TV Remote", charge_cycle_interval: 90 }; msg.operation = "addBattery"; return msg; </pre> </script>