Skip to content

Commit

Permalink
light on/off: fix timing / prevent unnecessary updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Garfonso committed Feb 10, 2024
1 parent 4bebfd1 commit 12ca739
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/converters/light.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const SUPPORT_EFFECT = 4;

async function readAttributesOnSwitchOn(entity) {
const attributeValues = {};
let updated = false;
for (const attr of Object.values(entity.context.ATTRIBUTES)) {
const id = attr.getId || attr.setId;
if (id) {
Expand All @@ -62,12 +63,15 @@ async function readAttributesOnSwitchOn(entity) {
for (const [name, attribute] of Object.entries(attributeValues)) {
if (entity.attributes[name] === null) { //if not updated, set value read:
entity.attributes[name] = attribute;
updated = true;
}
}
}

//now tell frontend about update:
adapterData.server.updateEntityInFrontend(entity);
if (updated) {
adapterData.server.updateEntityInFrontend(entity);
}
}

function _lightAdvancedAddState(states, objects, entity) {
Expand Down

0 comments on commit 12ca739

Please sign in to comment.