//**************************** // Wizard Nanoleaf //**************************** const nanoleafWizard = (() => { const retryInterval = 2; async function createNanoleafUserAuthorization() { const host = conf_editor.getEditor("root.specificOptions.host").getValue(); const params = { host }; let retryTime = 30; const UserInterval = setInterval(async function () { retryTime -= retryInterval; $("#connectionTime").html(retryTime); if (retryTime <= 0) { handleTimeout(); } else { const res = await requestLedDeviceAddAuthorization('nanoleaf', params); handleResponse(res); } }, retryInterval * 1000); function handleTimeout() { clearInterval(UserInterval); showNotification( 'warning', $.i18n('wiz_nanoleaf_failure_auth_token'), $.i18n('wiz_nanoleaf_failure_auth_token_t') ); resetWizard(true); } function handleResponse(res) { if (res && !res.error) { const response = res.info; if (jQuery.isEmptyObject(response)) { debugMessage(`${retryTime}: Power On/Off button not pressed or device not reachable`); } else { const token = response.auth_token; if (token !== 'undefined') { conf_editor.getEditor("root.specificOptions.token").setValue(token); } clearInterval(UserInterval); resetWizard(true); } } else { clearInterval(UserInterval); resetWizard(true); } } } return { start: function () { const nanoleaf_user_auth_title = 'wiz_nanoleaf_user_auth_title'; const nanoleaf_user_auth_intro = 'wiz_nanoleaf_user_auth_intro'; $('#wiz_header').html( `${$.i18n(nanoleaf_user_auth_title)}` ); $('#wizp1_body').html( `
${$.i18n(nanoleaf_user_auth_intro)}
` ); $('#wizp1_footer').html( `` ); $('#wizp3_body').html( `${$.i18n('wiz_nanoleaf_press_onoff_button')}