|
154 | 154 | // Ignore UI quirks for legacy Node-RED versions |
155 | 155 | } |
156 | 156 | }; |
157 | | - ["#node-input-server", "#node-input-serverHue"].forEach(ensureConfigSelection); |
| 157 | + ["#node-input-serverHue"].forEach(ensureConfigSelection); |
158 | 158 |
|
159 | 159 | function ensureVerticalTabsStyle() { |
160 | 160 | if ($('#knxUltimateHueLightVerticalTabs').length) return; |
|
203 | 203 |
|
204 | 204 | function onEditPrepare() { |
205 | 205 | ensureVerticalTabsStyle(); |
| 206 | + const $knxServerInput = $("#node-input-server"); |
| 207 | + const KNX_EMPTY_VALUES = new Set(['', 'none', '_ADD_', '__NONE__']); |
| 208 | + |
| 209 | + const resolveKnxServerValue = () => { |
| 210 | + const domValue = $knxServerInput.val(); |
| 211 | + if (domValue !== undefined && domValue !== null && domValue !== '') { |
| 212 | + return domValue; |
| 213 | + } |
| 214 | + if (node.server !== undefined && node.server !== null) { |
| 215 | + return node.server; |
| 216 | + } |
| 217 | + return ''; |
| 218 | + }; |
| 219 | + |
| 220 | + const hasKnxServerSelected = () => { |
| 221 | + const val = resolveKnxServerValue(); |
| 222 | + if (val === undefined || val === null) return false; |
| 223 | + return !KNX_EMPTY_VALUES.has(val); |
| 224 | + }; |
206 | 225 | // TIMER BLINK #################################################### |
207 | 226 | let blinkStatus = 2; |
208 | 227 | let timerBlinkBackground; |
|
408 | 427 | // ######################## |
409 | 428 | const prefixes = Array.isArray(_dpt) ? _dpt : [_dpt]; |
410 | 429 | $(_destinationWidget).empty(); |
411 | | - $.getJSON("knxUltimateDpts?serverId=" + $("#node-input-server").val() + "&" + { _: new Date().getTime() }, (data) => { |
| 430 | + if (!hasKnxServerSelected()) { |
| 431 | + return; |
| 432 | + } |
| 433 | + const serverId = resolveKnxServerValue(); |
| 434 | + $.getJSON(`knxUltimateDpts?serverId=${serverId}&_=${Date.now()}`, (data) => { |
412 | 435 | data.forEach((dpt) => { |
413 | 436 | if (prefixes.some((prefix) => prefix === "" || dpt.value.startsWith(prefix))) { |
414 | 437 | // Adjustment for HUE Temperature |
|
438 | 461 | $(_sourceWidgetAutocomplete).autocomplete({ |
439 | 462 | minLength: 0, |
440 | 463 | source: function (request, response) { |
441 | | - //$.getJSON("csv", request, function( data, status, xhr ) { |
442 | | - $.getJSON("knxUltimatecsv?nodeID=" + $("#node-input-server").val() + "&" + { _: new Date().getTime() }, (data) => { |
| 464 | + if (!hasKnxServerSelected()) { |
| 465 | + response([]); |
| 466 | + return; |
| 467 | + } |
| 468 | + const serverId = resolveKnxServerValue(); |
| 469 | + $.getJSON(`knxUltimatecsv?nodeID=${serverId}&_=${Date.now()}`, (data) => { |
443 | 470 | response( |
444 | 471 | $.map(data, function (value, key) { |
445 | 472 | var sSearch = value.ga + " (" + value.devicename + ") DPT" + value.dpt; |
|
475 | 502 | }).focus(function () { |
476 | 503 | $(this).autocomplete('search', $(this).val() + 'exactmatch'); |
477 | 504 | }); |
478 | | - try { var srv = RED.nodes.node($("#node-input-server").val()); if (srv && srv.id) KNX_enableSecureFormatting($(_sourceWidgetAutocomplete), srv.id); } catch (e) {} |
| 505 | + try { |
| 506 | + if (hasKnxServerSelected()) { |
| 507 | + const srv = RED.nodes.node(resolveKnxServerValue()); |
| 508 | + if (srv && srv.id) KNX_enableSecureFormatting($(_sourceWidgetAutocomplete), srv.id); |
| 509 | + } |
| 510 | + } catch (e) {} |
479 | 511 | } |
480 | 512 |
|
481 | | - getDPT("1.", "#node-input-dptLightSwitch"); |
482 | | - getGroupAddress("#node-input-GALightSwitch", "#node-input-nameLightSwitch", "#node-input-dptLightSwitch", ["1."]); |
| 513 | + const effectDptPrefixes = ["1.", "2.", "5.", "6.", "7.", "8.", "9.", "16.", "20."]; |
483 | 514 |
|
484 | | - getDPT("1.", "#node-input-dptLightState"); |
485 | | - getGroupAddress("#node-input-GALightState", "#node-input-nameLightState", "#node-input-dptLightState", ["1."]); |
| 515 | + const refreshKnxBindings = () => { |
| 516 | + getDPT("1.", "#node-input-dptLightSwitch"); |
| 517 | + getGroupAddress("#node-input-GALightSwitch", "#node-input-nameLightSwitch", "#node-input-dptLightSwitch", ["1."]); |
486 | 518 |
|
487 | | - getDPT("3.007", "#node-input-dptLightDIM"); |
488 | | - getGroupAddress("#node-input-GALightDIM", "#node-input-nameLightDIM", "#node-input-dptLightDIM", ["3.007"]); |
| 519 | + getDPT("1.", "#node-input-dptLightState"); |
| 520 | + getGroupAddress("#node-input-GALightState", "#node-input-nameLightState", "#node-input-dptLightState", ["1."]); |
489 | 521 |
|
490 | | - getDPT("5.001", "#node-input-dptLightBrightness"); |
491 | | - getGroupAddress("#node-input-GALightBrightness", "#node-input-nameLightBrightness", "#node-input-dptLightBrightness", ["5.001"]); |
| 522 | + getDPT("3.007", "#node-input-dptLightDIM"); |
| 523 | + getGroupAddress("#node-input-GALightDIM", "#node-input-nameLightDIM", "#node-input-dptLightDIM", ["3.007"]); |
492 | 524 |
|
493 | | - getDPT("5.001", "#node-input-dptLightBrightnessState"); |
494 | | - getGroupAddress("#node-input-GALightBrightnessState", "#node-input-nameLightBrightnessState", "#node-input-dptLightBrightnessState", ["5.001"]); |
| 525 | + getDPT("5.001", "#node-input-dptLightBrightness"); |
| 526 | + getGroupAddress("#node-input-GALightBrightness", "#node-input-nameLightBrightness", "#node-input-dptLightBrightness", ["5.001"]); |
495 | 527 |
|
496 | | - getDPT("232.600", "#node-input-dptLightColor"); |
497 | | - getGroupAddress("#node-input-GALightColor", "#node-input-nameLightColor", "#node-input-dptLightColor", ["232.600"]); |
| 528 | + getDPT("5.001", "#node-input-dptLightBrightnessState"); |
| 529 | + getGroupAddress("#node-input-GALightBrightnessState", "#node-input-nameLightBrightnessState", "#node-input-dptLightBrightnessState", ["5.001"]); |
498 | 530 |
|
499 | | - getDPT("232.600", "#node-input-dptLightColorState"); |
500 | | - getGroupAddress("#node-input-GALightColorState", "#node-input-nameLightColorState", "#node-input-dptLightColorState", ["232.600"]); |
| 531 | + getDPT("232.600", "#node-input-dptLightColor"); |
| 532 | + getGroupAddress("#node-input-GALightColor", "#node-input-nameLightColor", "#node-input-dptLightColor", ["232.600"]); |
501 | 533 |
|
502 | | - getDPT("3.007", "#node-input-dptLightKelvinDIM"); |
503 | | - getGroupAddress("#node-input-GALightKelvinDIM", "#node-input-nameLightKelvinDIM", "#node-input-dptLightKelvinDIM", ["3.007"]); |
| 534 | + getDPT("232.600", "#node-input-dptLightColorState"); |
| 535 | + getGroupAddress("#node-input-GALightColorState", "#node-input-nameLightColorState", "#node-input-dptLightColorState", ["232.600"]); |
504 | 536 |
|
505 | | - getDPT("5.001", "#node-input-dptLightKelvinPercentage"); |
506 | | - getGroupAddress("#node-input-GALightKelvinPercentage", "#node-input-nameLightKelvinPercentage", "#node-input-dptLightKelvinPercentage", ["5.001"]); |
| 537 | + getDPT("3.007", "#node-input-dptLightKelvinDIM"); |
| 538 | + getGroupAddress("#node-input-GALightKelvinDIM", "#node-input-nameLightKelvinDIM", "#node-input-dptLightKelvinDIM", ["3.007"]); |
507 | 539 |
|
508 | | - getDPT("5.001", "#node-input-dptLightKelvinPercentageState"); |
509 | | - getGroupAddress("#node-input-GALightKelvinPercentageState", "#node-input-nameLightKelvinPercentageState", "#node-input-dptLightKelvinPercentageState", ["5.001"]); |
| 540 | + getDPT("5.001", "#node-input-dptLightKelvinPercentage"); |
| 541 | + getGroupAddress("#node-input-GALightKelvinPercentage", "#node-input-nameLightKelvinPercentage", "#node-input-dptLightKelvinPercentage", ["5.001"]); |
510 | 542 |
|
511 | | - getDPT("1.", "#node-input-dptLightBlink"); |
512 | | - getGroupAddress("#node-input-GALightBlink", "#node-input-nameLightBlink", "#node-input-dptLightBlink", ["1."]); |
| 543 | + getDPT("5.001", "#node-input-dptLightKelvinPercentageState"); |
| 544 | + getGroupAddress("#node-input-GALightKelvinPercentageState", "#node-input-nameLightKelvinPercentageState", "#node-input-dptLightKelvinPercentageState", ["5.001"]); |
513 | 545 |
|
514 | | - getDPT("1.", "#node-input-dptLightColorCycle"); |
515 | | - getGroupAddress("#node-input-GALightColorCycle", "#node-input-nameLightColorCycle", "#node-input-dptLightColorCycle", ["1."]); |
| 546 | + getDPT("1.", "#node-input-dptLightBlink"); |
| 547 | + getGroupAddress("#node-input-GALightBlink", "#node-input-nameLightBlink", "#node-input-dptLightBlink", ["1."]); |
516 | 548 |
|
517 | | - const effectDptPrefixes = ["1.", "2.", "5.", "6.", "7.", "8.", "9.", "16.", "20."]; |
518 | | - getDPT(effectDptPrefixes, "#node-input-dptLightEffect"); |
519 | | - getGroupAddress("#node-input-GALightEffect", "#node-input-nameLightEffect", "#node-input-dptLightEffect", effectDptPrefixes); |
| 549 | + getDPT("1.", "#node-input-dptLightColorCycle"); |
| 550 | + getGroupAddress("#node-input-GALightColorCycle", "#node-input-nameLightColorCycle", "#node-input-dptLightColorCycle", ["1."]); |
520 | 551 |
|
521 | | - getDPT(effectDptPrefixes, "#node-input-dptLightEffectStatus"); |
522 | | - getGroupAddress("#node-input-GALightEffectStatus", "#node-input-nameLightEffectStatus", "#node-input-dptLightEffectStatus", effectDptPrefixes); |
| 552 | + getDPT(effectDptPrefixes, "#node-input-dptLightEffect"); |
| 553 | + getGroupAddress("#node-input-GALightEffect", "#node-input-nameLightEffect", "#node-input-dptLightEffect", effectDptPrefixes); |
523 | 554 |
|
524 | | - getDPT("1.", "#node-input-dptDaylightSensor"); |
525 | | - getGroupAddress("#node-input-GADaylightSensor", "#node-input-nameDaylightSensor", "#node-input-dptDaylightSensor", ["1."]); |
| 555 | + getDPT(effectDptPrefixes, "#node-input-dptLightEffectStatus"); |
| 556 | + getGroupAddress("#node-input-GALightEffectStatus", "#node-input-nameLightEffectStatus", "#node-input-dptLightEffectStatus", effectDptPrefixes); |
526 | 557 |
|
527 | | - getDPT("7.600", "#node-input-dptLightKelvin"); |
528 | | - getDPT("9.002", "#node-input-dptLightKelvin"); |
529 | | - getDPT("9.002", "#node-input-dptLightKelvinState"); |
530 | | - getDPT("7.600", "#node-input-dptLightKelvinState"); |
531 | | - getGroupAddress("#node-input-GALightKelvin", "#node-input-nameLightKelvin", "#node-input-dptLightKelvin", ["7.600", "9.002"]); |
532 | | - getGroupAddress("#node-input-GALightKelvinState", "#node-input-nameLightKelvinState", "#node-input-dptLightKelvinState", ["7.600", "9.002"]); |
| 558 | + getDPT("1.", "#node-input-dptDaylightSensor"); |
| 559 | + getGroupAddress("#node-input-GADaylightSensor", "#node-input-nameDaylightSensor", "#node-input-dptDaylightSensor", ["1."]); |
533 | 560 |
|
534 | | - // HSV ---------------------- |
535 | | - // H |
536 | | - getDPT("3.007", "#node-input-dptLightHSV_H_DIM"); |
537 | | - getGroupAddress("#node-input-GALightHSV_H_DIM", "#node-input-nameLightHSV_H_DIM", "#node-input-dptLightHSV_H_DIM", ["3.007"]); |
| 561 | + getDPT("7.600", "#node-input-dptLightKelvin"); |
| 562 | + getDPT("9.002", "#node-input-dptLightKelvin"); |
| 563 | + getDPT("9.002", "#node-input-dptLightKelvinState"); |
| 564 | + getDPT("7.600", "#node-input-dptLightKelvinState"); |
| 565 | + getGroupAddress("#node-input-GALightKelvin", "#node-input-nameLightKelvin", "#node-input-dptLightKelvin", ["7.600", "9.002"]); |
| 566 | + getGroupAddress("#node-input-GALightKelvinState", "#node-input-nameLightKelvinState", "#node-input-dptLightKelvinState", ["7.600", "9.002"]); |
538 | 567 |
|
539 | | - getDPT("5.001", "#node-input-dptLightHSV_H_State"); |
540 | | - getGroupAddress("#node-input-GALightHSV_H_State", "#node-input-nameLightHSV_H_State", "#node-input-dptLightHSV_H_State", ["5.001"]); |
| 568 | + // HSV ---------------------- |
| 569 | + // H |
| 570 | + getDPT("3.007", "#node-input-dptLightHSV_H_DIM"); |
| 571 | + getGroupAddress("#node-input-GALightHSV_H_DIM", "#node-input-nameLightHSV_H_DIM", "#node-input-dptLightHSV_H_DIM", ["3.007"]); |
541 | 572 |
|
542 | | - // S |
543 | | - getDPT("3.007", "#node-input-dptLightHSV_S_DIM"); |
544 | | - getGroupAddress("#node-input-GALightHSV_S_DIM", "#node-input-nameLightHSV_S_DIM", "#node-input-dptLightHSV_S_DIM", ["3.007"]); |
| 573 | + getDPT("5.001", "#node-input-dptLightHSV_H_State"); |
| 574 | + getGroupAddress("#node-input-GALightHSV_H_State", "#node-input-nameLightHSV_H_State", "#node-input-dptLightHSV_H_State", ["5.001"]); |
545 | 575 |
|
546 | | - getDPT("5.001", "#node-input-dptLightHSV_S_State"); |
547 | | - getGroupAddress("#node-input-GALightHSV_S_State", "#node-input-nameLightHSV_S_State", "#node-input-dptLightHSV_S_State", ["5.001"]); |
| 576 | + // S |
| 577 | + getDPT("3.007", "#node-input-dptLightHSV_S_DIM"); |
| 578 | + getGroupAddress("#node-input-GALightHSV_S_DIM", "#node-input-nameLightHSV_S_DIM", "#node-input-dptLightHSV_S_DIM", ["3.007"]); |
548 | 579 |
|
549 | | - // V |
550 | | - getDPT("3.007", "#node-input-dptLightHSV_V_DIM"); |
551 | | - getGroupAddress("#node-input-GALightHSV_V_DIM", "#node-input-nameLightHSV_V_DIM", "#node-input-dptLightHSV_V_DIM", ["3.007"]); |
| 580 | + getDPT("5.001", "#node-input-dptLightHSV_S_State"); |
| 581 | + getGroupAddress("#node-input-GALightHSV_S_State", "#node-input-nameLightHSV_S_State", "#node-input-dptLightHSV_S_State", ["5.001"]); |
552 | 582 |
|
553 | | - getDPT("5.001", "#node-input-dptLightHSV_V_State"); |
554 | | - getGroupAddress("#node-input-GALightHSV_V_State", "#node-input-nameLightHSV_V_State", "#node-input-dptLightHSV_V_State", ["5.001"]); |
555 | | - // END HSV ---------------------- |
| 583 | + // V |
| 584 | + getDPT("3.007", "#node-input-dptLightHSV_V_DIM"); |
| 585 | + getGroupAddress("#node-input-GALightHSV_V_DIM", "#node-input-nameLightHSV_V_DIM", "#node-input-dptLightHSV_V_DIM", ["3.007"]); |
| 586 | + |
| 587 | + getDPT("5.001", "#node-input-dptLightHSV_V_State"); |
| 588 | + getGroupAddress("#node-input-GALightHSV_V_State", "#node-input-nameLightHSV_V_State", "#node-input-dptLightHSV_V_State", ["5.001"]); |
| 589 | + // END HSV ---------------------- |
| 590 | + }; |
| 591 | + |
| 592 | + refreshKnxBindings(); |
| 593 | + $knxServerInput.on('change.knxUltimateHueLight', () => { |
| 594 | + refreshKnxBindings(); |
| 595 | + }); |
556 | 596 |
|
557 | 597 | // Get the HUE capabilities to enable/disable UI parts |
558 | 598 | var getJsonPromise; |
|
0 commit comments