Skip to content

Commit

Permalink
Merge pull request #243 from ka-vaNu/238-commands-werden-nicht-bestätigt
Browse files Browse the repository at this point in the history
238 commands werden nicht bestätigt
  • Loading branch information
ka-vaNu authored Dec 26, 2024
2 parents 6ecbfd5 + 9bf225a commit c4fdd7c
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 28 deletions.
37 changes: 36 additions & 1 deletion lib/tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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])}`);
}
Expand All @@ -200,6 +234,7 @@ module.exports = {
setIob,
initCommon,
getBleboxData,
getDatapoints,
simpleObjectUrlGetter,
initIobStates,
setIobStates,
Expand Down
43 changes: 16 additions & 27 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
{
Expand All @@ -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(
{
Expand All @@ -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(
{
Expand All @@ -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(
{
Expand All @@ -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(
{
Expand All @@ -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(
Expand Down Expand Up @@ -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(
{
Expand All @@ -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(
Expand Down Expand Up @@ -466,13 +474,15 @@ 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`:
this.log.info(`set relayForTime to ${state.val}`);
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(
Expand Down Expand Up @@ -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(
{
Expand All @@ -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(
{
Expand All @@ -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(
{
Expand All @@ -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(
Expand All @@ -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');

Expand All @@ -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');

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c4fdd7c

Please sign in to comment.