mirror of
https://github.com/myronblair/jarvis
synced 2026-06-30 17:50:23 -05:00
feat: ElevenLabs TTS George voice + fix HA toggle optimistic update
This commit is contained in:
@@ -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');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user