GithubHelp home page GithubHelp logo

Comments (10)

DarwinsBuddy avatar DarwinsBuddy commented on July 22, 2024

I am not aware of any secure caching functionality right now in HomeAssistant. Although I guess the Wiener Netze API offers to renew a particular token by using the refresh token along side the access token, we cannot really persist them in HA I fear.

from wienernetzesmartmeter.

reox avatar reox commented on July 22, 2024

Okay, but also username and password is stored? Can we not just use the same approach?

from wienernetzesmartmeter.

DarwinsBuddy avatar DarwinsBuddy commented on July 22, 2024

from wienernetzesmartmeter.

reox avatar reox commented on July 22, 2024

Maybe it is a good idea to switch to a proper OpenID-Connect library, which can handle all these things.

I also checked the token response, they are valid for 300 seconds, and the refresh token for 1800s (30min).
Thus, with the change to request only every 60minutes, we would have to login any ways or have another job running in the background that does the refreshing.

I guess the website sets a cookie with a longer lifespan?

from wienernetzesmartmeter.

DarwinsBuddy avatar DarwinsBuddy commented on July 22, 2024

regarding OpenID: that would be for sure the more stable solution, though we are assuming that log.wien correctly implemented it according to the standard.
We may have to reverse engineer that part, but imho it's worth a try.

regarding the token: Home assistant does not provide afaik the possibility to launch separate scheduled tasks then the update lifecycle. What we could do is reduce the update cycle to happen < 30min and first use refresh token and if that fails as a fallback the credentials login and update the sensors merely every 2nd-3rd time.
If the refresh token endpoint is computationally more efficient (as it should not require a persistence lookup) we could save them some load and give back some performance.

What do you think @reox?

from wienernetzesmartmeter.

reox avatar reox commented on July 22, 2024

regarding OpenID: that would be for sure the more stable solution, though we are assuming that log.wien correctly implemented it according to the standard.

The question is also if we are acting according to any standard :D

What we could do is reduce the update cycle to happen < 30min and first use refresh token and if that fails as a fallback the credentials login and update the sensors merely every 2nd-3rd time.

Or even reduce it to 5min and just update the API every half an hour. I implemented something similar with the statistics, to only query after 24h after the last imported stat, eve if the update function is called more often.

from wienernetzesmartmeter.

DarwinsBuddy avatar DarwinsBuddy commented on July 22, 2024

regarding OpenID: that would be for sure the more stable solution, though we are assuming that log.wien correctly implemented it according to the standard.

The question is also if we are acting according to any standard :D

For sure not. But as of my experience openId is often not implemented according to the standard. Just to keep that in mind, when integrating into an external system.

What we could do is reduce the update cycle to happen < 30min and first use refresh token and if that fails as a fallback the credentials login and update the sensors merely every 2nd-3rd time.

Or even reduce it to 5min and just update the API every half an hour. I implemented something similar with the statistics, to only query after 24h after the last imported stat, eve if the update function is called more often.
calling every 5 minutes is a bit too much. Most frequently 15 minutes is I guess already enough.
Regarding your grace timeout logic: I agree, we could probably think of update if next day after updatets at 00:00 < now

from wienernetzesmartmeter.

reox avatar reox commented on July 22, 2024

I had a look on what is taking so long during login. It is actually the fetching of the API keys from the javascript files.
The file that has to be downloaded is 1.8MB (okay, it is gziped to 400kB..)
Maybe a good addition would be to cache these keys. For starters, one could take the proposed cache value from the http response.

from wienernetzesmartmeter.

DarwinsBuddy avatar DarwinsBuddy commented on July 22, 2024

there you have a point.
You've got a good idea there:

We could download and cache the keys (by downloading the html-file -> js-files -> api keys) if

  • the cached key is None or
  • the login with the cached key fails due to a wrong key, as a fallback

and use the cached one as long as it doesn't fail to login due to invalid keys
What do you think @reox ?

from wienernetzesmartmeter.

reox avatar reox commented on July 22, 2024

I thought about that too. Probably would have to check in the _call_api function then if the call fails and if so, request new keys.

from wienernetzesmartmeter.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.