node-red-contrib-knx-ultimate
Version:
Control your KNX and KNX Secure intallation via Node-Red! A bunch of KNX nodes, with integrated Philips HUE control and ETS group address importer. Easy to use and highly configurable.
234 lines (210 loc) • 11.8 kB
HTML
<script type="text/javascript" src="resources/node-red-contrib-knx-ultimate/htmlUtils.js"></script>
<script type="text/javascript">
RED.nodes.registerType('hue-config', {
category: 'config',
defaults: {
host: { value: "" },
name: { value: "Hue Bridge" },
bridgeid: { value: "" }
},
credentials: {
username: { type: "password" },
clientkey: { type: "password" }
},
oneditprepare: function () {
// Go to the help panel
try {
RED.sidebar.show("help");
} catch (error) { }
var node = this;
if (this.bridgeid === undefined || this.bridgeid === '') {
$("#divDetails").hide()
} else {
$("#divDetails").show()
}
// #region "CONNECTION TO THE BRIDGE"
$("#getinfocam").click(function () {
$.getJSON("KNXUltimateGetHueBridgeInfo?IP=" + $("#node-config-input-host").val() + "&serverId=" + node.id, (data) => {
if (data.hasOwnProperty("error")) {
RED.notify(JSON.stringify(data.error),
{
modal: true,
fixed: false,
type: 'error'
});
return;
}
$("#node-config-input-bridgeid").val(data.bridgeid);
$("#node-config-input-name").val(data.name);
var myNotification = RED.notify("Please press the Link button on the HUE Bridge, then click OK. \nYou can also set the credentials manually by cliking SET CREDENTIALS MANUALLY.",
{
modal: true,
fixed: true,
type: 'info',
buttons: [
{
text: "OK",
click: function (e) {
$("#mainWindow").hide();
$("#waitWindow").show();
// Send the infos to Supergiovane
$.getJSON("KNXUltimateRegisterToHueBridge?IP=" + $("#node-config-input-host").val() + "&serverId=" + node.id, (data) => {
this.value = "Connect";
this.disabled = false;
if (data.hasOwnProperty("error")) {
RED.notify(JSON.stringify(data.error),
{
modal: true,
fixed: false,
type: 'error'
});
this.disabled = false;
$("#divDetails").hide()
$("#mainWindow").show();
$("#waitWindow").hide();
return;
}
// Expected { bridge: bridgeConfig, user: createdUser }
$("#node-config-input-name").val(data.bridge.data.name);
// $("#node-config-input-host").val(data.bridge.data.ipaddress);
$("#node-config-input-username").val(data.user.username);
$("#node-config-input-clientkey").val(data.user.clientkey);
$("#node-config-input-bridgeid").val(data.bridge.data.bridgeid);
$("#mainWindow").show();
$("#waitWindow").hide();
$("#divDetails").show()
}).error(function (jqXHR, textStatus, errorThrown) {
RED.notify("Something went wrong. Please create at least a KNX Gateway node first.",
{
modal: false,
fixed: false,
type: 'error'
})
$("#mainWindow").show();
$("#waitWindow").hide();
});
myNotification.close();
}
},
{
text: "SET CREDENTIALS MANUALLY",
click: function (e) {
myNotification.close();
$("#mainWindow").show();
$("#node-config-input-clientkey").removeAttr('disabled');
$("#node-config-input-username").removeAttr('disabled');
$("#DIVrevealBridgeSecrets").hide();
$("#BUTTONrevealBridgeSecrets").hide()
$("#divDetails").show()
$("#waitWindow").hide();
$("#divConnectButton").hide();
}
},
{
text: "CANCEL",
click: function (e) {
myNotification.close();
$("#mainWindow").show();
$("#waitWindow").hide();
//$("#DIVrevealBridgeSecrets").hide()
//$("#BUTTONrevealBridgeSecrets").hide()
}
}]
});
}).error(function (jqXHR, textStatus, errorThrown) {
RED.notify("Something went wrong. Please check the bridge's IP.",
{
modal: false,
fixed: false,
type: 'error'
})
return;
});
});
//#endregion
$("#revealBridgeSecrets").click(function () {
$("#DIVrevealBridgeSecrets").hide();
$.getJSON("KNXUltimateGetPlainHueBridgeCredentials?serverId=" + node.id, (data) => {
$("#TEXTrevealBridgeSecrets").val("Username:" + data.username + "\nClientkey:" + data.clientkey);
$("#DIVrevealBridgeSecrets").show();
}).error(function (jqXHR, textStatus, errorThrown) {
RED.notify("Something went wrong " + errorThrown,
{
modal: false,
fixed: false,
type: 'error'
})
$("#DIVrevealBridgeSecrets").hide();
});
})
},
oneditsave: function () {
// Return to the info tab
try {
RED.sidebar.show("info");
} catch (error) { }
},
label: function () {
return typeof this.name === undefined ? "Hue Bridge " + this.host : this.name + " " + this.host;
}
});
</script>
<script type="text/html" data-template-name="hue-config">
<div id="waitWindow" hidden>
<br/><br/>
<p align="center">
<i class="fa-solid fa-hourglass-start fa-spin-pulse fa-2x"></i><br/><br/>
<span data-i18n="hue-config.properties.wait_message"></span>
</p>
</div>
<div id="mainWindow">
<div class="form-row">
<b><span data-i18n="hue-config.properties.title"></span></b>
<p align='center'> <img src='https://raw.githubusercontent.com/Supergiovane/node-red-contrib-knx-ultimate/master/img/huehub.jpg' width='30%'></p>
<p><span data-i18n="hue-config.properties.caution"></span></p>
</div>
<div class="form-row">
<label for="node-config-input-host">
<i class="fa fa-server"></i> <span data-i18n="hue-config.properties.host"></span></label>
<input type="text" id="node-config-input-host" data-i18n="[placeholder]hue-config.properties.host_placeholder" placeholder="Write here the HUE bridge's IP, then click CONNECT">
</div>
<div class="form-row" id="divConnectButton">
<label><i class="fa fa-sign-in"></i> <span data-i18n="hue-config.properties.getinfocam"></span></label>
<input type="button" id="getinfocam" class="ui-button ui-corner-all ui-widget"
style="background-color:#AEE1FF;width:150px" data-i18n="[value]hue-config.properties.connect" value="CONNECT">
</div>
<div id="divDetails" hidden>
<div class="form-row">
<label for="node-config-input-name">
<i class="fa fa-tag"></i>
<span data-i18n="hue-config.properties.node-config-input-name"></span>
</label>
<input type="text" id="node-config-input-name" style="margin-left:5px;">
</div>
<div class="form-row">
<label for="node-config-input-bridgeid">
<i class="fa fa-tag"></i>
<span data-i18n="hue-config.properties.bridge_id"></span>
</label>
<input type="text" id="node-config-input-bridgeid">
</div>
<div class="form-row">
<label for="node-config-input-username"> <span data-i18n="hue-config.properties.username"></span></label>
<input type="password" id="node-config-input-username" placeholder="" disabled>
</div>
<div class="form-row">
<label for="node-config-input-clientkey"> <span data-i18n="hue-config.properties.client_key"></span></label>
<input type="password" id="node-config-input-clientkey" placeholder="" disabled>
</div>
<div class="form-row" id="BUTTONrevealBridgeSecrets">
<label><i class="fa fa-magic"></i> <span data-i18n="hue-config.properties.secrets"></span></label>
<input type="button" id="revealBridgeSecrets" class="ui-button ui-corner-all ui-widget"
style="background-color:#ffb1ae;width:150px" data-i18n="[value]hue-config.properties.reveal">
</div>
<div class="form-row" id="DIVrevealBridgeSecrets" hidden>
<label><i class="fa fa-file-text-o"></i> -> </label>
<textarea type="textarea" rows="3" cols="250" id="TEXTrevealBridgeSecrets"></textarea>
</div>
</div>
</div>
</script>