Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for correcting status/online in tesla_custom v3.12.2 #621

Closed
BogdanDIA opened this issue May 31, 2023 · 4 comments
Closed

Fix for correcting status/online in tesla_custom v3.12.2 #621

BogdanDIA opened this issue May 31, 2023 · 4 comments

Comments

@BogdanDIA
Copy link

BogdanDIA commented May 31, 2023

Version of the custom_component

v3.12.2

Configuration

  • using default

Describe the bug

In v3.12.2 the status of the car is not correctly reflected. E.g. the asleep state is not shown unless the force update or wake_up buttons are clicked.

I was debugging the teslajsonpy and I realized that the API call for "vehicles" is not triggered. Going into details the following function in controller.update() is not called because the update_vehicles variable is False:

async with self.__update_lock:
            if self._vehicle_list:
                cur_time = round(time.time())
                #  Update the online cars using get_vehicles()
                last_update = self._last_attempted_update_time
                _LOGGER.debug(
                    "Get vehicles. Force: %s Time: %s Interval %s update_vehicles: %s",
                    force,
                    cur_time - last_update,
                    ONLINE_INTERVAL,
                    update_vehicles,
                )
                if force or cur_time - last_update >= ONLINE_INTERVAL and update_vehicles:
                    cars = await self.get_vehicles()
                    for car in cars:
                        _LOGGER.debug(
                            "Get vehicles loop. State: %s",
                            car["state"]
                        )
                        self.set_id_vin(car_id=car["id"], vin=car["vin"])
                        self.set_vehicle_id_vin(
                            vehicle_id=car["vehicle_id"], vin=car["vin"]
                        )
                        self.set_car_online(
                            vin=car["vin"], online_status=car["state"] == "online"
                        )
                        self.cars[car["vin"]].update_car_info(car)
                    self._last_attempted_update_time = cur_time

The tesla_custom integration seems to call the update() function with update_vehicles=False.

Quick fix for me was to use the following modification in tesla_custom/__init__.py:

reload_lock = asyncio.Lock()
    _partial_coordinator = partial(
        TeslaDataUpdateCoordinator,
        hass,
        config_entry=config_entry,
        controller=controller,
        reload_lock=reload_lock,
        energy_site_ids=set(),
        vins=set(),
        update_vehicles=True, <--- was previously False
    )

Hope this helps.
Bogdan

@jherby2k
Copy link

i haven't tested your fix (will do so now) but this has been broken since 3.10.4.

@BogdanDIA
Copy link
Author

i haven't tested your fix (will do so now) but this has been broken since 3.10.4.

I just started with v3.12.2 but reading few reported bugs for this integration I got the idea that it stopped working after 3.10.4. Forgot to mention that HA needs to be restarted after the change.

@BogdanDIA
Copy link
Author

BogdanDIA commented Jun 1, 2023

I just tested the v3.12.3 and updating the vehicle status works for now. Thanks @alandtse

@BogdanDIA
Copy link
Author

Just to give feedback one day after installing v2.13.3, although it seems to not harm, I see in logs the same call for update() twice at every 10s, once with update_vehicles=True and second with update_vehicles=False

2023-06-02 07:17:15.099 DEBUG (MainThread) [teslajsonpy.controller] Get vehicles. Force: False Time: 30 Interval 60 update_vehicles: True
2023-06-02 07:17:15.099 DEBUG (MainThread) [custom_components.tesla_custom] Finished fetching tesla_custom data in 0.001 seconds (success: True)
2023-06-02 07:17:15.411 DEBUG (MainThread) [custom_components.tesla_custom] Running controller.update()
2023-06-02 07:17:15.411 DEBUG (MainThread) [teslajsonpy.controller] Get vehicles. Force: False Time: 30 Interval 60 update_vehicles: False
2023-06-02 07:17:15.412 DEBUG (MainThread) [teslajsonpy.controller] 15367: asleep. Polling policy: normal. Update state: normal. Since last park: 10. Since last wake up: 34773. Idle interval: 600. shift_state: None sentry: False climate: False, charging: Complete

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants