Apollon77 / daikin-controller-cloud

Connect and Control Daikin Cloud devices
MIT License
98 stars 25 forks source link

Porting of tokensaver to python #20

Closed rospogrigio closed 3 years ago

rospogrigio commented 3 years ago

Hi @Apollon77 , first of all thank you for your huuuuuge work. Since I saw that the tokensaver.js is working perfectly and allows to skip all the proxy procedure, I've been trying to port it to python in order to include it in my integration: in this way, when the tokenset expires it can be automatically renewed and we can live happily ever after (unless the Daikin guys decide to change things on their side, of course). I've reached 90% of the goal but I'm stuck at the very last step. I am attaching the code I've come up to (you'll see tons of commented lines of code, please understand): tokensaver.zip

You can launch it with "./tokensaver.py username password", and as you'll see from the output I can get login and obtain all the values you get in your process... until the last call where I'm supposed to get the tokenset. Here, I'm feeling quite lost because the oic library does not provide anything similar to the oauthCallback you are using in NodeJS... I believe I should use the do_access_token_request call (you can find a commented line) but it crashes because it finds the grant field of the client not set, and debugging I am seeing that it gets never set because in the parse_request_response the authentication call always gets a 302 status code (redirect), so it never reaches the parse_response method that is the only place where the grant field is finally set. Now, I know that you are not a python developer but if you can help me or give some suggestion on how I can overcome this problem it would be really great. Or even if you have some documentation to point to... even though I am understanding that the amazon OAuth process complicates things a bit. Looking forward to your reply, thank you in advance! rospogrigio

rospogrigio commented 3 years ago

Nevermind man, after A LOT of struggling I finally managed to get the tokenset!!! I'll be coming up with a brand new release of the integration! Thank you anyway!!!

Apollon77 commented 3 years ago

Have fun and good luck. :-) (I love issues that solve itself before I even see them ;-) )

rospogrigio commented 3 years ago

Eheh... I'm nearly there, it's all working in my venv development environment, I'm just struggling with moving to the real environment. Once I'll publish the integration, we should be able to forget all the re-login-once-per-month thing. And by the way... you are THE MAN!! This would not have been possible without you. Bye!

Apollon77 commented 3 years ago

Not me alone, was clearly a community effort ... I just condensed into code :-)

I hope that the "direct login method" will work for long because Daikin can break it anytime and then we need to adjust again and the usual "cat and mice" game starts ... lets see how it goes. Thats why I leave the proxy flow in here as fallback because they can not break that that easiely