@ronniepettersson/homebridge-dummy
Version:
Create Homebridge accessories to help with automation and control — scheduling, delays, sensors, commands, webhooks, and more
2 lines (1 loc) • 3.89 kB
JavaScript
;(()=>{var a="Homebridge Dummy";var g={github:'<a target="_blank" href="https://github.com/mpatfield/homebridge-dummy/">GitHub</a>',migration:'<a target="_blank" href="https://github.com/mpatfield/homebridge-dummy?tab=readme-ov-file#v10-migration">GitHub</a>',dummy:a};function m(e){document.querySelectorAll("[i18n]").forEach(t=>{let i=t.getAttribute("i18n"),n=e.config[i],o=t.getAttribute("i18n_replace");o&&(n=n.replace("%s",g[o])),t.innerHTML=n})}function x(e){let t=["span","label","legend","option","p"];Array.from(window.parent.document.querySelectorAll(t.join(","))).sort((n,o)=>t.indexOf(n.tagName.toLowerCase())-t.indexOf(o.tagName.toLowerCase())).forEach(n=>{let o=n.innerHTML;o=o.replaceAll(/\$\{config\.(title|description|enumNames)\.([^}]+)\}/g,(r,d,s)=>e.config[d]&&typeof e.config[d]=="object"&&s in e.config[d]?e.config[d][s]:r),n.innerHTML!==o&&(n.innerHTML=o)})}function c(e){let t=Array.from(window.parent.document.querySelectorAll("fieldset legend"));for(let i of t){let o=i.closest("fieldset")?.querySelector('input[type="text"][name="name"]');o&&i.textContent!==(o.value||e.config.title.accessory)&&(i.textContent=o.value!==""?o.value:e.config.title.accessory),o&&!o.dataset.accessoryNameListener&&(o.addEventListener("input",()=>c(e)),o.dataset.accessoryNameListener="true")}}function l(){if(typeof crypto<"u"){if(crypto.randomUUID)return crypto.randomUUID();if(crypto.getRandomValues)return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{let t=crypto.getRandomValues(new Uint8Array(1))[0]&15;return(e==="x"?t:t&3|8).toString(16)})}return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{let t=Math.random()*16|0;return(e==="x"?t:t&3|8).toString(16)})}async function f(e){let t=!1;e.forEach(i=>{i.accessories?.forEach(n=>{n.id===void 0&&(n.id=l(),t=!0),n.limiter!==void 0&&n.limiter.id===void 0&&(n.limiter.id=l(),t=!0)})}),t&&await homebridge.updatePluginConfig(e)}async function p(e){let t=!1;e.forEach(i=>{i.accessories?.forEach(n=>{let o=n.sensor;typeof o=="string"&&(n.sensor={type:o},t=!0);let r=n.schedule;r?.type==="CRON"&&r.cron!=="CRON_CUSTOM"&&!r.cron?.startsWith("@")&&(n.schedule={...r,cron:"CRON_CUSTOM",cronCustom:r.cron},t=!0)})}),t&&await homebridge.updatePluginConfig(e)}function u(e){document.getElementById("intro").style.display="none",document.getElementById("migration").style.display="none",document.getElementById("support").style.display="block",new MutationObserver(()=>{x(e),c(e)}).observe(window.parent.document.body,{childList:!0,subtree:!0}),homebridge.addEventListener("configChanged",async i=>{let n=i.data;await f(n)}),homebridge.showSchemaForm(),homebridge.hideSpinner(),homebridge.enableSaveButton()}function b(e){document.getElementById("header").style.display="none",document.getElementById("intro").style.display="none",document.getElementById("migration").style.display="block",document.getElementById("skipMigration").addEventListener("click",async()=>{await homebridge.updatePluginConfig([{name:a}]),await homebridge.savePluginConfig(),u(e)}),document.getElementById("doMigration").addEventListener("click",async()=>{await homebridge.updatePluginConfig([{name:a,migrationNeeded:!0}]),await homebridge.savePluginConfig(),homebridge.closeSettings(),homebridge.toast.info(e.config.migrationRestartDescription.replace("%s",a),e.config.migrationRestartTitle)})}function S(e){document.getElementById("showSettings").addEventListener("click",async()=>{await homebridge.updatePluginConfig([{name:a}]),u(e)}),document.getElementById("showMigration").addEventListener("click",()=>{b(e)}),document.getElementById("intro").style.display="block",homebridge.hideSpinner()}homebridge.disableSaveButton(),homebridge.showSpinner();(async()=>{let e=await homebridge.i18nCurrentLang(),t=await homebridge.request("i18n",e);m(t);let i=await homebridge.getPluginConfig();i.length?(await p(i),u(t)):S(t)})();})();