Skip to content

Commit

Permalink
geändert: README.md
Browse files Browse the repository at this point in the history
	geändert:       main.js
	geändert:       www/configuration.html
	geändert:       www/js/functions.min.js
	geändert:       www/js/i18n/de/translations.json
	geändert:       www/js/i18n/en/translations.json
	geändert:       www/js/i18n/es/translations.json
	geändert:       www/js/i18n/fr/translations.json
	geändert:       www/js/i18n/it/translations.json
	geändert:       www/js/i18n/nl/translations.json
	geändert:       www/js/i18n/pl/translations.json
	geändert:       www/js/i18n/pt/translations.json
	geändert:       www/js/i18n/ru/translations.json
	geändert:       www/js/i18n/uk/translations.json
	geändert:       www/js/i18n/zh-cn/translations.json
	geändert:       www/js/words.js
  • Loading branch information
SKB-CGN committed Sep 18, 2024
1 parent e8dae62 commit 5b70804
Show file tree
Hide file tree
Showing 16 changed files with 141 additions and 90 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ It provides an animated energyflow for all elements, you add. This could be: pho
Placeholder for the next version (at the beginning of the line):
### **WORK IN PROGRESS**
-->
### **WORK IN PROGRESS**
- Added: New option "Auto detect" for "Show source as". The source and unit (if present and not entered before) will be automatically detected
- Added: UI improvements
- FIX: Some basic values were not saved properly
- FIX: Skipping version check while in display-mode (reduces loading time and bandwidth)

