marvinroger / hass-addon-tiko

Control your tiko / Mon Pilotage Elec heaters from Home Assistant
10 stars 1 forks source link

Properties at null triggering zod schema validation error #6

Closed JSteunou closed 6 months ago

JSteunou commented 7 months ago

Tiko seems to have some kind of rate limiting not only at login but at data query too.

Most people think to have a login issue because of the log message

ERROR (7): Failed to fetch data from Tiko; are the credentials correct?

but this is due to a data validation issue.

This happen because server is returning {data: {properties: null}} instead of a real http error response and because the log error could be improve.

JSteunou commented 7 months ago

Login gives more info about rate limiting see https://github.com/marvinroger/hass-addon-tiko/issues/5#issuecomment-1962387451

it seems to be 5/min and 20/hour max

Maybe polling every minutes by default is not a sane default.

sebj54 commented 7 months ago

Thanks for the new issue! I think it is not a credentials issue too. Like I said in https://github.com/marvinroger/hass-addon-tiko/issues/5#issuecomment-1962749500, I'm sure of my password because I get it from a password manager and login works in the Tiko app).

The container crashes a few seconds after I start it in my case.

Complete logs ``` [23:42:46] INFO: Running in Home Assistant mode [23:42:46] INFO: MQTT_BROKER_URL not set, using MQTT addon service... [23:42:47.659] ERROR (7): Failed to fetch data from Tiko; are the credentials correct? err: { "type": "ZodError", "message": "[\n {\n \"code\": \"invalid_type\",\n \"expected\": \"object\",\n \"received\": \"null\",\n \"path\": [\n \"data\",\n \"logIn\"\n ],\n \"message\": \"Expected object, received null\"\n }\n]", "stack": ZodError: [ { "code": "invalid_type", "expected": "object", "received": "null", "path": [ "data", "logIn" ], "message": "Expected object, received null" } ] at get error [as error] (file:///app/node_modules/zod/lib/index.mjs:538:31) at doTikoRequest (file:///app/dist/tiko/client.js:150:31) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async TikoClient.getToken (file:///app/dist/tiko/client.js:22:28) at async TikoClient.fetchData (file:///app/dist/tiko/client.js:37:29) at async file:///app/dist/index.js:16:27 "aggregateErrors": [ { "type": "Object", "message": "Expected object, received null", "stack": "code": "invalid_type", "expected": "object", "received": "null", "path": [ "data", "logIn" ] } ], "issues": [ { "code": "invalid_type", "expected": "object", "received": "null", "path": [ "data", "logIn" ], "message": "Expected object, received null" } ], "name": "ZodError" } ```
andreidobrica commented 7 months ago

Tiko seems to have some kind of rate limiting not only at login but at data query too.

Most people think to have a login issue because of the log message

ERROR (7): Failed to fetch data from Tiko; are the credentials correct?

but this is due to a data validation issue.

This happen because server is returning {data: {properties: null}} instead of a real http error response and because the log error could be improve.

I have just tried triggering the rate limiter and without success. I did over 50 requests, one after the another, in Postman. So as I see it, either:

  1. the integration also performs a login request with status request, which triggers the rate limiter
  2. the Tiko backend is not very robust ....

My coding skills are very rusted and not sure if variant 1 is true or not, as I read the code.

JSteunou commented 7 months ago

Ok updating issue title to not focus on rate limiting but only on the real issue. Rate limiting might not be the source of this issue.

Might be an unvalid token and / or session cookie.

ExeDesK commented 7 months ago

I also thought that it came from a usage limit but the fact that this problem reappears every night but never during the day makes me think more of a disconnection due to the lifespan of the authentication token... Perhaps the plugin should be modified so that it reconnects automatically in the event of an error or periodically (every 12 hours for example)

JSteunou commented 7 months ago

2 possible improvement @marvinroger

andreidobrica commented 7 months ago

Every morning I find the add-on in error due to null data received. So I set an automation to restart the addon every night. I will let you know if this is a good workaround

ExeDesK commented 7 months ago

Every morning I find the add-on in error due to null data received. So I set an automation to restart the addon every night. I will let you know if this is a good workaround

I did a similar thing, as soon as one of my radiators is unavailable, the plugin restarts

dlevequeIT commented 7 months ago

Yes, I have the same issue for me in France with Engie Mon Pilotage Elec. With a restart it working back again, but no longer that 12-15h

dlevequeIT commented 7 months ago

@andreidobrica It's a good idea but I did another automation only in failed case: Screenshot_2024-02-29-10-27-16-42_c3a231c25ed346e59462e84656a70e50

SeeeeebDe commented 7 months ago

Hi guys! I’m very interested in your investigations cause I’m blocked with this error since a long time now. But in my case it never starts.

My user and passwords are ok, checked it a million times.

But I’ve red something new here for me : possibility of a cookie !? How to clear it for sure?

