robinostlund / homeassistant-volkswagencarnet

Volkswagen Carnet Component for home assistant
GNU General Public License v3.0
306 stars 59 forks source link

[BUG] Sensors update interval is not respected #478

Closed arthur1472 closed 1 year ago

arthur1472 commented 1 year ago

Environment

Describe the bug

I've changed the "Sensors update interval (minutes)", in the code "CONF_SCAN_INTERVAL" or in the config "scan_interval", to 1 instead of 5. However the updates still appear to happen every 5 minutes.

Steps to Reproduce

Setup the integration. Click on it again and set the "Sensors update interval (minutes)" to 1.

Expected behaviour

The expected behaviour is that the HomeAssistant integration updates the sensor data every minute instead of every 5 minutes, which is the default.

Screenshots

Screenshot_20230512-145439 image Some values have been removed as they contain the VIN or other personal information.

image The above screenshot contains the debug log for the update_interval, which should be 1 in my case.

Traceback/Error logs

None

Debug information - all JSON responses from logfile

2023-05-12 14:25:52.170 DEBUG (MainThread) [custom_components.volkswagencarnet] Async update finished for VIN (volkswagencarnet). Next update in 0:05:00.
2023-05-12 14:29:11.601 DEBUG (MainThread) [custom_components.volkswagencarnet] Async update finished for VIN (volkswagencarnet). Next update in 0:05:00.
2023-05-12 14:34:11.618 DEBUG (MainThread) [custom_components.volkswagencarnet] Async update finished for VIN (volkswagencarnet). Next update in 0:05:00.
2023-05-12 14:39:11.561 DEBUG (MainThread) [custom_components.volkswagencarnet] Async update finished for VIN (volkswagencarnet). Next update in 0:05:00.
2023-05-12 14:44:11.547 DEBUG (MainThread) [custom_components.volkswagencarnet] Async update finished for VIN (volkswagencarnet). Next update in 0:05:00.
2023-05-12 14:49:11.550 DEBUG (MainThread) [custom_components.volkswagencarnet] Async update finished for VIN (volkswagencarnet). Next update in 0:05:00.
2023-05-12 14:54:11.541 DEBUG (MainThread) [custom_components.volkswagencarnet] Async update finished for VIN (volkswagencarnet). Next update in 0:05:00.
2023-05-12 14:59:11.531 DEBUG (MainThread) [custom_components.volkswagencarnet] Async update finished for VIN (volkswagencarnet). Next update in 0:05:00.

Below is a clean log of HomeAssistant after I first restarted the supervisor and HomeAssistant afterwards.

2023-05-12 15:03:30.882 DEBUG (MainThread) [custom_components.volkswagencarnet] Async update finished for VIN (volkswagencarnet). Next update in 0:05:00.

Additional context

I've enabled the debug logging of HomeAssistant and enabled "Enable full debug logs from API". Restarted HomeAssistant multiple times to see if that helps / clears any cached values (if there are any), unfortunately that didn't help.

arthur1472 commented 1 year ago

While looking at the code I found the issue. In the file "custom_components/volkswagencarnet/init.py", rule 116, it makes use of the entry.options.get for the "CONF_SCAN_INTERVAL". image

However, as can be seen in the 2nd screenshot of the issue, it saves the "scan_interval" config variable in data. Not in the options.

In the file "/custom_components/volkswagencarnet/config_flow.py" it has the data_schema, rule 259, which includes the "CONF_SCAN_INTERVAL". image

After adding the "scan_interval": 1 line to my options through the .storage/config_entries, it started working.

2023-05-12 15:10:47.654 DEBUG (MainThread) [custom_components.volkswagencarnet] Async update finished for VIN (volkswagencarnet). Next update in 0:01:00.
2023-05-12 15:11:47.400 DEBUG (MainThread) [custom_components.volkswagencarnet] Async update finished for VIN (volkswagencarnet). Next update in 0:01:00.
2023-05-12 15:12:47.451 DEBUG (MainThread) [custom_components.volkswagencarnet] Async update finished for VIN (volkswagencarnet). Next update in 0:01:00.
2023-05-12 15:13:47.412 DEBUG (MainThread) [custom_components.volkswagencarnet] Async update finished for VIN (volkswagencarnet). Next update in 0:01:00.
2023-05-12 15:14:47.435 DEBUG (MainThread) [custom_components.volkswagencarnet] Async update finished for VIN (volkswagencarnet). Next update in 0:01:00.

Something similar might be happening to region as well.

If I have some time left over I will make a PR to fix this mistake.

arthur1472 commented 1 year ago

Has been fixed with release v4.4.62