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

UnboundLocalError: cannot access local variable 'event_recd' where it is not associated with a value in post_event #338

Open ehendrix23 opened 1 month ago

ehendrix23 commented 1 month ago

Seeing the following errors within Home Assistant log file:

2024-05-15 10:22:15.367 ERROR (SyncWorker_57) [custom_components.icloud3] cannot access local variable 'event_recd' where it is not associated with a value Traceback (most recent call last): File "/config/custom_components/icloud3/support/event_log.py", line 368, in post_event or event_recd[ELR_TEXT].startswith(EVLOG_ALERT)): ^^^^^^^^^^ UnboundLocalError: cannot access local variable 'event_recd' where it is not associated with a value

I'm on version 3.0.4 with HASS 2024.5.3.

This is in code:

` if len(event_text) > MAX_EVLOG_RECD_LENGTH: self._break_up_event_text(devicename, this_update_time, event_text, MAX_EVLOG_RECD_LENGTH) else: event_recd = [devicename, this_update_time, event_text]

            self._add_recd_to_event_recds(event_recd)

        if (self.startup_event_save_recd_flag
                or event_recd[ELR_TEXT].startswith(EVLOG_ALERT)):
            self._save_startup_log_recd(Device, event_recd)

`

I'm wondering if the following piece should be under that else as well as event_recd only seems to be set there within this function. if (self.startup_event_save_recd_flag or event_recd[ELR_TEXT].startswith(EVLOG_ALERT)): self._save_startup_log_recd(Device, event_recd)

Or by having _break_up_event_text return event_recd allowing it then to be set as well.

ehendrix23 commented 1 month ago

Note, I made the small change to the code in my instance by having _break_up_event_text return event_recd and that seems to work, at least no error. :-)

ehendrix23 commented 1 month ago

Created pull request #339 with potential fix