feat: ElevenLabs TTS George voice + fix HA toggle optimistic update

This commit is contained in:
2026-05-31 05:58:22 +00:00
parent b080ecb4bd
commit a96f8a3f85
4 changed files with 103 additions and 14 deletions
+15 -2
View File
@@ -1322,10 +1322,23 @@ function renderHATable(entities) {
}
function haToggle(entityId, currentState, el) {
const ON_STATES = ['on','home','open','playing','mowing','armed_home','armed_away','armed_night','active'];
const wasOn = ON_STATES.includes(currentState);
el.style.opacity = '0.5';
apiPost('ha_toggle', {entity_id: entityId, state: currentState}, () => {
apiPost('ha_toggle', {entity_id: entityId, state: currentState}, (res) => {
el.style.opacity = '1';
loadHA();
if (res.ok) {
// Optimistic update — flip state in cache so re-render shows new state immediately
const ent = _haEntities.find(e => e.entity_id === entityId);
if (ent) {
ent.state = wasOn ? 'off' : 'on';
filterHATable();
}
// Also sync from HA after 3s (actual state confirmation)
setTimeout(loadHA, 3000);
} else {
toast('Toggle failed (code ' + (res.code||'?') + ')', 'err');
}
});
}