1
0
mirror of https://github.com/beestat/app.git synced 2026-04-11 11:42:06 -04:00
beestat/js/beestat/poll.js
Jon Ziebell 6d7b4ff3f5 Metrics
There's no description for a commit with changes to 65 files.
2021-01-27 20:49:27 -05:00

99 lines
1.8 KiB
JavaScript

beestat.enable_poll = function() {
window.clearTimeout(beestat.poll_timeout);
if (beestat.poll_intervals.length > 0) {
beestat.poll_timeout = window.setTimeout(
beestat.poll,
Math.min.apply(null, beestat.poll_intervals)
);
}
};
/**
* Poll the database for changes and update the cache.
*/
beestat.poll = function() {
var api = new beestat.api();
api.add_call(
'thermostat',
'sync',
{},
'thermostat_sync'
);
api.add_call(
'sensor',
'sync',
{},
'sensor_sync'
);
api.add_call(
'user',
'read_id',
{},
'user'
);
api.add_call(
'thermostat',
'read_id',
{
'attributes': {
'inactive': 0
}
},
'thermostat'
);
api.add_call(
'sensor',
'read_id',
{
'attributes': {
'inactive': 0
}
},
'sensor'
);
api.add_call(
'ecobee_thermostat',
'read_id',
{
'attributes': {
'inactive': 0
}
},
'ecobee_thermostat'
);
api.add_call(
'ecobee_sensor',
'read_id',
{
'attributes': {
'inactive': 0
}
},
'ecobee_sensor'
);
api.set_callback(function(response) {
beestat.cache.set('user', response.user);
beestat.cache.set('thermostat', response.thermostat);
beestat.cache.set('sensor', response.sensor);
beestat.cache.set('ecobee_thermostat', response.ecobee_thermostat);
beestat.cache.set('ecobee_sensor', response.ecobee_sensor);
beestat.enable_poll();
beestat.ecobee.notify_if_down();
});
api.send();
};
// Five minutes
beestat.default_poll_interval = 300000;
beestat.poll_intervals = [beestat.default_poll_interval];