Skip to content

Commit

Permalink
Transform config to new format for compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
Yurkin Vitaliy committed Mar 22, 2018
1 parent e11740c commit eb82ffc
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 33 deletions.
73 changes: 41 additions & 32 deletions modules/ScheduledScene/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*** ScheduledScene Z-Way HA module *******************************************
Version: 2.2.1
(c) Z-Wave.Me, 2017
Version: 2.2.2
(c) Z-Wave.Me, 2018
-----------------------------------------------------------------------------
Author: Serguei Poltorak <[email protected]>, Niels Roche <[email protected]>, Yurkin Vitaliy <[email protected]>
Author: Hans-Christian Göckeritz <[email protected]>
Expand Down Expand Up @@ -32,15 +32,50 @@ ScheduledScene.prototype.init = function (config) {

var self = this;

/**** TRANSFORM OLD CONFIG FROM 2.1.2 TO 2.2.1 VERSION ****/
var needToSaveConfig = false;

if (self.config.switches) {
self.config.devices.switches = self.config.switches;
delete self.config.switches;
needToSaveConfig = true;
}
if (self.config.dimmers) {
self.config.devices.dimmers = self.config.dimmers;
delete self.config.dimmers;
needToSaveConfig = true;
}
if (self.config.thermostats) {
self.config.devices.thermostats = self.config.thermostats;
delete self.config.thermostats;
needToSaveConfig = true;
}
if (self.config.scenes) {
self.config.devices.scenes = self.config.scenes;
delete self.config.scenes;
needToSaveConfig = true;
}
if (self.config.locks) {
self.config.devices.locks = self.config.locks;
delete self.config.locks;
needToSaveConfig = true;
}
if (self.config.time) {
self.config.times = [];
self.config.times.push(self.config.time);
delete self.config.time;
needToSaveConfig = true;
}
if (needToSaveConfig) {
self.saveConfig();
}
/***********************************************************/

this.runScene = function() {
var switchesArray;
if (_.isArray(self.config.devices.switches)) {
switchesArray = self.config.devices.switches;
}
// compatibility configuration to version 2.2
if (_.isArray(self.config.switches)) {
switchesArray = self.config.switches;
}

if (switchesArray) {
switchesArray.forEach(function(devState) {
Expand All @@ -57,10 +92,6 @@ ScheduledScene.prototype.init = function (config) {
if (_.isArray(self.config.devices.thermostats)) {
thermostatsArray = self.config.devices.thermostats;
}
// compatibility configuration to version 2.2
if (_.isArray(self.config.thermostats)) {
thermostatsArray = self.config.thermostats;
}

if (thermostatsArray) {
thermostatsArray.forEach(function(devState) {
Expand All @@ -77,10 +108,6 @@ ScheduledScene.prototype.init = function (config) {
if (_.isArray(self.config.devices.dimmers)) {
dimmersArray = self.config.devices.dimmers;
}
// compatibility configuration to version 2.2
if (_.isArray(self.config.dimmers)) {
dimmersArray = self.config.dimmers;
}

if (dimmersArray) {
dimmersArray.forEach(function(devState) {
Expand All @@ -97,10 +124,6 @@ ScheduledScene.prototype.init = function (config) {
if (_.isArray(self.config.devices.locks)) {
locksArray = self.config.devices.locks;
}
// compatibility configuration to version 2.2
if (_.isArray(self.config.locks)) {
locksArray = self.config.locks;
}

if (locksArray) {
locksArray.forEach(function(devState) {
Expand All @@ -117,10 +140,6 @@ ScheduledScene.prototype.init = function (config) {
if (_.isArray(self.config.devices.scenes)) {
scenesArray = self.config.devices.scenes;
}
// compatibility configuration to version 2.2
if (_.isArray(self.config.scenes)) {
scenesArray = self.config.scenes;
}

if (scenesArray) {
scenesArray.forEach(function(scene) {
Expand Down Expand Up @@ -154,16 +173,6 @@ ScheduledScene.prototype.init = function (config) {
});
});
}
// compatibility configuration to version 2.2
else {
self.controller.emit("cron.addTask", "scheduledScene.run."+self.id, {
minute: parseInt(self.config.time.split(":")[1], 10),
hour: parseInt(self.config.time.split(":")[0], 10),
weekDay: wd,
day: null,
month: null
});
}
});
};

Expand Down
2 changes: 1 addition & 1 deletion modules/ScheduledScene/module.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"homepage": "http://razberry.z-wave.me",
"icon": "icon.png",
"moduleName":"ScheduledScene",
"version": "2.2.1",
"version": "2.2.2",
"maturity": "stable",
"repository": {
"type": "git",
Expand Down

0 comments on commit eb82ffc

Please sign in to comment.