vlebourl / custom_vesync

Custom VeSync component for Home Assistant
97 stars 66 forks source link

Excessive API calls #112

Closed crafty35a closed 1 year ago

crafty35a commented 1 year ago

The problem

I recently set up Pi-hole within my network, and have noticed what seems to be an excessive number of queries to the Vesync API. Vesync queries dwarf all other queries: image

Vesync calls are about 85% of all DNS calls coming from Home Assistant: image

What version of this integration has the issue?

0.2.6

What version of Home Assistant Core has the issue?

2023.3.4

Diagnostics

Diagnostics ```json { "home_assistant": { "installation_type": "Unsupported Third Party Container", "version": "2023.3.4", "dev": false, "hassio": false, "virtualenv": false, "python_version": "3.10.10", "docker": true, "arch": "x86_64", "timezone": "America/New_York", "os_name": "Linux", "os_version": "5.19.17-Unraid", "run_as_root": false }, "custom_components": { "frigidaire": { "version": "0.1.0", "requirements": [ "frigidaire==0.18.4" ] }, "nest_protect": { "version": "0.4.0", "requirements": [] }, "simpleicons": { "version": "v2.2.0", "requirements": [ "simpleicons==7.14.0" ] }, "dual_smart_thermostat": { "version": "0.5.5", "requirements": [] }, "vesync": { "version": "0.2.5", "requirements": [ "pyvesync==2.1.1" ] }, "scheduler": { "version": "v0.0.0", "requirements": [] }, "smartthinq_sensors": { "version": "0.31.4", "requirements": [ "pycountry>=20.7.3", "xmltodict>=0.12.0", "cchardet>=2.1.7" ] }, "average": { "version": "2.3.0", "requirements": [] }, "hacs": { "version": "1.31.0", "requirements": [ "aiogithubapi>=22.10.1" ] }, "thermal_comfort": { "version": "2.1.1", "requirements": [] }, "cync_lights": { "version": "1.0.1", "requirements": [] }, "var": { "version": "0.15.0", "requirements": [] }, "roborock": { "version": "0.1.2", "requirements": [ "python-roborock==0.1.7" ] }, "asusrouter": { "version": "0.21.1", "requirements": [ "asusrouter==0.20.3" ] } }, "integration_manifest": { "domain": "vesync", "name": "VeSync", "documentation": "https://www.home-assistant.io/integrations/vesync", "codeowners": [ "@markperdue", "@webdjoe", "@thegardenmonkey", "@vlebourl" ], "requirements": [ "pyvesync==2.1.1" ], "config_flow": true, "iot_class": "cloud_polling", "version": "0.2.5", "issue_tracker": "https://github.com/vlebourl/custom_vesync", "dhcp": [ { "hostname": "levoit-*", "macaddress": "*" } ], "is_built_in": false }, "data": { "humidifier": [ { "device_name": "Humidifier", "device_image": "https://image.vesync.com/defaultImages/Classic_300S_Series/icon_300s_humidifier_160.png", "cid": "**REDACTED**", "connection_status": "online", "connection_type": "WiFi+BTOnboarding+BTNotify", "device_type": "Classic300S", "type": "wifi-air", "uuid": "**REDACTED**", "config_module": "WiFiBTOnboardingNotify_AirHumidifier_Classic300S_US", "mac_id": "**REDACTED**", "mode": null, "speed": null, "extension": null, "current_firm_version": null, "sub_device_no": null, "config": { "auto_target_humidity": 45, "display": true, "automatic_stop": true }, "device_status": "off", "enabled": false, "config_dict": { "module": "VeSyncHumid200300S", "models": [ "Classic300S", "LUH-A601S-WUSB" ], "features": [ "nightlight" ], "mist_modes": [ "auto", "sleep", "manual" ], "mist_levels": [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ] }, "mist_levels": [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ], "mist_modes": [ "auto", "sleep", "manual" ], "features": [ "nightlight" ], "warm_mist_feature": false, "warm_mist_levels": [], "night_light": true, "details": { "humidity": 40, "mist_virtual_level": 9, "mist_level": 3, "mode": "manual", "water_lacks": false, "humidity_high": false, "water_tank_lifted": false, "display": false, "automatic_stop_reach_target": true, "night_light_brightness": 0 }, "_api_modes": [ "getHumidifierStatus", "setAutomaticStop", "setSwitch", "setNightLightBrightness", "setVirtualLevel", "setTargetHumidity", "setHumidityMode", "setDisplay", "setLevel" ] } ] } } ```

