jbergler / hass-ttlock

Home Assistant integration for TTLock locks
69 stars 13 forks source link

Attribute Error: NoneType #59

Open amm5172 opened 1 year ago

amm5172 commented 1 year ago

Receiving the following error on all of my locks (approximately 160 locks). Integration is set up and I can see that it is successfully collecting data but I have no devices listed in the integration. I have the following error multiple times in my log. Different users, different actions, different locks. Always the same error. AttributeError: 'NoneType' object has no attribute 'battery_level'

Logger: homeassistant.util.logging
Source: util/logging.py:168
First occurred: 3:07:44 PM (7 occurrences)
Last logged: 3:09:35 PM

Exception in _process_webhook_data when dispatching 'ttlock.data_received': (WebhookEvent(id=1847880, mac='C9:4B:4C:F1:B5:E1', battery_level=100, server_ts=datetime.datetime(2023, 7, 3, 15, 7, 44, 197000, tzinfo=zoneinfo.ZoneInfo(key='America/Chicago')), lock_ts=datetime.datetime(2023, 7, 3, 15, 7, 30, tzinfo=zoneinfo.ZoneInfo(key='America/Chicago')), event=Event(EventDescription(action=<Action.unlock: 3>, description='unlock by IC card')), user='hm', success=True),) Traceback (most recent call last): File "/config/custom_components/ttlock/coordinator.py", line 164, in _process_webhook_data new_data.battery_level = event.battery_level ^^^^^^^^^^^^^^^^^^^^^^ AttributeError: 'NoneType' object has no attribute 'battery_level'

config_entry-ttlock-ee6731597785b54275112671a8614839.json (3).txt

jbergler commented 1 year ago

@amm5172 thanks for the report, I poked around a little bit but think I'm going to need more data to debug this one. Could you please turn debug logging on and reload the extension, then send me the logs when the problem has re-occurred?

amm5172 commented 1 year ago

home-assistant_ttlock_2023-07-14T22-27-27.252Z.zip

amm5172 commented 1 year ago

ttlock log.txt

jbergler commented 1 year ago

Thanks for the logs, it looks like setting up the locks takes so long that webhooks are received before the locks are ready. I pushed a quick fix that skips processing the webhook in that case.

If you'd be so kind as to upgrade, and generate another debug log - I'd love to try and see if there's more that can be done with startup/setup performance.

amm5172 commented 1 year ago

home-assistant_ttlock_2023-07-17T17-23-36.010Z.log Failed again although it got much further this time

amm5172 commented 1 year ago

home-assistant_ttlock_2023-07-17T17-33-26.241Z.log