Explorar el Código

add getVersion

Luigi Cisana hace 7 años
padre
commit
cc9f9bb110
Se han modificado 2 ficheros con 26 adiciones y 8 borrados
  1. 3 5
      README.md
  2. 23 3
      ramp-thermostat/ramp-thermostat.js

+ 3 - 5
README.md

@@ -19,13 +19,11 @@ The hysteresis is used to prevent osciliation. The `[+]` value is added to the t
 
 ### Usage
 
-This node expects a numeric msg.payload containing the current temperature.
-The msg.topic should be `empty` or set to `setCurrent`. 
-It will calculate the target temperature depending on msg.payload at the current time and output 3 values:
+This node expects a numeric msg.payload containing the current temperature (number). The msg.topic should be `empty` or set to `setCurrent`. It will calculate the target temperature depending on msg.payload at the current time and output 3 values:
 
 * state (boolean)
-* current temperature
-* target temperature
+* current temperature (number)
+* target temperature (number)
 
 The state (true/false) is used to control an actuator. The current and target temperature outputs can be wired e.g. into an ui_chart node.
 

+ 23 - 3
ramp-thermostat/ramp-thermostat.js

@@ -1,6 +1,9 @@
+"use strict";
+var fs = require('fs');
+var path = require('path');
+
 module.exports = function(RED) {
-  "use strict";
-  
+
   function Profile(n) {
     RED.nodes.createNode(this,n);
     this.n = n;
@@ -14,6 +17,9 @@ module.exports = function(RED) {
     var node_name = this.name.replace(" ", "_");
     var globalContext = this.context().global;
     
+    //this.node_version = readNodeVersion();
+    //this.log(" version "+node_version);
+    
     // experimental
     //this.profile = globalContext.get(node_name);
     
@@ -86,12 +92,18 @@ module.exports = function(RED) {
                   result.status = {fill:"green",shape:"dot",text:"profile set to default ("+this.profile.name+")"};
                 }
                 globalContext.set(node_name, this.profile);
-                this.status(result.status); 
+                this.status(result.status);
               } else {
                 this.warn(msg.payload+" not found");
               }
               break;
               
+            case "getVersion":
+              var version = readNodeVersion();
+              this.warn("version: "+version);
+              this.status({fill:"green",shape:"dot",text:"version: "+version});
+              break;
+              
             default:
               this.warn("invalid topic >"+msg.topic+"<");
           }
@@ -263,4 +275,12 @@ module.exports = function(RED) {
     points = JSON.parse(points_str);
     return points;
   }
+  
+  function readNodeVersion () {
+    var package_json = "../package.json";
+    //console.log(__dirname+" - "+package_json);
+    var packageJSONPath = path.join(__dirname, package_json);
+    var packageJSON = JSON.parse(fs.readFileSync(packageJSONPath));
+    return packageJSON.version;
+  }
 }