Skip to content

Commit

Permalink
fix: resubmit
Browse files Browse the repository at this point in the history
  • Loading branch information
TheNoim committed Jan 18, 2023
1 parent 414b30b commit c9009f0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
7 changes: 6 additions & 1 deletion reactive_home/src/composeables/useNewBoolean.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,15 @@ export function useNewBoolean(state: FullfilledUseState, debug = false) {
}, 50);

const localValue = ref(stringBoolToBool(state.value.state));

let skipNextWatch = false;
const lastChanged = ref(state.value.last_changed);

// Local state changes
watch(localValue, (newLocalValue, oldLocalValue) => {
if (skipNextWatch) {
skipNextWatch = false;
return;
}
if (newLocalValue === oldLocalValue) {
return;
}
Expand All @@ -58,6 +62,7 @@ export function useNewBoolean(state: FullfilledUseState, debug = false) {
skipContexts.splice(contextIndex, 1);
return;
}
skipNextWatch = true;
localValue.value = stringBoolToBool(newEntityState.state);
lastChanged.value = newEntityState.last_changed;
}
Expand Down
7 changes: 7 additions & 0 deletions reactive_home/src/composeables/useNewLight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,18 @@ export function useNewLight(state: FullfilledUseState, debug = false) {
lock: false,
});

let skipNextWatch = false;

// Local state changes
watch(
() => {
return { value: localValues.value, brightness: localValues.brightness };
},
(newLocalValues, oldLocalValues) => {
if (skipNextWatch) {
skipNextWatch = false;
return;
}
if (
newLocalValues.value === oldLocalValues.value &&
newLocalValues.brightness === oldLocalValues.brightness
Expand Down Expand Up @@ -101,6 +107,7 @@ export function useNewLight(state: FullfilledUseState, debug = false) {
skipContexts.splice(contextIndex, 1);
return;
}
skipNextWatch = true;
localValues.value = stringBoolToBool(newEntityState.state);
localValues.brightness = getBrightnessFromAttribute(newEntityState);
}
Expand Down

0 comments on commit c9009f0

Please sign in to comment.