Skip to content

Commit

Permalink
fix: reset seconds on readings
Browse files Browse the repository at this point in the history
Avoid time sync issue when the script is running too fast.
EnergyId doesn't allow to add recordings in the future
  • Loading branch information
Th3S4mur41 committed Mar 17, 2023
1 parent 38d0e9e commit da20426
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ const getData = async () => {
const setReadings = (data) => {
const readings = [];
const readingDate = new Date();
// readingDate.setHours(0, 0, 0, 0);
readingDate.setSeconds(0, 0);

typeMap.forEach((type) => {
readings.push(new Reading(type, readingDate.toISOString(), data[type[0]]));
Expand All @@ -91,15 +91,15 @@ const setReadings = (data) => {
const sendReadings = (readings) => {
console.log("Sending readings to EnergyId Webhook...");
readings.forEach((reading) => {
console.log(`Sending reading: ${reading.json()}`);
fetch(energyid_hook, {
method: "post",
method: "POST",
headers: {
Accept: "application/json",
"Content-Type": "application/json",
},
body: reading.json(),
}).then((response) => {
console.log(`Sending reading: ${reading.json()}`);
console.log(response.statusText);
});
});
Expand Down

0 comments on commit da20426

Please sign in to comment.