Home Assistant log

Logs ```py Copy/paste any log here, between the starting and ending backticks. ```

Additional information

No response

github-actions[bot] commented 1 year ago

'There hasn't been any activity on this issue recently. Is this issue still present? Please make sure to update to the latest Home Assistant version and version of this integration to see if that solves the issue. Let us know if that works for you by adding a comment 👍. This issue now has been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.'

crafty35a commented 1 year ago

'There hasn't been any activity on this issue recently. Is this issue still present?

Still present. I should also note that this traffic is with just a single Levoit humidifier using the integration.

vlebourl commented 1 year ago

Just started looking into this, it appears each single entity makes a separate call to the VeSyncBaseEntity.update() method every minute. This can quickly be overwhelming... I'm pretty confident every entity belonging to the same device calls the same endpoint with the same body. This means that adding an update coordinator would significantly reduce api calls. That's quite a big update so that will take some time...

vlebourl commented 1 year ago

2023-03-26 09:28:11 INFO (SyncWorker_2) [homeassistant.loader] Loaded switch_as_x from homeassistant.components.switch_as_x
2023-03-26 09:28:39 WARNING (SyncWorker_4) [custom_components.vesync.common] Updating sensor.humidificateur_current_humidity
2023-03-26 09:28:39 WARNING (SyncWorker_3) [custom_components.vesync.common] Updating number.humidificateur_mist_level
2023-03-26 09:28:39 WARNING (SyncWorker_1) [custom_components.vesync.common] Updating binary_sensor.humidificateur_out_of_water
2023-03-26 09:28:40 WARNING (SyncWorker_2) [custom_components.vesync.common] Updating number.humidificateur_target_level
2023-03-26 09:28:40 WARNING (SyncWorker_0) [custom_components.vesync.common] Updating binary_sensor.humidificateur_water_tank_lifted
2023-03-26 09:28:40 WARNING (SyncWorker_3) [custom_components.vesync.common] Updating switch.humidificateur_auto_mode
2023-03-26 09:28:41 WARNING (SyncWorker_1) [custom_components.vesync.common] Updating switch.humidificateur_automatic_stop
2023-03-26 09:28:41 WARNING (SyncWorker_5) [custom_components.vesync.common] Updating switch.humidificateur_display
vlebourl commented 1 year ago

for reference: https://developers.home-assistant.io/docs/integration_fetching_data/#coordinated-single-api-poll-for-data-for-all-entities

1920x1200 commented 1 year ago

I also have a Levoit humidifier and noticed the exact same issue as op with the excessive API calls on my network. I'm looking forward to any improvement that can be made with this. Thank you!

github-actions[bot] commented 1 year ago

'There hasn't been any activity on this issue recently. Is this issue still present? Please make sure to update to the latest Home Assistant version and version of this integration to see if that solves the issue. Let us know if that works for you by adding a comment 👍. This issue now has been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.'

1920x1200 commented 1 year ago

There has been no change, issue still present.

vlebourl commented 1 year ago

Sorry, I had no time to look into this... I'll try to make some soon.

github-actions[bot] commented 1 year ago

'There hasn't been any activity on this issue recently. Is this issue still present? Please make sure to update to the latest Home Assistant version and version of this integration to see if that solves the issue. Let us know if that works for you by adding a comment 👍. This issue now has been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.'

1920x1200 commented 1 year ago

There has been no change, issue still present.

vlebourl commented 1 year ago

Could you try the fix branch? I've done some testing and it seems to work, but I'd me happier with more testing

crafty35a commented 1 year ago

Could you try the fix branch? I've done some testing and it seems to work, but I'd me happier with more testing

Sure, but I'm not sure how to switch branches of an integration in HACS. Can that be done, or do I need to switch to a manual installation?

crafty35a commented 1 year ago

I installed it manually, and everything is working - I will keep an eye on the DNS queries!

vlebourl commented 1 year ago

I'll publish it as a beta release.

github-actions[bot] commented 1 year ago

'There hasn't been any activity on this issue recently. Is this issue still present? Please make sure to update to the latest Home Assistant version and version of this integration to see if that solves the issue. Let us know if that works for you by adding a comment 👍. This issue now has been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.'

1920x1200 commented 1 year ago

I've put my humidifier away for the season, so unable to test. Has anyone been able to test the beta?

vlebourl commented 1 year ago

few people have I think... But so far no issue related to that. I'll wait another week and release this version as stable. I'll fix the issues later when they arise. I'll mark this closed for now, feel free to reopen if need be.