penguin/homekey-go

homekey-go

commit 388041c3fc18253190554d6d29e6079f0875d180

author斟酌 鵬兄 <tgckpg@gmail.com>
date2026-10-15T11:50:44Z
subjectAdded auto refresh toggle
commit 388041c3fc18253190554d6d29e6079f0875d180
Author: 斟酌 鵬兄 <tgckpg@gmail.com>
Date:   2026-10-15T11:50:44Z

    Added auto refresh toggle
---
 build.env              |  2 +-
 ha-app/CHANGELOG.md    |  4 ++++
 ha-app/config.yaml     |  2 +-
 internal/app/page.html | 12 ++++++++++--
 4 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/build.env b/build.env
index 0f0870d..a9e9c33 100644
--- a/build.env
+++ b/build.env
@@ -1,4 +1,4 @@
 IMAGE_NAME=ghcr.io/tgckpg/homekey-go
-IMAGE_TAG=0.0.17
+IMAGE_TAG=0.0.18
 
 APT_PROXY=
diff --git a/ha-app/CHANGELOG.md b/ha-app/CHANGELOG.md
index 33ccff4..d5aaf82 100644
--- a/ha-app/CHANGELOG.md
+++ b/ha-app/CHANGELOG.md
@@ -1,3 +1,7 @@
+## 0.0.18
+
+- Added auto refresh toggle
+
 ## 0.0.17
 
 - Fixed a bug that disconnect could report success after removing a failed preparation
diff --git a/ha-app/config.yaml b/ha-app/config.yaml
index 84c784d..f62de6e 100644
--- a/ha-app/config.yaml
+++ b/ha-app/config.yaml
@@ -1,5 +1,5 @@
 name: Home Key Go
-version: "0.0.17"
+version: "0.0.18"
 slug: homekey_go
 description: HomeKit virtual lock with Apple Home Key NFC authentication
 url: https://sgit.k8s.astropenguin.net/penguin/homekey-go/
diff --git a/internal/app/page.html b/internal/app/page.html
index 2afe23d..a313851 100644
--- a/internal/app/page.html
+++ b/internal/app/page.html
@@ -5,7 +5,7 @@
 :root{font:16px system-ui;color:#172735;background:#f4f6f8}body{max-width:920px;margin:30px auto;padding:0 20px}h1{margin-bottom:8px}h2{margin-top:0}article,section{background:white;border:1px solid #ccd6df;border-radius:12px;padding:20px;margin:18px 0}button,input,select{font:inherit}button{padding:9px 16px;border:1px solid #bcc9d5;border-radius:6px;background:white;cursor:pointer}button.primary{background:#136fb1;color:white;border-color:#136fb1}button:disabled{opacity:.5;cursor:default}.toolbar{display:flex;gap:10px;flex-wrap:wrap;margin:16px 0}.muted,small{color:#536675}.error{color:#a02020}label{display:block;margin:14px 0}input:not([type=checkbox]),select{box-sizing:border-box;display:block;width:100%;margin-top:6px;padding:9px;border:1px solid #bcc9d5;border-radius:5px}input[type=checkbox]{margin-right:10px;accent-color:#136fb1}fieldset{border:1px solid #ccd6df;border-radius:6px}dialog{border:1px solid #bcc9d5;border-radius:12px;padding:24px;max-width:520px;width:calc(100% - 90px)}dialog::backdrop{background:#17273577}code{font-size:26px}.badge{font-size:14px;background:#eaf1f6;border-radius:4px;padding:4px 7px}.reader{display:flex;justify-content:space-between;gap:12px;align-items:center;border-top:1px solid #e0e7ed;padding:14px 0}.reader:first-child{border-top:0}.reader p{margin:4px 0}.empty{color:#536675}.notice{min-height:24px}details{margin:15px 0}
 </style></head><body>
 <h1>Home Key locks</h1><p class="muted">Assign NFC readers and physical locks to a Home Key lock, then pair with Apple Home.</p>
-<div class="toolbar"><button id="add-lock" class="primary">Add lock</button><button id="save" disabled>Save configuration</button></div>
+<div class="toolbar"><button id="add-lock" class="primary">Add lock</button><button id="save" disabled>Save configuration</button><label><input id="auto-refresh" type="checkbox">Auto Refresh</label></div>
 <p id="message" class="notice" role="status"></p><main id="locks"></main>
 <section><h2>NFC readers</h2><p class="muted">Readers can be assigned to several locks in the same Apple Home.</p><div id="readers"></div><div class="toolbar"><button id="add-reader">Add reader</button><button id="scan">Scan Bluetooth</button></div><p id="discovery-status" class="muted" role="status"></p></section>
 <section><h2>Physical locks</h2><p class="muted">Scanning connects unregistered Sesame locks immediately. Wait for Ready to register below, then click Register. Set positions after registration and assign the lock to a Home Key lock.</p><div id="physical-locks"></div><div class="toolbar"><button id="add-physical">Add physical lock</button><button id="scan-physical">Scan for locks</button></div><p id="physical-discovery-status" class="muted" role="status"></p></section>
@@ -112,5 +112,13 @@ function updateCalibration(){if(!calibrating)return;const p=physicalLocks.find(p
 }
 async function physicalAction(action){if(calibrationBusy||!calibrating)return;calibrationBusy=true;$('calibration-error').textContent='';updateCalibration();try{await request('api/physical-locks/'+encodeURIComponent(calibrating)+'/'+action,{method:'POST',headers:{'X-Homekey-Action':'physical-lock'}});await refresh()}catch(e){$('calibration-error').textContent=e.message}finally{calibrationBusy=false;updateCalibration()}}
 $('capture-lock').onclick=()=>physicalAction('set-lock');$('capture-unlock').onclick=()=>physicalAction('set-unlock');$('capture-boundary').onclick=()=>physicalAction('set-boundary');$('test-lock').onclick=()=>physicalAction('lock');$('test-unlock').onclick=()=>physicalAction('unlock');$('close-calibration').onclick=()=>{$('calibration-dialog').close();calibrating=null};
-load().then(()=>Promise.all([scan(),scanPhysical()])).catch(e=>message(e.message,true));setInterval(()=>{if(!restarting){refresh();refreshConnections()}},2000);
+load().then(()=>Promise.all([scan(),scanPhysical()])).catch(e=>message(e.message,true));let autoRefreshTimer=null;
+$('auto-refresh').onchange=()=>{
+ if(autoRefreshTimer!==null){clearInterval(autoRefreshTimer);autoRefreshTimer=null}
+ if($('auto-refresh').checked){
+  const poll=()=>{if(!restarting){refresh();refreshConnections()}};
+  poll();
+  autoRefreshTimer=setInterval(poll,2000);
+ }
+};
 </script></body></html>