Skip to content

Commit

Permalink
light: hide extra toggle in webui
Browse files Browse the repository at this point in the history
amend b5a03da
  • Loading branch information
mcspr committed Jan 12, 2023
1 parent faeedee commit 909949b
Show file tree
Hide file tree
Showing 22 changed files with 9,829 additions and 9,798 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.
14 changes: 11 additions & 3 deletions code/espurna/light.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -807,6 +807,10 @@ struct LightTemperature {

LightTemperature _light_temperature;

#if RELAY_SUPPORT
auto _light_state_relay_id = RelaysMax;
#endif

bool _light_state_changed = false;
LightStateListener _light_state_listener = nullptr;

Expand Down Expand Up @@ -2568,9 +2572,9 @@ void _lightApiSetup() {
namespace {

bool _lightWebSocketOnKeyCheck(espurna::StringView key, const JsonVariant&) {
return espurna::settings::query::samePrefix(key, STRING_VIEW("light"))
|| espurna::settings::query::samePrefix(key, STRING_VIEW("use"))
|| espurna::settings::query::samePrefix(key, STRING_VIEW("lt"));
return key.startsWith(STRING_VIEW("light"))
|| key.startsWith(STRING_VIEW("use"))
|| key.startsWith(STRING_VIEW("lt"));
}

void _lightWebSocketStatus(JsonObject& root) {
Expand Down Expand Up @@ -2604,6 +2608,9 @@ void _lightWebSocketOnVisible(JsonObject& root) {
wsPayloadModule(root, PSTR("light"));

JsonObject& light = root.createNestedObject("light");
#if RELAY_SUPPORT
light["state_relay_id"] = _light_state_relay_id;
#endif

JsonArray& channels = light.createNestedArray("channels");

Expand Down Expand Up @@ -3589,6 +3596,7 @@ void _lightSettingsMigrate(int version) {
RelayProviderBasePtr lightMakeStateRelayProvider(size_t id) {
#if RELAY_SUPPORT
if (!_light_state_listener) {
_light_state_relay_id = id;
_light_state_listener = [id](bool state) {
relayStatus(id, state);
};
Expand Down
4,606 changes: 2,304 additions & 2,302 deletions code/espurna/static/index.all.html.gz.h

Large diffs are not rendered by default.

1,392 changes: 696 additions & 696 deletions code/espurna/static/index.curtain.html.gz.h

Large diffs are not rendered by default.

1,313 changes: 657 additions & 656 deletions code/espurna/static/index.garland.html.gz.h

Large diffs are not rendered by default.

2,504 changes: 1,253 additions & 1,251 deletions code/espurna/static/index.light.html.gz.h

Large diffs are not rendered by default.

1,319 changes: 660 additions & 659 deletions code/espurna/static/index.lightfox.html.gz.h

Large diffs are not rendered by default.

1,383 changes: 692 additions & 691 deletions code/espurna/static/index.rfbridge.html.gz.h

Large diffs are not rendered by default.

2,880 changes: 1,440 additions & 1,440 deletions code/espurna/static/index.rfm69.html.gz.h

Large diffs are not rendered by default.

1,559 changes: 780 additions & 779 deletions code/espurna/static/index.sensor.html.gz.h

Large diffs are not rendered by default.

1,287 changes: 644 additions & 643 deletions code/espurna/static/index.small.html.gz.h

Large diffs are not rendered by default.

1,357 changes: 679 additions & 678 deletions code/espurna/static/index.thermostat.html.gz.h

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions code/html/custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -1681,6 +1681,9 @@ function relayToggle(event) {
function initRelayToggle(id, cfg) {
let line = loadConfigTemplate("relay-control");

let root = line.querySelector("div");
root.classList.add(`relay-control-${id}`);

let name = line.querySelector("span[data-key='relayName']");
name.textContent = cfg.relayName;
name.dataset["id"] = id;
Expand Down Expand Up @@ -2170,6 +2173,12 @@ function colorUpdate(mode, value) {
}
}

function lightStateHideRelay(id) {
styleInject([
styleVisible(`.relay-control-${id}`, false)
]);
}

function initLightState() {
const toggle = document.getElementById("light-state-value");
toggle.addEventListener("change", (event) => {
Expand Down Expand Up @@ -2290,6 +2299,10 @@ function updateLight(data) {
updateLightState(value);
break;

case "state_relay_id":
lightStateHideRelay(value);
break;

case "channels":
initLightState();
initBrightness();
Expand Down

0 comments on commit 909949b

Please sign in to comment.