marvinroger / hass-addon-tiko

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

null value in column "retain_mobile_session" of relation "smarties_home_user" violates not-null constraint #10

Closed sebj54 closed 8 months ago

sebj54 commented 8 months ago

Hi there!

I constantly have this error when I'm starting the Tiko extension:

[11:17:43] INFO: Running in Home Assistant mode
[11:17:43] INFO: MQTT_BROKER_URL not set, using MQTT addon service...
[11:17:45.145] ERROR (7): Unable to fetch initial data from tiko API
    err: {
      "type": "Error",
      "message": "Unable to get a token from Tiko; are the credentials correct?: The tiko API returned an error: {\"errors\":[{\"message\":\"null value in column \\\"retain_mobile_session\\\" of relation \\\"smarties_home_user\\\" violates not-null constraint\\nDETAIL:  Failing row contains (2469, xxx@example.com, 220034769, 18577, null, 2133).\\n\"}]}",
      "stack":
          Error: Unable to get a token from Tiko; are the credentials correct?
              at TikoClient.getToken (file:///app/dist/tiko/client.js:35:24)
              at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
              at async TikoClient.fetchData (file:///app/dist/tiko/client.js:45:29)
              at async file:///app/dist/index.js:16:27
          caused by: Error: The tiko API returned an error: {"errors":[{"message":"null value in column \"retain_mobile_session\" of relation \"smarties_home_user\" violates not-null constraint\nDETAIL:  Failing row contains (2469, xxx@example.com, 220034769, 18577, null, 2133).\n"}]}
              at doTikoRequest (file:///app/dist/tiko/client.js:161:24)
              at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
              at async TikoClient.getToken (file:///app/dist/tiko/client.js:26:28)
              at async TikoClient.fetchData (file:///app/dist/tiko/client.js:45:29)
              at async file:///app/dist/index.js:16:27
    }

(I anonymized my email from the logs)

I already had this problem on previous version, but the new error log is now showing the real problem. Thanks for the new version :)

I'm not against making a PR to fix this issue but I'm not sure how to run / debug the code outside of HA. If anyone has any tips on this, it would be great!

marvinroger commented 8 months ago

Hi there!

Hm, weird you're the only user having this issue! Are you using tiko or Mon Pilotage Elec?

Also, can you connect successfully using the application?

sebj54 commented 8 months ago

Thanks for the quick reply!

I'm using Tiko and can successfully connect in the app. I'm using a password manager to retrieve the password so I'm 100% sure that credentials are correct.

I share the account with my girlfriend on her phone, maybe it is related? I would bet that I'm not the only one to share an account though.

If it can be useful, feel free to ask for technical details. I am a web developer so I am familiar with Docker and Node. Maybe I can run the container locally to add some logs or something.

marvinroger commented 8 months ago

Awesome if you're a dev!

Could you please try to execute the following GraphQL query against https://particuliers-tiko.fr/api/v3/graphql/:

mutation LogIn($email: String!, $password: String!) {
    logIn(input: { email: $email, password: $password }) {
        user {
            properties {
                id
                name
            }
        }
        token
    }
}

And confirm that you have the same error?

Then, can you try with:

mutation LogIn($email: String!, $password: String!, $retainSession: Boolean) {
    logIn(
        input: { email: $email, password: $password, retainSession: $retainSession }
    ) {
        user {
            properties {
                id
                name
            }
        }
        token
    }
}

And report if it works?

sebj54 commented 8 months ago

I think you found it! The first query fails as expected and the second one works!

Here is the response I got (anonymized):

{
    "data": {
        "logIn": {
            "user": {
                "properties": [
                    {
                        "id": 123,
                        "name": "Home xxx #1"
                    }
                ]
            },
            "token": "xxx"
        }
    }
}
marvinroger commented 8 months ago

Super ! Est-ce que tu peux tester la 1.4.4 ?

sebj54 commented 8 months ago

Ça fonctionne désormais 🥳

[14:18:52.169] INFO (6): Connection ready

Merci pour le correctif et surtout pour l'add-on lui-même 🙏

marvinroger commented 8 months ago

Merci à toi pour les tests 😉