Skip to content

Commit

Permalink
fix: stop attribute updates when not_home
Browse files Browse the repository at this point in the history
Previously the timestamp was continuously updated even though no change
happened while a device was not_home. As no change happened, there is no
point in always pushing a new timestamp.

Closes #113
  • Loading branch information
mKeRix committed Feb 27, 2020
1 parent 0d47a54 commit 6e9f31a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
Expand Up @@ -138,4 +138,11 @@ describe('RoomPresenceDistanceSensor', () => {
expect(sensor.state).toBe(STATE_NOT_HOME);
expect(sensor.attributes.distance).toBeUndefined();
});

it('should stop sending attribute updates after not_home has been set', () => {
sensor.state = STATE_NOT_HOME;
sensor.handleNewDistance('room1', 10, true);

expect(sensor.attributes.lastUpdatedAt).toBeUndefined();
});
});
Expand Up @@ -53,7 +53,7 @@ export class RoomPresenceDistanceSensor extends Sensor {
this.attributes.distance = closestInRange[1].distance;
this.attributes.lastUpdatedAt = closestInRange[1].lastUpdatedAt.toISOString();
}
} else {
} else if (this.state !== STATE_NOT_HOME) {
this.setNotHome();
}
}
Expand Down

0 comments on commit 6e9f31a

Please sign in to comment.