Skip to content

Commit

Permalink
Fix wrong value retained after a period of consumption stability
Browse files Browse the repository at this point in the history
  • Loading branch information
fmartinou committed Oct 24, 2022
1 parent 7664d75 commit a64090c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
4 changes: 3 additions & 1 deletion app/teleinfo/TicMode.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class TicMode {
this.currentFrame = {};
this.eventEmitter = new EventEmitter();
this.lastEmitTime = Date.now();
this.lastFrameSent = {};

// Graceful exit
process.on('SIGTERM', () => this.disconnect());
Expand Down Expand Up @@ -122,6 +123,7 @@ class TicMode {
log.debug(`Dispatch frame ${JSON.stringify(this.currentFrame)}`);
this.eventEmitter.emit('frame', this.currentFrame);
this.lastEmitTime = currentTime;
this.lastFrameSent = this.currentFrame;
} else {
log.debug(`Ignoring MQTT emission because of emit interval (Emit interval : ${emitInterval} - Last emit time : ${this.lastEmitTime} - Current time : ${currentTime}`);
}
Expand Down Expand Up @@ -237,7 +239,7 @@ class TicMode {
* @return {*|boolean}
*/
isSameFrame() {
return deepEqual(this.currentFrame, this.previousFrame);
return deepEqual(this.currentFrame, this.lastFrameSent);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions app/teleinfo/TicMode.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ test('processData should not publish event when frame date is under emit interva
test('processData should not publish event when frame is identical', async () => {
const ticMode = new TicMode();
jest.spyOn(ticMode.eventEmitter, 'emit').mockImplementation(() => {});
ticMode.previousFrame = {
ticMode.lastFrameSent = {
IDENTICAL: 'IDENTICAL',
};
ticMode.currentFrame = {
Expand Down Expand Up @@ -202,7 +202,7 @@ test('processData should reset frame when frame starts', async () => {

test('isSameFrame should return true when frame is same as previous one', () => {
const ticMode = new TicMode();
ticMode.previousFrame = {
ticMode.lastFrameSent = {
ADCO: {
raw: '12345678901',
value: 12345678901,
Expand Down Expand Up @@ -283,7 +283,7 @@ test('isSameFrame should return true when frame is same as previous one', () =>

test('isSameFrame should return true when frame is same as previous one but keys shuffled', async () => {
const ticMode = new TicMode();
ticMode.previousFrame = {
ticMode.lastFrameSent = {
OPTARIF: {
raw: 'HC..',
value: 'HC',
Expand Down
3 changes: 3 additions & 0 deletions docs/changelog/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## dev
- :fire: Fix wrong value retained after a period of consumption stability

## 8.1.3
- :fire: Rollback "Fix home-assistant configuration not republished when the MQTT broker is restarted (without retain option)"

Expand Down

0 comments on commit a64090c

Please sign in to comment.