Skip to content

Conversation

@Jan-nl
Copy link
Contributor

@Jan-nl Jan-nl commented Nov 5, 2025

Made the expire time of the refresh token of the Tado API dynamic, based on the expire time returned when a token is refreshed. Max loops is abs(expire time / poll interval) - 1, to be safe.

Remark: the first expire time is 599 seconds, the first refresh token returns 600 secs

@gizmocuz
Copy link
Contributor

gizmocuz commented Nov 6, 2025

Is one second not to risky? Maybe make it 30 seconds?
I don't see anywhere where you use a time_t to measure the actual time... Please remove the loop count thing and just store the time when you got the token, and then it is just a matter of subtracting it

if (acttime-token_get_time >= token_refresh_time) ...

@Jan-nl
Copy link
Contributor Author

Jan-nl commented Nov 6, 2025

It is not one second, the 599/600 is something Tado delivers. The actual time is at least the poll intervall.

Could be an issue if the poll intervall is set to 1 or so, but in that case the request limit is reached way too soon.

In case the poll intervall is greater compared to expire time, there also is a problem, but in that case the loops is set to one.

I know, not fool proof.

@gizmocuz
Copy link
Contributor

Sorry that is not what I meant. You receive 600 from Tado. Instead of checking the time and see if 600 seconds have elapsed, be a bit more safe, like 590 seconds (minus 10 seconds)

@Jan-nl
Copy link
Contributor Author

Jan-nl commented Nov 10, 2025

I made use of the loopcheck already present in the code.

The time should be at least the pollinterval.

Or do you mean substract 10secs from the expire time Tado sends and compute the nr of loops based on that and the pollinterval?

Jan

@gizmocuz
Copy link
Contributor

Yes, and I suggest to not use the loop for time checking,

while (!IsStopRequested(1000))
{

time_t atime=time(nullptr)
if (atime >= m_token_expire_time) {
RefreshToken();
}

bool RefreshToken()
{

  • get token
  • get token timeout
  • m_token_expire_time = time(nullptr) + (result of get token timeout) - 10

tado.h
private:
time_t m_token_expire_time = 0

@gizmocuz
Copy link
Contributor

@Jan-nl , is it possible to implement the above feature request?

@Jan-nl
Copy link
Contributor Author

Jan-nl commented Nov 24, 2025

Yes, sure. But it will take some time. Due to my c++ knowledge and the actual time I have.

If you can cancel the pr for now that is fine.

@gizmocuz
Copy link
Contributor

No that's fine, take your time!

@gizmocuz gizmocuz force-pushed the development branch 2 times, most recently from a0a55cd to e57a1b6 Compare December 2, 2025 11:09
@gizmocuz
Copy link
Contributor

Is the "expries_in" in Seconds?

Could you make the m_iTokenExpiresIn a time_t type in the header

and when it is in seconds you could do

m_iTokenExpiresIn = time(nullptr) + std::stoi(root["expires_in"].asString());

Is it a string or a number? Maybe you could directly to integer?

m_iTokenExpiresIn = time(nullptr) + root["expires_in"].asInt();

Delete the 'Set_TokenRefresh' function, this is not needed

m_iTADO_TOKEN_MAXLOOPS can also be deleted

In Do_Work above this line

	if (!(iSecCounter % m_iPollInterval == 0))
			continue;

do something like

if (time(nullptr)>=m_iTokenExpiresIn ) {
//refresh the token (m_iTokenExpiresIn should get a new value in the feature, in case of an error, you can also set this to actualtime+30 seconds, to retry in 30 seconds in that function of course)
}

Maybe clean up some code, and move code from Do_Work in it's own function (Own poll function)

If no token, no need to poll

Hope that makes a bit sense?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants