Skip to content

Commit

Permalink
fix: another sync issue
Browse files Browse the repository at this point in the history
  • Loading branch information
TheNoim committed Jan 18, 2023
1 parent 7f72c6e commit 6ffb1f7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
11 changes: 5 additions & 6 deletions reactive_home/src/composeables/useNewBoolean.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,11 @@ export function useNewBoolean(state: FullfilledUseState, debug = false) {
const lastChanged = ref(state.value.last_changed);

// Local state changes
watch(localValue, (newLocalValue, oldLocalValue) => {
watch(localValue, (newLocalValue) => {
if (skipNextWatch) {
skipNextWatch = false;
return;
}
if (newLocalValue === oldLocalValue) {
return;
}
if (debug) {
console.log(`call(${state.value.entity_id}): updateHASSState`);
}
Expand All @@ -62,8 +59,10 @@ export function useNewBoolean(state: FullfilledUseState, debug = false) {
skipContexts.splice(contextIndex, 1);
return;
}
skipNextWatch = true;
localValue.value = stringBoolToBool(newEntityState.state);
if (localValue.value !== stringBoolToBool(newEntityState.state)) {
skipNextWatch = true;
localValue.value = stringBoolToBool(newEntityState.state);
}
lastChanged.value = newEntityState.last_changed;
}
);
Expand Down
21 changes: 11 additions & 10 deletions reactive_home/src/composeables/useNewLight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,11 @@ export function useNewLight(state: FullfilledUseState, debug = false) {
() => {
return { value: localValues.value, brightness: localValues.brightness };
},
(newLocalValues, oldLocalValues) => {
(newLocalValues) => {
if (skipNextWatch) {
skipNextWatch = false;
return;
}
if (
newLocalValues.value === oldLocalValues.value &&
newLocalValues.brightness === oldLocalValues.brightness
) {
return;
}
if (debug) {
console.log(`call(${state.value.entity_id}): updateHASSState`);
}
Expand Down Expand Up @@ -107,9 +101,16 @@ export function useNewLight(state: FullfilledUseState, debug = false) {
skipContexts.splice(contextIndex, 1);
return;
}
skipNextWatch = true;
localValues.value = stringBoolToBool(newEntityState.state);
localValues.brightness = getBrightnessFromAttribute(newEntityState);
if (localValues.value !== stringBoolToBool(newEntityState.state)) {
skipNextWatch = true;
localValues.value = stringBoolToBool(newEntityState.state);
}
if (
localValues.brightness !== getBrightnessFromAttribute(newEntityState)
) {
skipNextWatch = true;
localValues.brightness = getBrightnessFromAttribute(newEntityState);
}
}
);

Expand Down

0 comments on commit 6ffb1f7

Please sign in to comment.