1
0

Remove #stateToValue

This commit is contained in:
2023-08-14 19:42:01 +02:00
parent 6ec3f4e143
commit 5ee804c69a

View File

@@ -44,7 +44,7 @@ class Watch {
alertRepeat: (params['alertRepeat'] !== undefined) ? params['alertRepeat'] : 0, alertRepeat: (params['alertRepeat'] !== undefined) ? params['alertRepeat'] : 0,
initialAlertFunc: (params['initialAlertFunc'] !== undefined) ? params['initialAlertFunc'] : '', initialAlertFunc: (params['initialAlertFunc'] !== undefined) ? params['initialAlertFunc'] : '',
endAlertFunc: (params['endAlertFunc'] !== undefined) ? params['endAlertFunc'] : '', endAlertFunc: (params['endAlertFunc'] !== undefined) ? params['endAlertFunc'] : '',
hysteresis: (params['hysteresis'] !== undefined) ? this.#stateToValue(params['hysteresis']) : '', hysteresis: (params['hysteresis'] !== undefined) ? lib.convertValue(params['hysteresis']) : '',
alert: false alert: false
} }
@@ -240,44 +240,6 @@ class Watch {
); );
} }
} }
#stateToValue(state) {
console.log('Converting value ' + state + ' of type ' + typeof state);
if(typeof state === 'string') {
if(state.includes(' ')) {
try {
console.log('Quantity: ' + state);
return Quantity(state)
} catch(e) {
// do nothing, leave it as a String
console.log('Not a Quantity but has a space, leaving as a string: ' + state);
return state;
}
}
else if(!isNaN(state)) {
console.log('Number: ' + state)
return Number.parseFloat(state);
}
else if(state == 'UnDefType' || state == 'NULL' || state == 'UNDEF') {
console.log('UnDefType: ' + state);
return 'UnDefType';
}
console.log('String: ' + state);
return state;
}
else if(state instanceof DecimalType || state instanceof PercentType) {
console.log('DecimalType or PercentType: ' + state);
return state.floatValue();
}
else if(state instanceof QuantityType) {
console.log('QuantityType: ' + state);
return Quantity(state);
}
else {
console.log('String: ' + state);
return state.toString();
}
}
} }
module.exports = { module.exports = {