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
498 stars 52 forks source link

'NoneType' object has no attribute 'loop' #327

Closed SoCuul closed 1 month ago

SoCuul commented 2 months ago

Hi!

Recently I've noticed the following error being spammed in my logs.

2024-04-05 00:00:04.526 ERROR (SyncWorker_9) [custom_components.icloud3] 'NoneType' object has no attribute 'loop'
Traceback (most recent call last):
  File "/config/custom_components/icloud3/sensor.py", line 1259, in async_update_sensor
    self.schedule_update_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1213, in schedule_update_ha_state
    self.hass.loop.call_soon_threadsafe(self.async_write_ha_state)
    ^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'loop'
gcobb321 commented 2 months ago

Another person noticed that a few days ago. I can not reproduce it but it looks like a sensor was being updated when it didn't exist, when it had not been set up yet or when there was no data to use.

I added some code to see if the sensor had been set up before doing anything and also put another error check in to try to catch it. This was just changed at the request of balloob. See if it helps and let me know if you still see the error msg.

Unzip sensor.zip into the icloud3 directory and restart HA

sensor.zip

SoCuul commented 2 months ago

Hey, sorry for the late response!

I just got around to trying it, and it seems to fix the error. Thanks :)