Hi everyone,
I'm using the sure-pet contrib to access the API from Surepetcare company.
I came to this place a while ago because this contrib is not in work anymore and was crashing my nodered when handling an error, so again thank you to this forum it was working amazing since then.
Since yesterday I cannot communicate anymore with the API, all I have in logs are
Error: Get state failed: unauthenticated
The API seems to be working fine, I am using it with Jeedom (less possibilites than node-red, there is my problem) and there is no problem here. I checked the password and login, the API stopped working randomly, no reboot, no crash. It seems that something changes from their side and the actual code is not the right way to access it anymore.
So my code is changed from the github, here it is :
module.exports = function (RED) {
"use strict"
const SurePet = require('sure-pet-care-client');
function SurePetNode(config) {
RED.nodes.createNode(this, config);
const node = this;
node.surepet = RED.nodes.getNode(config.surepet);
node.on('input', function (msg) {
// special case, if `topic` === connect, then re-authenticate
if (msg.topic === "connect") {
node.surepet.client = new SurePet.SurePetCareClient();
node.surepet.client.authenticate(msg.username || msg.payload?.username, msg.password || msg.paylo>
.then(() => node.status({ fill: "green", shape: "dot", text: "Connected." }))
.catch(err => {
node.error(err, msg)
node.status({ fill: "red", shape: "ring", text: err })
})
return
}
// normal operation
if (config.mode === 'list_pets') {
node.surepet.client.getPets().then((pets) => {
msg.payload = {
pets: pets
}
node.send(msg)
}).catch((err) => {
node.error(err, msg);
})
} else if (config.mode === "get_status") {
node.surepet.client.getState().then((state) => {
msg.payload = state;
node.send(msg);
}).catch((err) => {
node.error(err, msg);
})
}
});
}
RED.nodes.registerType("surepet", SurePetNode);
function SurePetCredentials(n) {
RED.nodes.createNode(this, n);
const node = this
node.username = n.username || node.credentials.username;
node.password = n.password || node.credentials.password;
node.client = new SurePet.SurePetCareClient();
if (node.username && node.password) {
node.log("Présence d'identifiants, authentification en cours.")
node.client.authenticate(node.username, node.password)
.then(() => node.status({ fill: "green", shape: "dot", text: "Connected." }))
.catch(err => {
node.status({ fill: "red", shape: "ring", text: err })
node.error(err)
})
}
}
RED.nodes.registerType("surepet-credentials", SurePetCredentials, {
credentials: {
username: { type: "text" },
password: { type: "password" }
}
});
}
Does someone have an idea of if there is a chance I can make it work again ?
If this could be helpful, the Jeedom plugin that seems to work is this one : GitHub - jmvedrine/jeedom-surepetcare: Jeedom plugin for Sure Petcare connected products for pets
Thanks for your time