Skip to content

Commit

Permalink
sns: show and edit correction values in webui
Browse files Browse the repository at this point in the history
fixes #2491
  • Loading branch information
mcspr committed May 5, 2022
1 parent 57f0402 commit 62b2eda
Show file tree
Hide file tree
Showing 23 changed files with 12,136 additions and 12,100 deletions.
Binary file modified code/espurna/data/index.all.html.gz
Binary file not shown.
Binary file modified code/espurna/data/index.curtain.html.gz
Binary file not shown.
Binary file modified code/espurna/data/index.garland.html.gz
Binary file not shown.
Binary file modified code/espurna/data/index.light.html.gz
Binary file not shown.
Binary file modified code/espurna/data/index.lightfox.html.gz
Binary file not shown.
Binary file modified code/espurna/data/index.rfbridge.html.gz
Binary file not shown.
Binary file modified code/espurna/data/index.rfm69.html.gz
Binary file not shown.
Binary file modified code/espurna/data/index.sensor.html.gz
Binary file not shown.
Binary file modified code/espurna/data/index.small.html.gz
Binary file not shown.
Binary file modified code/espurna/data/index.thermostat.html.gz
Binary file not shown.
4 changes: 2 additions & 2 deletions code/espurna/sensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1649,8 +1649,8 @@ constexpr double _magnitudeCorrection(unsigned char type) {
constexpr bool _magnitudeCorrectionSupported(unsigned char type) {
return (MAGNITUDE_TEMPERATURE == type)
|| (MAGNITUDE_HUMIDITY == type)
|| (MAGNITUDE_LUX == type)
|| (MAGNITUDE_PRESSURE == type);
|| (MAGNITUDE_PRESSURE == type)
|| (MAGNITUDE_LUX == type);
}

SettingsKey _magnitudeSettingsCorrectionKey(unsigned char type, size_t index) {
Expand Down
3,217 changes: 1,612 additions & 1,605 deletions code/espurna/static/index.all.html.gz.h

Large diffs are not rendered by default.

1,431 changes: 716 additions & 715 deletions code/espurna/static/index.curtain.html.gz.h

Large diffs are not rendered by default.

2,769 changes: 1,385 additions & 1,384 deletions code/espurna/static/index.garland.html.gz.h

Large diffs are not rendered by default.

2,515 changes: 1,258 additions & 1,257 deletions code/espurna/static/index.light.html.gz.h

Large diffs are not rendered by default.

2,781 changes: 1,391 additions & 1,390 deletions code/espurna/static/index.lightfox.html.gz.h

Large diffs are not rendered by default.

2,836 changes: 1,418 additions & 1,418 deletions code/espurna/static/index.rfbridge.html.gz.h

Large diffs are not rendered by default.

1,428 changes: 714 additions & 714 deletions code/espurna/static/index.rfm69.html.gz.h

Large diffs are not rendered by default.

3,011 changes: 1,508 additions & 1,503 deletions code/espurna/static/index.sensor.html.gz.h

Large diffs are not rendered by default.

2,751 changes: 1,376 additions & 1,375 deletions code/espurna/static/index.small.html.gz.h

Large diffs are not rendered by default.

1,395 changes: 698 additions & 697 deletions code/espurna/static/index.thermostat.html.gz.h

Large diffs are not rendered by default.

50 changes: 34 additions & 16 deletions code/html/custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -1396,20 +1396,21 @@ function showPanel(event) {
// Relays & magnitudes mapping
// -----------------------------------------------------------------------------

function createRelayList(values, container, template_name) {
let target = document.getElementById(container);
function createRelayList(containerId, values, keyPrefix) {
const target = document.getElementById(containerId);
if (target.childElementCount > 0) {
return;
}

// TODO: let schema set the settings key
let template = loadConfigTemplate(template_name);
const template = loadConfigTemplate("number-input");
values.forEach((value, index) => {
let line = template.cloneNode(true);
const line = template.cloneNode(true);
line.querySelector("label").textContent = (Enumerable.relay)
? Enumerable.relay[index].name : `Switch #${index}`;

let input = line.querySelector("input");
const input = line.querySelector("input");
input.name = keyPrefix;
input.value = value;
input.dataset["original"] = value;

Expand All @@ -1420,7 +1421,7 @@ function createRelayList(values, container, template_name) {
//removeIf(!sensor)

function initModuleMagnitudes(data) {
const targetId = `${data.prefix}Magnitudes`;
const targetId = `${data.prefix}-magnitudes`;

let target = document.getElementById(targetId);
if (target.childElementCount > 0) { return; }
Expand Down Expand Up @@ -1796,33 +1797,41 @@ function createMagnitudeUnitSelector(id, magnitude) {
}
}

function emonRatioInfo(id) {
function magnitudeSettingInfo(id, key) {
const out = {
id: id,
name: Magnitudes.properties[id].name,
prefix: `${Magnitudes.typePrefix[Magnitudes.properties[id].type]}`,
index_global: `${Magnitudes.properties[id].index_global}`
};

out.key = `${out.prefix}Ratio${out.index_global}`;
out.key = `${out.prefix}${key}${out.index_global}`;
return out;
}

function initMagnitudesRatio(id, ratio) {
const template = loadTemplate("emon-ratios");
function emonRatioInfo(id) {
return magnitudeSettingInfo(id, "Ratio");
}

function initMagnitudeTextSetting(containerId, id, keySuffix, value) {
const template = loadTemplate("text-input");
const input = template.querySelector("input");

const info = emonRatioInfo(id);
const info = magnitudeSettingInfo(id, keySuffix);
input.id = info.key;
input.name = input.id;
input.value = ratio;
input.value = value;
setOriginalsFromValuesForNode(template, [input]);

const label = template.querySelector("label");
label.textContent = info.name;
label.htmlFor = input.id;

mergeTemplate(document.getElementById("emon-ratios"), template);
mergeTemplate(document.getElementById(containerId), template);
}

function initMagnitudesRatio(id, value) {
initMagnitudeTextSetting("emon-ratios", id, "Ratio", value);
}

function initMagnitudesExpected(id) {
Expand Down Expand Up @@ -1892,13 +1901,22 @@ function emonApplyRatios() {
showPanelByName("sns");
}

function initMagnitudesCorrection(id, value) {
initMagnitudeTextSetting("magnitude-corrections", id, "Correction", value);
}

function initMagnitudesSettings(data) {
data.values.forEach((cfg, id) => {
const settings = fromSchema(cfg, data.schema);
if (settings.Ratio) {

if (settings.Ratio != null) {
initMagnitudesRatio(id, settings.Ratio);
initMagnitudesExpected(id);
}

if (settings.Correction != null) {
initMagnitudesCorrection(id, settings.Correction);
}
});
}

Expand Down Expand Up @@ -2628,12 +2646,12 @@ function processData(data) {
// ---------------------------------------------------------------------

if ("dczRelays" === key) {
createRelayList(value, "dczRelays", "dcz-relay");
createRelayList("dcz-relays", value, "dczRelayIdx");
return;
}

if ("tspkRelays" === key) {
createRelayList(value, "tspkRelays", "tspk-relay");
createRelayList("tspk-relays", value, "tspkRelay");
return;
}

Expand Down
48 changes: 24 additions & 24 deletions code/html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1520,10 +1520,10 @@ <h2>
Set IDX to 0 to disable notifications from that component.
</span>

<div id="dczRelays" class="settings-group" data-settings-target="dczRelay" ></div>
<div id="dcz-relays" class="settings-group" data-settings-target="dczRelay" ></div>

<!-- removeIf(!sensor) -->
<div id="dczMagnitudes" class="settings-group" data-settings-target="dczMagnitude" ></div>
<div id="dcz-magnitudes" class="settings-group" data-settings-target="dczMagnitude" ></div>
<!-- endRemoveIf(!sensor) -->
</fieldset>
</div>
Expand Down Expand Up @@ -1630,10 +1630,10 @@ <h2>
Enter the field number to send each data to, 0 disable notifications from that component.
</span>

<div id="tspkRelays" class="settings-group" data-settings-target="tspkRelay" ></div>
<div id="tspk-relays" class="settings-group" data-settings-target="tspkRelay" ></div>

<!-- removeIf(!sensor) -->
<div id="tspkMagnitudes" class="settings-group" data-settings-target="tspkMagnitude" ></div>
<div id="tspk-magnitudes" class="settings-group" data-settings-target="tspkMagnitude" ></div>
<!-- endRemoveIf(!sensor) -->
</fieldset>
</div>
Expand Down Expand Up @@ -1900,6 +1900,12 @@ <h2>
</div>
</fieldset>

<fieldset>
<legend>Corrections</legend>
<div id="magnitude-corrections" class="pure-form-aligned settings-group">
</div>
</fieldset>

<fieldset class="module module-emon">
<legend>Ratios</legend>
<div id="emon-ratios" class="pure-form-aligned settings-group">
Expand Down Expand Up @@ -2031,6 +2037,20 @@ <h2>

<!-- Templates -->

<template id="template-text-input">
<div class="pure-control-group">
<label></label>
<input type="text">
</div>
</template>

<template id="template-number-input">
<div class="pure-control-group">
<label></label>
<input type="number" min="0">
</div>
</template>

<template id="template-led-config" >
<div class="pure-form pure-form-aligned">
<fieldset>
Expand Down Expand Up @@ -2331,28 +2351,8 @@ <h2>
</div>
</template>

<template id="template-emon-ratios">
<div class="pure-control-group">
<label></label>
<input type="text">
</div>
</template>
<!-- endRemoveIf(!sensor) -->

<template id="template-dcz-relay">
<div class="pure-control-group">
<label></label>
<input name="dczRelayIdx" type="number" min="0">
</div>
</template>

<template id="template-tspk-relay" class="template">
<div class="pure-control-group">
<label></label>
<input name="tspkRelay" type="number" min="0">
</div>
</template>

<!-- removeIf(!light) -->
<template id="template-channel-control">
<div class="pure-control-group">
Expand Down

0 comments on commit 62b2eda

Please sign in to comment.