This simple plugin loads a device with data from the Canadian Covid Tracker API.
Attributes:
date total_cases total_fatalities total_tests total_hospitalizations total_criticals total_recoveries total_vaccinations total_vaccines_distributed total_vaccinated people_1_dose percent_doses_admin percent_pop_1_dose
Code:
plugin.Name = “covidtracker”;
plugin.OnChangeRequest = onChangeRequest;
plugin.OnConnect = onConnect;
plugin.OnDisconnect = onDisconnect;
plugin.OnPoll = onPoll;
plugin.OnSynchronizeDevices = onSynchronizeDevices;
plugin.PollingInterval = 600000;
plugin.DefaultSettings = {};var http = new HTTPClient();
function onChangeRequest(device, attribute, value) { }
function onConnect() { console.log(“connected covid”); }
function onDisconnect() { console.log(“disconnected covid”); }function onPoll() {
console.log(“polling covid”);
var response = http.get(“https://api.covid19tracker.ca/summary”);
var json = response.data.data[0];
var last_updated = response.data.last_updated;
//console.log(JSON.stringify(json));
//console.log(last_updated);
var mainDevice = plugin.Devices[“100”];
mainDevice.date = last_updated;
mainDevice.people_1_dose = json.total_vaccinations - json.total_vaccinated;
mainDevice.percent_doses_admin = (100 * json.total_vaccinations / json.total_vaccines_distributed);
mainDevice.percent_doses_admin = mainDevice.percent_doses_admin.toFixed(2)+’%’;
mainDevice.percent_pop_1_dose = (100 * mainDevice.people_1_dose / 38000000);
mainDevice.percent_pop_1_dose = mainDevice.percent_pop_1_dose.toFixed(2)+’%’;
for (var i in json) mainDevice[i] = json[i].replace(/\B(?=(\d{3})+(?!\d))/g, ‘,’);
}function onSynchronizeDevices() {}