Skip to content

Commit

Permalink
fix: Fix duplicate action being published under rare circumstances K…
Browse files Browse the repository at this point in the history
  • Loading branch information
Koenkk committed Dec 15, 2023
1 parent 05485ec commit 172a386
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,14 @@ export function mapNumberRange(value: number, fromLow: number, fromHigh: number,
return precisionRound(mappedValue, precision);
}

const transactionStore: {[s: string]: number} = {};
const transactionStore: {[s: string]: number[]} = {};
export function hasAlreadyProcessedMessage(msg: Fz.Message, model: Definition, ID: number=null, key: string=null) {
if (model.meta && model.meta.publishDuplicateTransaction) return false;
const currentID = ID !== null ? ID : msg.meta.zclTransactionSequenceNumber;
key = key || msg.device.ieeeAddr;
if (transactionStore[key] === currentID) return true;
transactionStore[key] = currentID;
if (transactionStore[key]?.includes(currentID)) return true;
// Keep last 5, as they might come in different order: https://github.com/Koenkk/zigbee2mqtt/issues/20024
transactionStore[key] = [currentID, ...transactionStore[key]].slice(0, 5);
return false;
}

Expand Down

0 comments on commit 172a386

Please sign in to comment.