gcobb321 / icloud3

iCloud3 v3 - iCloud3 is an advanced iDevice tracker that uses Apple iCloud account and HA Companion App data for presence detection and location based automations.
MIT License
545 stars 54 forks source link

Thread is calling async methods directly #315

Closed balloob closed 2 months ago

balloob commented 6 months ago

The main loop _polling_loop_5_sec_device is not decorated as callback, so it is executed in a thread every 5 seconds. When it detects an update, it can call write_ha_sensor_state (still within the context of the thread). This method then calls self.async_write_ha_state().

A sync method is not allowed to call any async method. They can be recognized by the async_ prefix. Some of them need to be awaited, others are not.

In this case, you should call self.schedule_update_ha_state().

26tajeen commented 6 months ago

@balloob could this be causing Home Assistant to restart?

gcobb321 commented 6 months ago

Thank you for your advice. This change has been included in the version of iCloud3 v3.0.1 that will be posted to the iCloud3 Development GitHub repository this week and the general release GitHub repository a short time later.

gcobb321 commented 6 months ago

@26tajeen I have updated iCloud3. Here is a preliminary copy of v3.0.1. Let me know if it does not solve your issue.

Unzip it to the icloud3 directory and restart HA. icloud3_v3.0.1.zip

26tajeen commented 6 months ago

Hi, I had hoped it would fix my issue but I got another freeze this morning as I arrived home. Thanks for being 'on it' :-)

gcobb321 commented 2 months ago

Completed in v3.0.1/v3.0.2