Cause I’ve already try to remove and re install the add on without success… :(

noiwid commented 7 months ago

hi, on what domain / url are you able to login ? Tiko have several endpoints depending on countries and maybe brands, it might be the issue...

Le jeu. 29 févr. 2024, 18:17, SeeeeebDe @.***> a écrit :

Hi guys! I’m very interested in your investigations cause I’m blocked with this error since a long time now. But in my case it never starts.

My user and passwords are ok, checked it a million times.

But I’ve red something new here for me : possibility of a cookie !? How to clear it for sure?

Cause I’ve already try to remove and re install the add on without success… :(

— Reply to this email directly, view it on GitHub https://github.com/marvinroger/hass-addon-tiko/issues/6#issuecomment-1971602094, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFML5A3T434YNXTCYWTFM2DYV5RENAVCNFSM6AAAAABDZX7WMSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNZRGYYDEMBZGQ . You are receiving this because you are subscribed to this thread.Message ID: @.***>

sebj54 commented 7 months ago

Same problem here. I'm using the Tiko app and it's also the endpoint configured in HA. Can't login even with valid credentials (or it's a misleading error message)

SeeeeebDe commented 7 months ago

Hi!

The site on which I connect with no problem is https://particuliers-tiko.fr/

phid78 commented 7 months ago

Tu as la version 1.4 , dans config tu as selectionné Tiko et mis tes identifiants, et ca bloque ? Colle le journal d'erreur

SeeeeebDe commented 7 months ago

Oui msieur, tout comme ça 😌

Pour le journal : [19:00:41] INFO: Running in Home Assistant mode [19:00:45.269] ERROR (7): Failed to fetch data from Tiko; are the credentials correct? err: { "type": "ZodError", "message": "[\n {\n \"code\": \"invalid_type\",\n \"expected\": \"number\",\n \"received\": \"null\",\n \"path\": [\n \"data\",\n \"properties\",\n 0,\n \"rooms\",\n 5,\n \"currentTemperatureDegrees\"\n ],\n \"message\": \"Expected number, received null\"\n }\n]", "stack": ZodError: [ { "code": "invalid_type", "expected": "number", "received": "null", "path": [ "data", "properties", 0, "rooms", 5, "currentTemperatureDegrees" ], "message": "Expected number, received null" } ] at get error [as error] (file:///app/node_modules/zod/lib/index.mjs:538:31) at doTikoRequest (file:///app/dist/tiko/client.js:150:31) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async TikoClient.fetchData (file:///app/dist/tiko/client.js:49:32) at async file:///app/dist/index.js:16:27 "aggregateErrors": [ { "type": "Object", "message": "Expected number, received null", "stack":

      "code": "invalid_type",
      "expected": "number",
      "received": "null",
      "path": [
        "data",
        "properties",
        0,
        "rooms",
        5,
        "currentTemperatureDegrees"
      ]
    }
  ],
  "issues": [
    {
      "code": "invalid_type",
      "expected": "number",
      "received": "null",
      "path": [
        "data",
        "properties",
        0,
        "rooms",
        5,
        "currentTemperatureDegrees"
      ],
      "message": "Expected number, received null"
    }
  ],
  "name": "ZodError"
}
JSteunou commented 7 months ago

Évitez d'utiliser une issue comme un fil de discussion pour un problème différent que l'issue elle même svp :pray:

Ça dilue complètement le problème. Basculez sur le sujet du forum pour ça plutôt

phid78 commented 7 months ago

Parce que toi tu savais a l'avance le probleme qu'il avait ? Moi j'ai juste repris sa phrase : I’m blocked with this error since a long time now Merci pour tes commentaires constructifs, on te laisse regler son probleme.

SeeeeebDe commented 7 months ago

À vrai dire, je vous du « ZodError » et des  « null » un peu partout dans le log que je viens de poster. Donc j’ai simplement fait le rapprochement avec le titre du poste. Maintenant si tu me dis que ce n’est pas la même erreur et que tu m’orientes vers ailleurs j’y vais volontiers. Désolé pour la mauvaise adresse 😌

sebj54 commented 7 months ago

Même constat pour moi. Et je me rends compte à l'instant que le but de cette issue est justement de rendre compréhensible le message d'erreur, non pas de corriger le problème sous-jacent 😅

marvinroger commented 7 months ago

Bonjour à tous,

Je viens de publier la 1.4.1 qui devrait régler tous les problèmes. L'add-on rafraîchit maintenant le jeton toutes les 12 heures, les messages d'erreur ont été améliorés et le rate limiting du login est géré.

Je laisse l'issue ouverte, n'hésitez pas à me dire si tout est OK pour vous et je la fermerai dans quelques jours. 😉

Merci à tous pour votre implication et plus particulièrement à @JSteunou et à @ExeDesK pour vos idées, ça a bien aidé, merci !


[!IMPORTANT]
Petite parenthèse quand même, je trouve que tout le monde fait preuve de bonne volonté ici, notamment @JSteunou qui a tout à fait raison quand il dit cordialement d'éviter de diluer l'issue, même s'il est également complètement légitime de la part de @SeeeeebDe d'avoir fait le rapprochement avec cette issue qui y ressemble.

En l'occurence il est vrai que c'est un bug différent (le currentTemperatureDegrees est à null, j'ai encore jamais vu ça, peut-être que le thermomètre est indisponible temporairement), je t'invite à ouvrir une issue dédiée pour éviter que ce cas ne tombe aux oubliettes.

Il n'y a donc aucun tord, et je trouve que le "Merci pour tes commentaires constructifs, on te laisse regler son probleme" était de trop et instaure un climat inutile étant donnée la bienveillance de chacun. 😊

JSteunou commented 7 months ago

De rien ;) Je n'ai pas trop le temps de te faire de PR donc c'est la moindre des choses vu ce que tu donnes pour la communauté.

SeeeeebDe commented 7 months ago

Alors pour faire un retour sur la 1.4.1 : hélas ne règle pas le problème que je rencontre. Mais c’est donc un autre sujet.

À noter quand même que le message d’erreur a légèrement changé 😋

marvinroger commented 6 months ago

Le problème initialement rapporté est résolu, merci à tous pour vos contributions !