Authentication error on surepet contrib

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

Personally, i would start with raising an issue on the repository: Issues · jpwsutton/node-red-contrib-surepet · GitHub. Perhaps the owner does not know this is an issue?

But, that said, the real culpret is probably the underlying library sure-pet-care-client - this has no issues raised either. Maybe consider reporting the probem so the author is aware?

If you want to proceed yourself, then I would suggest forking the node, then switching from sure-pet-care-client (updated 3y ago) to node-surepetcare (updated 10m ago) then publishing a PR (Pull Request) back to the original node.

If the author of node-red-contrib-surepet accepts - job done. If not, you can always install your branch direct from GitHub or release a new version to NPM e.g. @YourName/node-red-contrib-surepet

I raised an issue back to my last problem months ago but it seems that the author is not active anymore.

I see what you mean, but I'm not capable of doing it myself so I will raise some tickets on the different subjects in hope that someone is still active on it.

Thank you

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.