Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable auto-refresh if desired #166

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,11 @@
},
"refreshInterval": {
"title": "Refresh Interval",
"description": "How often to update Homekit in minutes",
"description": "How often to update Homekit in minutes. Setting to 0 will disable auto-refresh and only refresh when queried by HomeKit",
"type": "integer",
"required": false,
"placeholder": 1,
"minimum": 1,
"minimum": 0,
"maximum": 60
},
"connectionTime": {
Expand Down
75 changes: 40 additions & 35 deletions src/V2/platformAccessory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,15 +149,17 @@ export class iRobotPlatformAccessoryV1 {
}
}
}
const interval = setInterval(() => {
this.platform.log.debug(this.logPrefix, 'Auto-Updating state');
this.roomba.getMission()
.then(mission => this.events.emit('update', mission))
.catch(err => this.platform.log.error(this.logPrefix, 'Failed To Auto Update State:\n', err));
}, this.platform.config.refreshInterval * 60000 || 60000);
this.platform.api.on('shutdown', () => {
clearInterval(interval);
});
if(this.platform.config.refreshInterval > 0) {
const interval = setInterval(() => {
this.platform.log.debug(this.logPrefix, 'Auto-Updating state');
this.roomba.getMission()
.then(mission => this.events.emit('update', mission))
.catch(err => this.platform.log.error(this.logPrefix, 'Failed To Auto Update State:\n', err));
}, this.platform.config.refreshInterval * 60000 || 60000);
this.platform.api.on('shutdown', () => {
clearInterval(interval);
});
}
}
}

Expand Down Expand Up @@ -340,19 +342,20 @@ export class iRobotPlatformAccessoryV2 {
}
}
}
const interval = setInterval(() => {
this.platform.log.debug(this.logPrefix, 'Auto-Updating state');
this.roomba.getMission()
.then(mission => {

this.events.emit('update', mission);
})
.catch(err => this.platform.log.error(this.logPrefix, 'Failed To Update State:\n', err));
}, this.platform.config.refreshInterval * 60000 || 60000);
this.platform.api.on('shutdown', () => {
clearInterval(interval);
this.roomba.end();
});
if(this.platform.config.refreshInterval > 0) {
const interval = setInterval(() => {
this.platform.log.debug(this.logPrefix, 'Auto-Updating state');
this.roomba.getMission()
.then(mission => {
this.events.emit('update', mission);
})
.catch(err => this.platform.log.error(this.logPrefix, 'Failed To Update State:\n', err));
}, this.platform.config.refreshInterval * 60000 || 60000);
this.platform.api.on('shutdown', () => {
clearInterval(interval);
this.roomba.end();
});
}
this.roomba.on('update', (mission: MissionV3) => {
this.events.emit('update', mission);
});
Expand Down Expand Up @@ -536,19 +539,21 @@ export class iRobotPlatformAccessoryV3 {
}
}
}
const interval = setInterval(() => {
this.platform.log.debug(this.logPrefix, 'Auto-Updating state');
this.roomba.getMission()
.then(mission => {
this.events.emit('update', mission);
})
.catch(err => this.platform.log.error(this.logPrefix, 'Failed To Update State:\n', err));
}, this.platform.config.refreshInterval * 60000 || 60000);
this.platform.api.on('shutdown', () => {
this.platform.log.info(this.logPrefix, 'Disconnecting...');
clearInterval(interval);
this.roomba.end();
});
if(this.platform.config.refreshInterval > 0) {
const interval = setInterval(() => {
this.platform.log.debug(this.logPrefix, 'Auto-Updating state');
this.roomba.getMission()
.then(mission => {
this.events.emit('update', mission);
})
.catch(err => this.platform.log.error(this.logPrefix, 'Failed To Update State:\n', err));
}, this.platform.config.refreshInterval * 60000 || 60000);
this.platform.api.on('shutdown', () => {
this.platform.log.info(this.logPrefix, 'Disconnecting...');
clearInterval(interval);
this.roomba.end();
});
}
this.roomba.on('update', (mission: MissionV3) => {
this.events.emit('update', mission);
});
Expand Down