Advertisement
Guest User

Untitled

a guest
Jun 6th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 'use strict';
  2.  
  3. const config = {
  4.   // directory for files generated by emulator
  5.   tmpDirectory: './tmp',
  6.  
  7.   // only used with switch --store-log-to-database
  8.   database: {
  9.     host: 'localhost',
  10.     port: 3307,
  11.     user: 'root',
  12.     password: '',
  13.     database: 'ngwcs'
  14.   },
  15.  
  16.   logLevel: 'TRACE',
  17.   // TODO
  18.   // logFile: './temp/default.log',
  19.  
  20.   // device state file (overriden by command line)
  21.   // if not present generated to temp directory in format [serialNumber].json
  22.   // deviceStateFile: './temp/default.json',
  23.  
  24.   /**
  25.    * Default state of device at first boot
  26.    *
  27.    * state is used to store persistent data and state of emulated machine
  28.    */
  29.   defaultDeviceState: {
  30.     // Factory-default ytun configuration
  31.     ytunHost: 'ytun2.jablotron.cz', // required
  32.     ytunPort: 8087, // required
  33.  
  34.     /**
  35.      * Variables for complex behavior not emulated, but simply mocked
  36.      */
  37.     allowRegister: true,
  38.  
  39.     /**
  40.      * Set by data enable command sent at registration
  41.      * false - no state data send to application (application has no entries for this location and cannot store values)
  42.      * true - sending state data
  43.      */
  44.     dataEnable: true,
  45.  
  46.     // identifier of structure in varState; mismatch with identifier on application side will trigger synchronization
  47.     // of varState to application
  48.     structureId: 1,
  49.  
  50.     // State of device
  51.     varState: {
  52.       // location = root object - object_id of this object translates to serial number
  53.       /**
  54.        * Ids of objects are 4 bytes long. 'location' is root object whitch has
  55.        * same objectId as serial number of location, for better readability it is named 'location' in config
  56.        */
  57.       'location': {
  58.         '_type': 'location',
  59.         '_rooms': ['0x010A0000', '0x020A0000'], // objectIds of child objects
  60.         '_devices': ['0x000A0000'], // objectIds of child objects
  61.         'hc_mode': {
  62.           value: 0, // HEATING
  63.           time: new Date()
  64.         },
  65.         'vacation': {
  66.           value: false,
  67.           time: new Date()
  68.         },
  69.         'vacation_end_time': {
  70.           value: null,
  71.           time: new Date()
  72.         },
  73.         'standby': {
  74.           value: 0,
  75.           time: new Date()
  76.         }
  77.       },
  78.       /**
  79.        * Rooms are connected to device with same bottom three bytes in id and zero top byte.
  80.        * Room with id 0x01120FBA belongs to device with id 0x00120FBA and it is 12th room on that device
  81.        */
  82.       '0x000A0000': {
  83.         '_type': 'device',
  84.         'name': {
  85.           value: 'Living room and Bedroom',
  86.           time: new Date()
  87.         },
  88.         'status': {
  89.           value: Math.floor(new Date().getTime() / 1000), // disconnected now
  90.           time: new Date()
  91.         }
  92.       },
  93.       '0x010A0000': {
  94.         '_type': 'room',
  95.         'name': {
  96.           value: 'Badroom',
  97.           time: new Date()
  98.         },
  99.         'air_temp': {
  100.           value: 21.2,
  101.           time: new Date()
  102.         },
  103.         'floor_temp': {
  104.           value: 20.3,
  105.           time: new Date()
  106.         },
  107.         'humidity': {
  108.           value: 64,
  109.           time: new Date()
  110.         },
  111.         'tmp_ctrl.heat.temp_set_party': {
  112.           value: 22,
  113.           time: new Date()
  114.         },
  115.         'tmp_ctrl.cool.temp_set_party': {
  116.           value: 22,
  117.           time: new Date()
  118.         },
  119.         'tmp_ctrl.heat.temp_set_adjusted': {
  120.           value: 16.5,
  121.           time: new Date()
  122.         },
  123.         'tmp_ctrl.cool.temp_set_adjusted': {
  124.           value: 16.5,
  125.           time: new Date()
  126.         },
  127.         'tmp_ctrl.heat.temp_set_manual': {
  128.           value: 22,
  129.           time: new Date()
  130.         },
  131.         'tmp_ctrl.cool.temp_set_manual': {
  132.           value: 22,
  133.           time: new Date()
  134.         },
  135.         'tmp_ctrl.heat.temp_set_eco': {
  136.           value: 16.5,
  137.           time: new Date()
  138.         },
  139.         'tmp_ctrl.cool.temp_set_eco': {
  140.           value: 10.5,
  141.           time: new Date()
  142.         },
  143.         'tmp_ctrl.heat.temp_set_comfort': {
  144.           value: 22,
  145.           time: new Date()
  146.         },
  147.         'tmp_ctrl.cool.temp_set_comfort': {
  148.           value: 18,
  149.           time: new Date()
  150.         },
  151.         'tmp_ctrl.heat.temp_set_extra_comfort': {
  152.           value: 27.5,
  153.           time: new Date()
  154.         },
  155.         'tmp_ctrl.cool.temp_set_extra_comfort': {
  156.           value: 25.5,
  157.           time: new Date()
  158.         },
  159.         'tmp_ctrl.heat.floor_temp_limit_min_eco': {
  160.           value: 12,
  161.           time: new Date()
  162.         },
  163.         'tmp_ctrl.heat.floor_temp_limit_max_eco': {
  164.           value: 14,
  165.           time: new Date()
  166.         },
  167.         'tmp_ctrl.heat.floor_temp_limit_min_extra_comfort': {
  168.           value: 12,
  169.           time: new Date()
  170.         },
  171.         'tmp_ctrl.heat.floor_temp_limit_max_extra_comfort': {
  172.           value: 12,
  173.           time: new Date()
  174.         },
  175.         'tmp_ctrl.heat.floor_temp_limit_min_comfort': {
  176.           value: 12,
  177.           time: new Date()
  178.         },
  179.         'tmp_ctrl.heat.floor_temp_limit_max_comfort': {
  180.           value: 12,
  181.           time: new Date()
  182.         },
  183.         'tmp_ctrl.cool.temp_hysteresis': {
  184.           value: 10,
  185.           time: new Date()
  186.         },
  187.         'tmp_ctrl.heat.temp_hysteresis': {
  188.           value: 10,
  189.           time: new Date()
  190.         },
  191.         'tmp_ctrl.heat.floor_temp_hysteresis': {
  192.           value: 14,
  193.           time: new Date()
  194.         },
  195.         'hum_ctrl.hum_hysteresis': {
  196.           value: 15,
  197.           time: new Date()
  198.         }
  199.       },
  200.       '0x020A0000': {
  201.         '_type': 'room',
  202.         'name': {
  203.           value: 'Bedroom',
  204.           time: new Date()
  205.         },
  206.         'air_temp': {
  207.           value: 21.7,
  208.           time: new Date()
  209.         },
  210.         'floor_temp': {
  211.           value: 20.8,
  212.           time: new Date()
  213.         },
  214.         'humidity': {
  215.           value: 64,
  216.           time: new Date()
  217.         },
  218.         'tmp_ctrl.heat.temp_set_party': {
  219.           value: 22,
  220.           time: new Date()
  221.         },
  222.         'tmp_ctrl.cool.temp_set_party': {
  223.           value: 22,
  224.           time: new Date()
  225.         },
  226.         'tmp_ctrl.heat.temp_set_adjusted': {
  227.           value: 16.5,
  228.           time: new Date()
  229.         },
  230.         'tmp_ctrl.cool.temp_set_adjusted': {
  231.           value: 16.5,
  232.           time: new Date()
  233.         },
  234.         'tmp_ctrl.heat.temp_set_manual': {
  235.           value: 22,
  236.           time: new Date()
  237.         },
  238.         'tmp_ctrl.cool.temp_set_manual': {
  239.           value: 22,
  240.           time: new Date()
  241.         },
  242.         'tmp_ctrl.heat.temp_set_eco': {
  243.           value: 16.5,
  244.           time: new Date()
  245.         },
  246.         'tmp_ctrl.cool.temp_set_eco': {
  247.           value: 10.5,
  248.           time: new Date()
  249.         },
  250.         'tmp_ctrl.heat.temp_set_comfort': {
  251.           value: 22,
  252.           time: new Date()
  253.         },
  254.         'tmp_ctrl.cool.temp_set_comfort': {
  255.           value: 18,
  256.           time: new Date()
  257.         },
  258.         'tmp_ctrl.heat.temp_set_extra_comfort': {
  259.           value: 27.5,
  260.           time: new Date()
  261.         },
  262.         'tmp_ctrl.cool.temp_set_extra_comfort': {
  263.           value: 25.5,
  264.           time: new Date()
  265.         },
  266.         'tmp_ctrl.heat.floor_temp_limit_min_eco': {
  267.           value: 12,
  268.           time: new Date()
  269.         },
  270.         'tmp_ctrl.heat.floor_temp_limit_max_eco': {
  271.           value: 14,
  272.           time: new Date()
  273.         },
  274.         'tmp_ctrl.heat.floor_temp_limit_min_extra_comfort': {
  275.           value: 12,
  276.           time: new Date()
  277.         },
  278.         'tmp_ctrl.heat.floor_temp_limit_max_extra_comfort': {
  279.           value: 12,
  280.           time: new Date()
  281.         },
  282.         'tmp_ctrl.heat.floor_temp_limit_min_comfort': {
  283.           value: 12,
  284.           time: new Date()
  285.         },
  286.         'tmp_ctrl.heat.floor_temp_limit_max_comfort': {
  287.           value: 12,
  288.           time: new Date()
  289.         },
  290.         'tmp_ctrl.cool.temp_hysteresis': {
  291.           value: 10,
  292.           time: new Date()
  293.         },
  294.         'tmp_ctrl.heat.temp_hysteresis': {
  295.           value: 10,
  296.           time: new Date()
  297.         },
  298.         'tmp_ctrl.heat.floor_temp_hysteresis': {
  299.           value: 14,
  300.           time: new Date()
  301.         },
  302.         'hum_ctrl.hum_hysteresis': {
  303.           value: 15,
  304.           time: new Date()
  305.         }
  306.       }
  307.     }
  308.   },
  309.  
  310.   simulations: [
  311.     {
  312.       count: 0, // 0 - infinity
  313.       delay: 8 * 1000, // delay time for one run, interval time for multiple runs
  314.       action: function (location) {
  315.         /**
  316.          * Simulate random air_temp, floor_temp and humidity change on each room every 8 seconds
  317.          */
  318.         let objects = location.listObjects();
  319.         for (let i in objects) {
  320.           if (objects[i]['_type'] === 'room') {
  321.             location.set(i, 'air_temp', Math.floor(Math.random() * 40) / 10 + 20);
  322.             location.set(i, 'floor_temp', Math.floor(Math.random() * 40) / 10 + 21);
  323.             location.set(i, 'humidity', Math.floor(Math.random() * 40) + 50);
  324.           }
  325.         }
  326.         location.set('0x000A0000', 'status', 1);
  327.         location.send('changed', null, 500)  // send all changed after 0.5 s
  328.           .catch(e => {
  329.             console.log(e);
  330.           });
  331.       }
  332.     }
  333.   ],
  334.  
  335.   /**
  336.    * Actions provided in config.example.js are defaults
  337.    * For onValue methods default is simply saving value
  338.    */
  339.   interactions: {
  340.     onConnect: function (location) {
  341.       // synchronization of state to application - for correct work must be executed
  342.       let forceSyncStrcuture = false;
  343.       location.sync(forceSyncStrcuture).then(() => {
  344.         location.set('0x010A0000', 'tmp_ctrl.temp_desired', 16.5);
  345.         location.send('changed', 1 * 1000)
  346.           .catch(e => {
  347.             console.log(e);
  348.           });
  349.       });
  350.     },
  351.     onValue: {
  352.       // location
  353.       'location': {
  354.         'name': function (location, objectId, value) {
  355.           location.set(objectId, 'name', value);
  356.           location.send('changed', 1 * 1000)
  357.             .catch(e => {
  358.               console.log(e);
  359.             });
  360.         }
  361.       },
  362.  
  363.       // rooms
  364.       'room': {
  365.         'name': function (location, objectId, value) {
  366.           location.set(objectId, 'name', value);
  367.         },
  368.         'tmp_ctrl.heat.temp_set_eco': function (location, objectId, value) {
  369.           // custom implementation
  370.           location.set(objectId, 'tmp_ctrl.heat.temp_set_eco', value);
  371.           location.set(objectId, 'tmp_ctrl.temp_desired', value - 1.5);
  372.           location.send('changed', 500)
  373.             .catch(e => {
  374.               console.log(e);
  375.             });
  376.         }
  377.       }
  378.     },
  379.     onDataEnable: function (location, enabled) {
  380.       // if data were enabled
  381.       if (enabled) {
  382.         // synchronization of state to application - for correct work must be executed
  383.         location.sync(true);
  384.       }
  385.     }
  386.   }
  387. };
  388.  
  389. module.exports = config;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement