From 4504f034793d0daccea92c9aa040e6d04d502eab Mon Sep 17 00:00:00 2001 From: ka-vaNu Date: Thu, 26 Dec 2024 16:27:34 +0100 Subject: [PATCH 1/2] =?UTF-8?q?#238=20commands=20werden=20nun=20best=C3=A4?= =?UTF-8?q?tigt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.js | 43 ++++++++++++++++--------------------------- 1 file changed, 16 insertions(+), 27 deletions(-) diff --git a/main.js b/main.js index a57ce1a..5f26329 100644 --- a/main.js +++ b/main.js @@ -300,6 +300,7 @@ class Blebox extends utils.Adapter { response = await this.getSimpleObject(device, 'shutterSendDown', null); response['command.move'] = ''; await tools.setIobStates(response); + this.setState(id, state, true); tools.getBleboxData(device, 'shutterExtendedState'); shutterboxRefreshJob = schedule.scheduleJob( { @@ -317,6 +318,7 @@ class Blebox extends utils.Adapter { response = await this.getSimpleObject(device, 'shutterSendUp', null); response['command.move'] = ''; await tools.setIobStates(response); + this.setState(id, state, true); tools.getBleboxData(device, 'shutterExtendedState'); shutterboxRefreshJob = schedule.scheduleJob( { @@ -334,6 +336,7 @@ class Blebox extends utils.Adapter { response = await this.getSimpleObject(device, 'shutterSendStop', null); response['command.move'] = ''; await tools.setIobStates(response); + this.setState(id, state, true); tools.getBleboxData(device, 'shutterExtendedState'); shutterboxRefreshJob = schedule.scheduleJob( { @@ -354,6 +357,7 @@ class Blebox extends utils.Adapter { response = await this.getSimpleObject(device, 'shutterTilt', state.val); response['command.tilt'] = ''; await tools.setIobStates(response); + this.setState(id, state, true); tools.getBleboxData(device, 'shutterExtendedState'); shutterboxRefreshJob = schedule.scheduleJob( { @@ -373,6 +377,7 @@ class Blebox extends utils.Adapter { response = await this.getSimpleObject(device, 'shutterFavorite', state.val); response['command.favorite'] = ''; await tools.setIobStates(response); + this.setState(id, state, true); tools.getBleboxData(device, 'shutterExtendedState'); shutterboxRefreshJob = schedule.scheduleJob( { @@ -392,6 +397,7 @@ class Blebox extends utils.Adapter { response = await this.getSimpleObject(device, 'shutterPosition', state.val); response['command.position'] = ''; await tools.setIobStates(response); + this.setState(id, state, true); tools.getBleboxData(device, 'shutterExtendedState'); // eslint-disable-next-line shutterboxRefreshJob = schedule.scheduleJob( @@ -421,6 +427,7 @@ class Blebox extends utils.Adapter { response = await this.getSimpleObject(device, 'tvliftSendDown', null); response['command.move'] = ''; await tools.setIobStates(response); + this.setState(id, state, true); tools.getBleboxData(device, 'tvliftExtendedState'); tvliftRefreshJob = schedule.scheduleJob( { @@ -438,6 +445,7 @@ class Blebox extends utils.Adapter { response = await this.getSimpleObject(device, 'tvliftSendUp', null); response['command.move'] = ''; await tools.setIobStates(response); + this.setState(id, state, true); tools.getBleboxData(device, 'tvliftExtendedState'); // eslint-disable-next-line tvliftRefreshJob = schedule.scheduleJob( @@ -466,6 +474,7 @@ class Blebox extends utils.Adapter { response = await this.getSimpleObject(device, 'switchSetRelay', state.val); response['command.relay'] = ''; await tools.setIobStates(response); + this.setState(id, state, true); tools.getBleboxData(device, 'switchState'); break; case `${this.namespace}.${name}.command.setRelayForTime`: @@ -473,6 +482,7 @@ class Blebox extends utils.Adapter { response = await this.getSimpleObject(device, 'switchSetRelayForTime', state.val); response['command.setRelayForTime'] = ''; await tools.setIobStates(response); + this.setState(id, state, true); tools.getBleboxData(device, 'switchState'); // eslint-disable-next-line switchboxRefreshJob = schedule.scheduleJob( @@ -502,6 +512,7 @@ class Blebox extends utils.Adapter { response = await this.getSimpleObject(device, 'gatePrimary', null); response['command.move'] = ''; await tools.setIobStates(response); + this.setState(id, state, true); tools.getBleboxData(device, 'gateExtendedState'); gateboxRefreshJob = schedule.scheduleJob( { @@ -519,6 +530,7 @@ class Blebox extends utils.Adapter { response = await this.getSimpleObject(device, 'gateSecondary', null); response['command.move'] = ''; await tools.setIobStates(response); + this.setState(id, state, true); tools.getBleboxData(device, 'gateExtendedState'); gateboxRefreshJob = schedule.scheduleJob( { @@ -536,6 +548,7 @@ class Blebox extends utils.Adapter { response = await this.getSimpleObject(device, 'gateOpen', null); response['command.move'] = ''; await tools.setIobStates(response); + this.setState(id, state, true); tools.getBleboxData(device, 'gateExtendedState'); gateboxRefreshJob = schedule.scheduleJob( { @@ -553,6 +566,7 @@ class Blebox extends utils.Adapter { response = await this.getSimpleObject(device, 'gateClose', null); response['command.move'] = ''; await tools.setIobStates(response); + this.setState(id, state, true); tools.getBleboxData(device, 'gateExtendedState'); // eslint-disable-next-line gateboxRefreshJob = schedule.scheduleJob( @@ -578,6 +592,7 @@ class Blebox extends utils.Adapter { this.log.info(`set heat to ${state.val}`); response = await this.getSimpleObject(device, 'saunaboxSetHeat', state.val); response['command.state'] = ''; + this.setState(id, state, true); await tools.setIobStates(response); tools.getBleboxData(device, 'saunaboxExtendedState'); @@ -586,6 +601,7 @@ class Blebox extends utils.Adapter { this.log.info(`set relayForTime to ${state.val}`); response = await this.getSimpleObject(device, 'saunaboxSetdesiredTemp', state.val * 100); response['command.desiredTemp'] = ''; + this.setState(id, state, true); await tools.setIobStates(response); tools.getBleboxData(device, 'saunaboxExtendedState'); @@ -638,33 +654,6 @@ class Blebox extends utils.Adapter { values = await tools.simpleObjectUrlGetter(device, locationUrl); return values; } - - /** - * - * @param type Type of device to get Datapoints from - * @returns array of datapoints - */ - getDatapoints(type) { - switch (type) { - case 'gatebox': - return gatebox.datapoints; - case 'shutterbox': - return shutterbox.datapoints; - case 'tvlift': - return tvlift.datapoints; - case 'switchbox': - return switchbox.datapoints; - case 'tempsensor': - return tempsensor.datapoints; - case 'multisensor': - return multisensor.datapoints; - case 'saunabox': - return saunabox.datapoints; - default: - break; - } - return false; - } } // @ts-expect-error parent is a valid property on module From 9bf225a292f23f10f4721b9df05d2c43067e9041 Mon Sep 17 00:00:00 2001 From: ka-vaNu Date: Thu, 26 Dec 2024 16:28:05 +0100 Subject: [PATCH 2/2] getDatapoints in tools verschoben --- lib/tools.js | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/lib/tools.js b/lib/tools.js index 8f51fe0..6c63f77 100644 --- a/lib/tools.js +++ b/lib/tools.js @@ -2,6 +2,13 @@ const axios = require('axios'); const dot = require('dot-object'); +const gatebox = require('./gatebox'); +const shutterbox = require('./shutterbox'); +const switchbox = require('./switchbox'); +const tempsensor = require('./tempsensor'); +const multisensor = require('./multisensor'); +const saunabox = require('./saunabox'); +const tvlift = require('./tvlift'); let iob = {}; @@ -57,6 +64,33 @@ function findVal(obj, prop) { return null; } +/** + * + * @param type Type of device to get Datapoints from + * @returns array of datapoints + */ +function getDatapoints(type) { + switch (type) { + case 'gatebox': + return gatebox.datapoints; + case 'shutterbox': + return shutterbox.datapoints; + case 'tvlift': + return tvlift.datapoints; + case 'switchbox': + return switchbox.datapoints; + case 'tempsensor': + return tempsensor.datapoints; + case 'multisensor': + return multisensor.datapoints; + case 'saunabox': + return saunabox.datapoints; + default: + break; + } + return false; +} + /** * * @param device object of the device to request data @@ -186,7 +220,7 @@ async function initCommon(name, apiType) { if (iob.extLog) { iob.log.info(`initCommon: name: ${name} type: ${apiType}`); } - iob.datapoints[name] = iob.getDatapoints(apiType); + iob.datapoints[name] = getDatapoints(apiType); if (iob.extLog) { iob.log.info(`initCommon: datapoints: ${JSON.stringify(iob.datapoints[name])}`); } @@ -200,6 +234,7 @@ module.exports = { setIob, initCommon, getBleboxData, + getDatapoints, simpleObjectUrlGetter, initIobStates, setIobStates,