special-devices.js 7.07 KiB
/*
answer:"special",
triggers:{zone-scene:[{group:1,scene:1,name:[{de_DE:'dingsa'}]},{group:0,scene:2},{zone:0,scene:3}],
          device:[{id:0,name:[{de_DE:'dingsa'}]}], // device click events
          sensor-event:[{id:'.0',value:'inactive',name:[{de_DE:'dingsa'}]}],  // akm event
          device-event:[{id:'eventXY',name:[{de_DE:'dingsa'}]}]}, // sensor event
actions:{ zone-action:[{scene:1,group:1,name:[{de_DE:'dingsa'}]},{group:0,scene:2},{zone:0,scene:3}]
          device-action:[{scene:1,name:[{de_DE:'dingsa'}]},
                         {outputValue:1,name:[{de_DE:'dingsa'}]}]
conditions:{
	   sensor-event:[{}]}
}*/
var lWarn = {
	logln : function(o) {
var lInfo = {
	logln : function(o) {
var LOGFILE_NAME = "sr-config.log";
lWarn = new Logger(LOGFILE_NAME);
lInfo = new Logger(LOGFILE_NAME)
Property.setSavedProperty = function(path, value) {
	Property.setProperty(path, value);
	Property.setFlag(path, 'ARCHIVE', true);
try {
	if (raisedEvent.name == 'system-addon-scene-responder.iterateSpecialDevices') {
		lInfo.logln('fetch for gtin ' + raisedEvent.parameter.gtin);
		var h = new HTTP({
			'debug' : 0
		}, {});
		var code = h.get("http://illuminant-wizard.aizo.net/specialDevices.php?gtin=" + raisedEvent.parameter.gtin);
		if (code.status.valueOf() === 200) {
			lInfo.logln(code.body);
			var DataObject = JSON.parse(code.body);
			if (DataObject.answer != 'nospecial') {
				if (DataObject.actions != null) {
					if (DataObject.actions['zone-action'] != null) {
						for (var iIndex = 0; iIndex < DataObject.actions['zone-action'].length; iIndex++) {
							var oDataObject = DataObject.actions['zone-action'][iIndex];
							for ( var sKey in oDataObject.name) {
								Property.setSavedProperty('specialDevices/' + raisedEvent.parameter.gtin + '/actions/zoneAction/' + iIndex + '/name/' + sKey, oDataObject.name[sKey]);
							Property.setSavedProperty('specialDevices/' + raisedEvent.parameter.gtin + '/actions/zoneAction/' + iIndex + '/scene', oDataObject.scene);
							if (oDataObject.zone != null)
								Property.setSavedProperty('specialDevices/' + raisedEvent.parameter.gtin + '/actions/zoneAction/' + iIndex + '/zone', oDataObject.zone);
							if (oDataObject.group != null)
								Property.setSavedProperty('specialDevices/' + raisedEvent.parameter.gtin + '/actions/zoneAction/' + iIndex + '/group', oDataObject.group);
					if (DataObject.actions['device-action'] != null) {
						for (var iIndex = 0; iIndex < DataObject.actions['device-action'].length; iIndex++) {
							var oDataObject = DataObject.actions['device-action'][iIndex];
							lInfo.logln('action ' + JSON.stringify(oDataObject));
							for ( var sKey in oDataObject.name) {
								Property.setSavedProperty('specialDevices/' + raisedEvent.parameter.gtin + '/actions/deviceActions/' + iIndex + '/name/' + sKey, oDataObject.name[sKey]);
							if (oDataObject.scene != null)
								Property.setSavedProperty('specialDevices/' + raisedEvent.parameter.gtin + '/actions/deviceActions/' + iIndex + '/scene', oDataObject.scene);
							if (oDataObject.outputValue != null)
7172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
Property.setSavedProperty('specialDevices/' + raisedEvent.parameter.gtin + '/actions/deviceActions/' + iIndex + '/outputValue', oDataObject.outputValue); } } } if (DataObject.triggers != null) { if (DataObject.triggers['zone-scene'] != null) { for (var iIndex = 0; iIndex < DataObject.triggers['zone-scene'].length; iIndex++) { var oDataObject = DataObject.triggers['zone-scene'][iIndex]; for ( var sKey in oDataObject.name) { Property.setSavedProperty('specialDevices/' + raisedEvent.parameter.gtin + '/triggers/zoneSzene/' + iIndex + '/name/' + sKey, oDataObject.name[sKey]); } Property.setSavedProperty('specialDevices/' + raisedEvent.parameter.gtin + '/triggers/zoneSzene/' + iIndex + '/scene', oDataObject.scene); if (oDataObject.zone != null) Property.setSavedProperty('specialDevices/' + raisedEvent.parameter.gtin + '/triggers/zoneSzene/' + iIndex + '/zone', oDataObject.zone); if (oDataObject.group != null) Property.setSavedProperty('specialDevices/' + raisedEvent.parameter.gtin + '/triggers/zoneSzene/' + iIndex + '/group', oDataObject.group); } } if (DataObject.triggers['device'] != null) { for (var iIndex = 0; iIndex < DataObject.triggers['device'].length; iIndex++) { var oDataObject = DataObject.triggers['device'][iIndex]; Property.setSavedProperty('specialDevices/' + raisedEvent.parameter.gtin + '/triggers/deviceMsg/' + iIndex + '/id', oDataObject.id); for ( var sKey in oDataObject.name) { Property.setSavedProperty('specialDevices/' + raisedEvent.parameter.gtin + '/triggers/deviceMsg/' + iIndex + '/name/' + sKey, oDataObject.name[sKey]); } } } if (DataObject.triggers['sensor-event'] != null) { for (var iIndex = 0; iIndex < DataObject.triggers['sensor-event'].length; iIndex++) { var oDataObject = DataObject.triggers['sensor-event'][iIndex]; Property.setSavedProperty('specialDevices/' + raisedEvent.parameter.gtin + '/triggers/sensorEvent/' + iIndex + '/id', oDataObject.id); Property.setSavedProperty('specialDevices/' + raisedEvent.parameter.gtin + '/triggers/sensorEvent/' + iIndex + '/value', oDataObject.value); for ( var sKey in oDataObject.name) { Property.setSavedProperty('specialDevices/' + raisedEvent.parameter.gtin + '/triggers/sensorEvent/' + iIndex + '/name/' + sKey, oDataObject.name[sKey]); } } } if (DataObject.triggers['device-event'] != null) { for (var iIndex = 0; iIndex < DataObject.triggers['device-event'].length; iIndex++) { var oDataObject = DataObject.triggers['device-event'][iIndex]; Property.setSavedProperty('specialDevices/' + raisedEvent.parameter.gtin + '/triggers/deviceEvents/' + iIndex + '/id', oDataObject.id); for ( var sKey in oDataObject.name) { Property.setSavedProperty('specialDevices/' + raisedEvent.parameter.gtin + '/triggers/deviceEvents/' + iIndex + '/name/' + sKey, oDataObject.name[sKey]); } } } } Property.store(); } } } if (raisedEvent.name == 'system-addon-scene-responder.fetchSpecialDevices') { var oGTIN = {}; var deviceArray = Property.getNode('/apartment/zones/zone0/devices').getChildren(); for (var iIndex = 0; iIndex < deviceArray.length; iIndex++) { var oNode = deviceArray[iIndex]; var GTIN = oNode.getChild('GTIN').getValue(); if (GTIN != null) if (GTIN != "") { oGTIN[GTIN] = 1; } else { lInfo.logln('device ' + oNode.getChild('dSUID').getValue() + ' has no GTIN (function ' + oNode.getChild('functionID').getValue() + ')'); oGTIN["" + oNode.getChild('functionID').getValue()] = 1; } } for ( var sKey in oGTIN) { lInfo.logln('starting for gtin ' + sKey); new Event('system-addon-scene-responder.iterateSpecialDevices', {
141142143144145146147
gtin : sKey }).raise(); } } } catch (e) { lWarn.logln(e); }