Skip to content

Commit

Permalink
toZigbee: update color_mode on scene_recall
Browse files Browse the repository at this point in the history
  • Loading branch information
sjorge committed Mar 16, 2021
1 parent e7bc843 commit 99db784
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions converters/toZigbee.js
Original file line number Diff line number Diff line change
Expand Up @@ -3839,19 +3839,33 @@ const converters = {
const isGroup = entity.constructor.name === 'Group';
const metaKey = `${sceneid}_${groupid}`;
if (isGroup) {
let readColorMode = false;
const membersState = {};
for (const member of entity.members) {
if (member.meta.hasOwnProperty('scenes') && member.meta.scenes.hasOwnProperty(metaKey)) {
if (member.meta.scenes[metaKey].state.hasOwnProperty('color') ||
member.meta.scenes[metaKey].state.hasOwnProperty('color_temp')) {
readColorMode = true;
}
membersState[member.getDevice().ieeeAddr] = member.meta.scenes[metaKey].state;
} else {
meta.logger.warn(`Unknown scene was recalled for ${member.getDevice().ieeeAddr}, can't restore state.`);
membersState[member.getDevice().ieeeAddr] = {};
}
}

// read colorMode if color or color_temp in scene state, as the color_mode might have changed
if (readColorMode) {
await entity.read('lightingColorCtrl', ['colorMode']);
}
return {membersState};
} else {
if (entity.meta.scenes.hasOwnProperty(metaKey)) {
// read colorMode if color or color_temp in scene state, as the color_mode might have changed
if (entity.meta.scenes[metaKey].state.hasOwnProperty('color') ||
entity.meta.scenes[metaKey].state.hasOwnProperty('color_temp')) {
await entity.read('lightingColorCtrl', ['colorMode']);
}
return {state: entity.meta.scenes[metaKey].state};
} else {
meta.logger.warn(`Unknown scene was recalled for ${entity.deviceIeeeAddress}, can't restore state.`);
Expand Down

0 comments on commit 99db784

Please sign in to comment.