mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
Fix Nanoleaf, add user auth token wizard
This commit is contained in:
@@ -566,8 +566,8 @@
|
||||
"edt_conf_webc_port_title": "HTTP Port",
|
||||
"edt_conf_webc_sslport_expl": "Port for the WebServer, RPC and WebSocket HTTPS connections",
|
||||
"edt_conf_webc_sslport_title": "HTTPS Port",
|
||||
"edt_dev_auth_key_title": "Authentication Token",
|
||||
"edt_dev_auth_key_title_info": "Authentication Token required to acccess the device",
|
||||
"edt_dev_auth_key_title": "Authorization Token",
|
||||
"edt_dev_auth_key_title_info": "Authorization Token required to acccess the device",
|
||||
"edt_dev_enum_sub_min_cool_adjust": "Subtract cool white",
|
||||
"edt_dev_enum_sub_min_warm_adjust": "Subtract warm white",
|
||||
"edt_dev_enum_subtract_minimum": "Subtract minimum",
|
||||
@@ -1123,6 +1123,11 @@
|
||||
"wiz_identify_light": "Identify $1",
|
||||
"wiz_ids_disabled": "Deactivated",
|
||||
"wiz_ids_entire": "Whole picture",
|
||||
"wiz_nanoleaf_failure_auth_token": "Please press the Nanoleaf Power On/Off button within 30 seconds",
|
||||
"wiz_nanoleaf_failure_auth_token_t": "User authorization token generating timeout",
|
||||
"wiz_nanoleaf_press_onoff_button": "Please press the Power On/Off button on your Nanoleaf device for 5-7 seconds",
|
||||
"wiz_nanoleaf_user_auth_intro": "The wizard supports you in generating a user authorization token required to allowing Hyperion to access the device.",
|
||||
"wiz_nanoleaf_user_auth_title": "Authorization Token Generating Wizard",
|
||||
"wiz_noLights": "No $1 found! Please get the lights connected to the network or configure them manually.",
|
||||
"wiz_pos": "Position/State",
|
||||
"wiz_rgb_expl": "The color dot switches every x seconds the color (red, green), at the same time your LEDs switch the color too. Answer the questions at the bottom to check/correct your byte order.",
|
||||
|
@@ -1060,6 +1060,13 @@ $(document).ready(function () {
|
||||
var hue_title = 'wiz_hue_title';
|
||||
changeWizard(data, hue_title, startWizardPhilipsHue);
|
||||
}
|
||||
else if (ledType == "nanoleaf") {
|
||||
var ledWizardType = ledType;
|
||||
var data = { type: ledWizardType };
|
||||
var nanoleaf_user_auth_title = 'wiz_nanoleaf_user_auth_title';
|
||||
changeWizard(data, nanoleaf_user_auth_title, startWizardNanoleafUserAuth);
|
||||
$('#btn_wiz_holder').hide();
|
||||
}
|
||||
else if (ledType == "atmoorb") {
|
||||
var ledWizardType = (this.checked) ? "atmoorb" : ledType;
|
||||
var data = { type: ledWizardType };
|
||||
@@ -1341,6 +1348,13 @@ $(document).ready(function () {
|
||||
|
||||
if (host === "") {
|
||||
conf_editor.getEditor("root.generalOptions.hardwareLedCount").setValue(1);
|
||||
switch (ledType) {
|
||||
|
||||
case "nanoleaf":
|
||||
$('#btn_wiz_holder').hide();
|
||||
break;
|
||||
default:
|
||||
}
|
||||
}
|
||||
else {
|
||||
let params = {};
|
||||
@@ -1352,6 +1366,8 @@ $(document).ready(function () {
|
||||
break;
|
||||
|
||||
case "nanoleaf":
|
||||
$('#btn_wiz_holder').show();
|
||||
|
||||
var token = conf_editor.getEditor("root.specificOptions.token").getValue();
|
||||
if (token === "") {
|
||||
return;
|
||||
@@ -2165,15 +2181,8 @@ function updateElements(ledType, key) {
|
||||
case "nanoleaf":
|
||||
var ledProperties = devicesProperties[ledType][key];
|
||||
|
||||
if (ledProperties && ledProperties.panelLayout.layout) {
|
||||
//Identify non-LED type panels, e.g. Rhythm (1) and Shapes Controller (12)
|
||||
var nonLedNum = 0;
|
||||
for (const panel of ledProperties.panelLayout.layout.positionData) {
|
||||
if (panel.shapeType === 1 || panel.shapeType === 12) {
|
||||
nonLedNum++;
|
||||
}
|
||||
}
|
||||
hardwareLedCount = ledProperties.panelLayout.layout.numPanels - nonLedNum;
|
||||
if (ledProperties) {
|
||||
hardwareLedCount = ledProperties.ledCount;
|
||||
}
|
||||
conf_editor.getEditor("root.generalOptions.hardwareLedCount").setValue(hardwareLedCount);
|
||||
|
||||
|
@@ -2187,3 +2187,90 @@ async function identify_atmoorb_device(orbId) {
|
||||
}
|
||||
}
|
||||
|
||||
//****************************
|
||||
// Nanoleaf Token Wizard
|
||||
//****************************
|
||||
var lights = null;
|
||||
function startWizardNanoleafUserAuth(e) {
|
||||
//create html
|
||||
var nanoleaf_user_auth_title = 'wiz_nanoleaf_user_auth_title';
|
||||
var nanoleaf_user_auth_intro = 'wiz_nanoleaf_user_auth_intro';
|
||||
|
||||
$('#wiz_header').html('<i class="fa fa-magic fa-fw"></i>' + $.i18n(nanoleaf_user_auth_title));
|
||||
$('#wizp1_body').html('<h4 style="font-weight:bold;text-transform:uppercase;">' + $.i18n(nanoleaf_user_auth_title) + '</h4><p>' + $.i18n(nanoleaf_user_auth_intro) + '</p>');
|
||||
|
||||
$('#wizp1_footer').html('<button type="button" class="btn btn-primary" id="btn_wiz_cont"><i class="fa fa-fw fa-check"></i>'
|
||||
+ $.i18n('general_btn_continue') + '</button><button type="button" class="btn btn-danger" data-dismiss="modal"><i class="fa fa-fw fa-close"></i>'
|
||||
+ $.i18n('general_btn_cancel') + '</button>');
|
||||
|
||||
$('#wizp3_body').html('<span>' + $.i18n('wiz_nanoleaf_press_onoff_button') + '</span> <br /><br /><center><span id="connectionTime"></span><br /><i class="fa fa-cog fa-spin" style="font-size:100px"></i></center>');
|
||||
|
||||
if (getStorage("darkMode") == "on")
|
||||
$('#wizard_logo').attr("src", 'img/hyperion/logo_negativ.png');
|
||||
|
||||
//open modal
|
||||
$("#wizard_modal").modal({ backdrop: "static", keyboard: false, show: true });
|
||||
|
||||
//listen for continue
|
||||
$('#btn_wiz_cont').off().on('click', function () {
|
||||
createNanoleafUserAuthorization();
|
||||
$('#wizp1').toggle(false);
|
||||
$('#wizp3').toggle(true);
|
||||
});
|
||||
}
|
||||
|
||||
function createNanoleafUserAuthorization() {
|
||||
var host = conf_editor.getEditor("root.specificOptions.host").getValue();
|
||||
|
||||
let params = { host: host };
|
||||
|
||||
var retryTime = 30;
|
||||
var retryInterval = 2;
|
||||
|
||||
var UserInterval = setInterval(function () {
|
||||
|
||||
$('#wizp1').toggle(false);
|
||||
$('#wizp3').toggle(true);
|
||||
|
||||
(async () => {
|
||||
|
||||
retryTime -= retryInterval;
|
||||
$("#connectionTime").html(retryTime);
|
||||
if (retryTime <= 0) {
|
||||
abortConnection(UserInterval);
|
||||
clearInterval(UserInterval);
|
||||
|
||||
showNotification('warning', $.i18n('wiz_nanoleaf_failure_auth_token'), $.i18n('wiz_nanoleaf_failure_auth_token_t'))
|
||||
|
||||
resetWizard(true);
|
||||
}
|
||||
else {
|
||||
const res = await requestLedDeviceAddAuthorization('nanoleaf', params);
|
||||
if (res && !res.error) {
|
||||
var response = res.info;
|
||||
|
||||
if (jQuery.isEmptyObject(response)) {
|
||||
debugMessage(retryTime + ": Power On/Off button not pressed or device not reachable");
|
||||
} else {
|
||||
$('#wizp1').toggle(false);
|
||||
$('#wizp3').toggle(false);
|
||||
|
||||
var token = response.auth_token;
|
||||
if (token != 'undefined') {
|
||||
conf_editor.getEditor("root.specificOptions.token").setValue(token);
|
||||
}
|
||||
clearInterval(UserInterval);
|
||||
resetWizard(true);
|
||||
}
|
||||
} else {
|
||||
$('#wizp1').toggle(false);
|
||||
$('#wizp3').toggle(false);
|
||||
clearInterval(UserInterval);
|
||||
resetWizard(true);
|
||||
}
|
||||
}
|
||||
})();
|
||||
|
||||
}, retryInterval * 1000);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user