briancmpbll / home_assistant_custom_envoy

177 stars 77 forks source link

Possible Performance Improvement: Make call to home.json optional #113

Closed dh99999 closed 1 year ago

dh99999 commented 1 year ago

Calls to home.json appear to take a disproportionately large amount of time to complete as opposed to the other calls - on my system the actual time varies from around 2 seconds to 5 seconds - it is in the example below it is 4 seconds, eith most other calls less than a second:

2023-07-17 18:03:39.248 DEBUG (MainThread) [custom_components.enphase_envoy.envoy_reader] Token expires at: 2024-07-16 16:58:19
2023-07-17 18:03:39.248 DEBUG (MainThread) [custom_components.enphase_envoy.envoy_reader] HTTP GET Attempt #1: https://10.1.1.5/production.json?details=1: Header:{'Authorization': 'Bearer .......... 2023-07-17 18:03:40.083 DEBUG (MainThread) [custom_components.enphase_envoy.envoy_reader] Fetched from https://10.1.1.5/production.json?details=1: <Response [200 OK]>: {"production":[{"type":"inverters", ..... 2023-07-17 18:03:40.086 DEBUG (MainThread) [custom_components.enphase_envoy.envoy_reader] HTTP GET Attempt #1: https://10.1.1.5/ivp/ensemble/inventory: Header:{'Authorization': ...... 2023-07-17 18:03:40.322 DEBUG (MainThread) [custom_components.enphase_envoy.envoy_reader] Fetched from https://10.1.1.5/ivp/ensemble/inventory: <Response [200 OK]>: []
2023-07-17 18:03:40.324 DEBUG (MainThread) [custom_components.enphase_envoy.envoy_reader] HTTP GET Attempt #1: https://10.1.1.5/home.json: Header:{'Authorization': ........... 2023-07-17 18:03:44.276 DEBUG (MainThread) [custom_components.enphase_envoy.envoy_reader] Fetched from https://10.1.1.5/home.json: <Response [200 OK]>: {"software_build_epoch":1687430621,........... 2023-07-17 18:03:44.280 DEBUG (MainThread) [custom_components.enphase_envoy.envoy_reader] HTTP GET Attempt #1: https://10.1.1.5/api/v1/production/inverters: Header:{'Authorization': .............. 2023-07-17 18:03:44.622 DEBUG (MainThread) [custom_components.enphase_envoy.envoy_reader] Fetched from https://10.1.1.5/api/v1/production/inverters: <Response [200 OK]>: [

In addition to this it appears that "grid_status" is the only sensor which uses the call, and for me at least, grid_status is always "Unavailable".

I am not sure why it is always Unavailable, but from other reading it may be related to installer accounts or batteries.

Either way, would it be possible to optimise the calling pattern to home.json to only call it if needed?

ie: If the previous call did not return "Unavailable"

posixx commented 1 year ago

Very good idea. I have merged this into main. You can test by switching the intergration to use main branch instead of latest release.

Let us know if it works!

dh99999 commented 1 year ago

Looks good to me - data fetch takes just over a second now. Much much better! Thanks!

ps: I think the "ensemble" call can also be made optional - does not return anything in my system,

posixx commented 1 year ago

That one contains battery information (if available) and takes 200ms to retrieve.. Let's keep the code as simple as possible. I'm closing this now, thanks for confirming!