Skip to content

Commit

Permalink
fix(bluetooth-classic): exclude old measurements from preservation
Browse files Browse the repository at this point in the history
  • Loading branch information
mKeRix committed Aug 16, 2020
1 parent 3e1e5b2 commit 10b0e21
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
Expand Up @@ -546,6 +546,26 @@ Requesting information ...
expect(clusterService.publish).not.toHaveBeenCalled();
});

it('should send no pseudo state update if the last recorded distance is too old', () => {
const updateSpy = jest.spyOn(service, 'handleNewRssi').mockResolvedValue();
jest.spyOn(service, 'shouldInquire').mockReturnValue(false);
config.preserveState = true;

const sensor = new RoomPresenceDistanceSensor('bt-test', 'Test', 5);
sensor.distances = {};
sensor.distances['test-instance'] = {
distance: 10,
outOfRange: false,
lastUpdatedAt: new Date(Date.now() - 25 * 1000),
};
const device = { address: 'test', name: 'Test' };

service.updateSensorState(sensor, device);

expect(updateSpy).not.toHaveBeenCalled();
expect(clusterService.publish).not.toHaveBeenCalled();
});

it('should not distribute inquiries if not the leader', () => {
clusterService.isMajorityLeader.mockReturnValue(false);
const inquireSpy = jest.spyOn(service, 'inquireRssi');
Expand Down
Expand Up @@ -296,7 +296,12 @@ export class BluetoothClassicService extends KalmanFilterable(Object, 1.4, 1)
const instanceName = this.configService.get('global').instanceName;
const previousReading = sensor.distances[instanceName];

if (previousReading) {
if (
previousReading &&
Date.now() <
previousReading.lastUpdatedAt.getTime() +
this.calculateCurrentTimeout() * 1000
) {
// emit pseudo update to keep local state alive
const event = new NewRssiEvent(
instanceName,
Expand Down

0 comments on commit 10b0e21

Please sign in to comment.