### 0.5.1-alpha.7 (2024-09-16)
- Added: Backup routine reworked to improve storage (sending/receiving data reduced)
- Added: Elements, which have addition or subtraction in use, now create states with their values and can be re-used by the user
Expand Down
207 changes: 119 additions & 88 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,12 +242,22 @@ class EnergieflussErweitert extends utils.Adapter {
case '_updateElementInView':
// Receive Object from ioBroker to show it in Configuration
const id = `tmp_${obj.message.id}`;
const state = await this.getForeignStateAsync(obj.message.source);
const originSource = obj.message.source;
const state = await this.getForeignStateAsync(originSource);
let objectUnit = '';
rawValues[id] = state.val;

// Modify the source
obj.message.source = id;

if (state) {
// Get the type if auto
if (obj.message.source_display == 'auto') {
const type = await this.getForeignObjectAsync(originSource);
obj.message.source_type = type.common.type;
objectUnit = type.common.unit;
}

await this.calculateValue(id, obj.message, state);
this.log.debug(`Found ${obj.message.source} and calculated the value for Web-ID: ${id}!`);
if (outputValues.values.hasOwnProperty(id)) {
Expand All @@ -259,6 +269,7 @@ class EnergieflussErweitert extends utils.Adapter {
data: {
id: obj.message.id,
value: outputValues.values[id],
unit: objectUnit,
override: override
}
}, obj.callback);
Expand Down Expand Up @@ -337,101 +348,121 @@ class EnergieflussErweitert extends utils.Adapter {
let timeStamp = this.getTimeStamp(state.ts, obj.source_option);
outputValues.values[id] = timeStamp;
} else {
switch (obj.source_display) {
case 'text':
// Linebreak Option
let strOutput;
if (obj.linebreak > 0 && state.val && state.val.length > 0) {
let splitOpt = new RegExp(`.{0,${obj.linebreak}}(?:\\s|$)`, 'g');
let splitted = state.val.toString().match(splitOpt);
strOutput = splitted.join('<br>');
} else {
strOutput = state.val;
}
outputValues.values[id] = strOutput;
sourceValue = strOutput;
break;

case 'bool':
outputValues.values[id] = sourceValue ? systemDictionary['on'][systemLang] : systemDictionary['off'][systemLang];
break;

case 'own_text':
outputValues.values[id] = obj.text;
break;

default:
// Threshold need to be positive
if (obj.threshold >= 0) {
this.log.debug(`Threshold for: ${id} is: ${obj.threshold}`);

// Check, if we have Subtractions for this value
const subArray = obj.subtract;
let subValue = 0;
if (Array.isArray(subArray) && subArray.length > 0 && subArray[0] != -1) {
subValue = subArray.reduce((acc, idx) => acc - (rawValues[idx] * globalConfig.datasources[idx].factor || 0), 0);
this.log.debug(`Subtracted by: ${subArray.toString()}`);

// Set the subtraction state
await this.setStateChangedAsync(`calculation.elements.element_${id}.subtract`, { val: Number(sourceValue) + Number(subValue), ack: true });
}
const checkDisplay = async (method) => {
switch (method) {
case 'auto':
switch (obj.source_type) {
case 'boolean':
checkDisplay('bool');
break;

// Check, if we have Additions for this value
const addArray = obj.add;
let addValue = 0;
if (Array.isArray(addArray) && addArray.length > 0 && addArray[0] != -1) {
addValue = addArray.reduce((acc, idx) => acc + (rawValues[idx] * globalConfig.datasources[idx].factor || 0), 0);
this.log.debug(`Added to Value: ${addArray.toString()}`);
case 'number':
checkDisplay('');
break;

// Set the addition state
await this.setStateChangedAsync(`calculation.elements.element_${id}.addition`, { val: Number(sourceValue) + Number(addValue), ack: true });
case 'string':
checkDisplay('text');
break;
}
break;

case 'text':
// Linebreak Option
let strOutput;
if (obj.linebreak > 0 && state.val && state.val.length > 0) {
let splitOpt = new RegExp(`.{0,${obj.linebreak}}(?:\\s|$)`, 'g');
let splitted = state.val.toString().match(splitOpt);
strOutput = splitted.join('<br>');
} else {
strOutput = state.val;
}
outputValues.values[id] = strOutput;
sourceValue = strOutput;
break;

case 'bool':
outputValues.values[id] = sourceValue ? systemDictionary['on'][systemLang] : systemDictionary['off'][systemLang];
break;

case 'own_text':
outputValues.values[id] = obj.text;
break;

default:
// Threshold need to be positive
if (obj.threshold >= 0) {
this.log.debug(`Threshold for: ${id} is: ${obj.threshold}`);

// Check, if we have Subtractions for this value
const subArray = obj.subtract;
let subValue = 0;
if (Array.isArray(subArray) && subArray.length > 0 && subArray[0] != -1) {
subValue = subArray.reduce((acc, idx) => acc - (rawValues[idx] * globalConfig.datasources[idx].factor || 0), 0);
this.log.debug(`Subtracted by: ${subArray.toString()}`);

// Set the subtraction state
await this.setStateChangedAsync(`calculation.elements.element_${id}.subtract`, { val: Number(sourceValue) + Number(subValue), ack: true });
}

// Check, if we have Additions for this value
const addArray = obj.add;
let addValue = 0;
if (Array.isArray(addArray) && addArray.length > 0 && addArray[0] != -1) {
addValue = addArray.reduce((acc, idx) => acc + (rawValues[idx] * globalConfig.datasources[idx].factor || 0), 0);
this.log.debug(`Added to Value: ${addArray.toString()}`);

// Set the addition state
await this.setStateChangedAsync(`calculation.elements.element_${id}.addition`, { val: Number(sourceValue) + Number(addValue), ack: true });
}

let formatValue = (Number(sourceValue) + Number(subValue) + Number(addValue));

let formatValue = (Number(sourceValue) + Number(subValue) + Number(addValue));

// Check if value is over threshold
if (Math.abs(formatValue) >= obj.threshold) {
// Convert Value to positive
let cValue = obj.convert ? Math.abs(formatValue) : formatValue;
// Calculation
switch (obj.calculate_kw) {
case 'calc':
case true:
// Convert to kW if set
cValue = (Math.round((cValue / 1000) * 100) / 100);
break;
case 'auto':
if (Math.abs(cValue) >= 1000000000) {
outputValues.unit[id] = 'GW';
// Convert to GW if set
cValue = (Math.round((cValue / 1000000000) * 100) / 100);
} else if (Math.abs(cValue) >= 1000000) {
outputValues.unit[id] = 'MW';
// Convert to MW if set
cValue = (Math.round((cValue / 1000000) * 100) / 100);
} else if (Math.abs(cValue) >= 1000) {
outputValues.unit[id] = 'kW';
// Check if value is over threshold
if (Math.abs(formatValue) >= obj.threshold) {
// Convert Value to positive
let cValue = obj.convert ? Math.abs(formatValue) : formatValue;
// Calculation
switch (obj.calculate_kw) {
case 'calc':
case true:
// Convert to kW if set
cValue = (Math.round((cValue / 1000) * 100) / 100);
} else {
outputValues.unit[id] = 'W';
}
break;
case 'none':
case false:
break;
default:
cValue = cValue;
break;
}
break;
case 'auto':
if (Math.abs(cValue) >= 1000000000) {
outputValues.unit[id] = 'GW';
// Convert to GW if set
cValue = (Math.round((cValue / 1000000000) * 100) / 100);
} else if (Math.abs(cValue) >= 1000000) {
outputValues.unit[id] = 'MW';
// Convert to MW if set
cValue = (Math.round((cValue / 1000000) * 100) / 100);
} else if (Math.abs(cValue) >= 1000) {
outputValues.unit[id] = 'kW';
// Convert to kW if set
cValue = (Math.round((cValue / 1000) * 100) / 100);
} else {
outputValues.unit[id] = 'W';
}
break;
case 'none':
case false:
break;
default:
cValue = cValue;
break;
}

outputValues.values[id] = obj.decimal_places >= 0 ? this.decimalPlaces(cValue, obj.decimal_places) : cValue;
} else {
outputValues.values[id] = obj.decimal_places >= 0 ? this.decimalPlaces(0, obj.decimal_places) : sourceValue;
outputValues.values[id] = obj.decimal_places >= 0 ? this.decimalPlaces(cValue, obj.decimal_places) : cValue;
} else {
outputValues.values[id] = obj.decimal_places >= 0 ? this.decimalPlaces(0, obj.decimal_places) : sourceValue;
}
}
}
break;
}
break;
}
};

checkDisplay(obj.source_display);
}
break;
}
Expand Down
2 changes: 2 additions & 0 deletions www/configuration.html
Original file line number Diff line number Diff line change
Expand Up @@ -836,6 +836,8 @@
as</label>
<select class="input_select elm_config elm_config_update"
name="elm_source_display" id="elm_source_display">
<option value="auto" class="translate" data-lang="opt_autodetect">
Auto Detect</option>
<option value="value" class="translate" data-lang="opt_value">
Value</option>
<option value="text" class="translate" data-lang="opt_text">
Expand Down
2 changes: 1 addition & 1 deletion www/js/functions.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions www/js/i18n/de/translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@
"opt_animation_type_2": "Beginnt schnell, verlangsamt sich bis zum Ende",
"opt_animation_type_3": "langsamer Übergang, Beschleunigung und dann wieder Verlangsamung",
"opt_animation_type_4": "gleichmäßige Geschwindigkeit",
"opt_autodetect": "Automatische Erkennung",
"opt_b_to_t": "Von unten nach oben",
"opt_bottom": "Unten",
"opt_buttons": "Knöpfe",
Expand Down
1 change: 1 addition & 0 deletions www/js/i18n/en/translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@
"opt_animation_type_2": "starts quickly, slows down until end",
"opt_animation_type_3": "slowly transitioning, speeding up, and then slowing down again",
"opt_animation_type_4": "even speed",
"opt_autodetect": "Auto Detect",
"opt_b_to_t": "From bottom to top",
"opt_bottom": "Bottom",
"opt_buttons": "Buttons",
Expand Down
1 change: 1 addition & 0 deletions www/js/i18n/es/translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@
"opt_animation_type_2": "comienza rápidamente, se ralentiza hasta el final",
"opt_animation_type_3": "transición lenta, aceleración y luego desaceleración nuevamente",
"opt_animation_type_4": "incluso velocidad",
"opt_autodetect": "Detección automática",
"opt_b_to_t": "De abajo hacia arriba",
"opt_bottom": "Abajo",
"opt_buttons": "Botones",
Expand Down
1 change: 1 addition & 0 deletions www/js/i18n/fr/translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@
"opt_animation_type_2": "démarre vite, ralentit jusqu'à la fin",
"opt_animation_type_3": "transition lente, accélération, puis ralentissement à nouveau",
"opt_animation_type_4": "même vitesse",
"opt_autodetect": "Détection automatique",
"opt_b_to_t": "De bas en haut",
"opt_bottom": "Bas",
"opt_buttons": "Boutons",
Expand Down
1 change: 1 addition & 0 deletions www/js/i18n/it/translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@
"opt_animation_type_2": "inizia velocemente, rallenta fino alla fine",
"opt_animation_type_3": "passando lentamente, accelerando e poi rallentando di nuovo",
"opt_animation_type_4": "anche la velocità",
"opt_autodetect": "Rilevamento automatico",
"opt_b_to_t": "Dal basso verso l'alto",
"opt_bottom": "Metter il fondo a",
"opt_buttons": "Pulsanti",
Expand Down
1 change: 1 addition & 0 deletions www/js/i18n/nl/translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@
"opt_animation_type_2": "begint snel, vertraagt ​​tot het einde",
"opt_animation_type_3": "langzaam overgaand, versnellend en dan weer vertragend",
"opt_animation_type_4": "gelijkmatige snelheid",
"opt_autodetect": "Automatische detectie",
"opt_b_to_t": "Van onder naar boven",
"opt_bottom": "Onderkant",
"opt_buttons": "Knoppen",
Expand Down
1 change: 1 addition & 0 deletions www/js/i18n/pl/translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@
"opt_animation_type_2": "zaczyna się szybko, zwalnia aż do końca",
"opt_animation_type_3": "powoli się zmienia, przyspiesza i ponownie zwalnia",
"opt_animation_type_4": "nawet prędkość",
"opt_autodetect": "Automatyczne wykrywanie",
"opt_b_to_t": "Od dołu do góry",
"opt_bottom": "Spód",
"opt_buttons": "Pikolak",
Expand Down
1 change: 1 addition & 0 deletions www/js/i18n/pt/translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@
"opt_animation_type_2": "começa rapidamente, desacelera até o final",
"opt_animation_type_3": "transitando lentamente, acelerando e desacelerando novamente",
"opt_animation_type_4": "velocidade uniforme",
"opt_autodetect": "Detecção automática",
"opt_b_to_t": "De baixo para cima",
"opt_bottom": "Fundo",
"opt_buttons": "Botões",
Expand Down
1 change: 1 addition & 0 deletions www/js/i18n/ru/translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@
"opt_animation_type_2": "начинается быстро, замедляется до конца",
"opt_animation_type_3": "медленно переходить, ускоряться, а затем снова замедляться",
"opt_animation_type_4": "даже скорость",
"opt_autodetect": "Автоопределение",
"opt_b_to_t": "Снизу вверх",
"opt_bottom": "Нижний",
"opt_buttons": "Кнопки",
Expand Down
1 change: 1 addition & 0 deletions www/js/i18n/uk/translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@
"opt_animation_type_2": "починає швидко, гальмує до кінця",
"opt_animation_type_3": "повільно переходить, прискорюється, а потім знову сповільнюється",
"opt_animation_type_4": "рівномірна швидкість",
"opt_autodetect": "Автоматичне визначення",
"opt_b_to_t": "Від низу до верху",
"opt_bottom": "Дно",
"opt_buttons": "кнопки",
Expand Down
1 change: 1 addition & 0 deletions www/js/i18n/zh-cn/translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@
"opt_animation_type_2": "快速开始,缓慢直至结束",
"opt_animation_type_3": "缓慢过渡,加速,然后再次减速",
"opt_animation_type_4": "均匀的速度",
"opt_autodetect": "自动检测",
"opt_b_to_t": "从下到上",
"opt_bottom": "底部",
"opt_buttons": "按钮",
Expand Down
Loading

0 comments on commit 5b70804

Please sign in to comment.