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

Errors in _async_subscribe_for_data #347

Open
sambeetm opened this issue Jul 24, 2024 · 16 comments
Open

Errors in _async_subscribe_for_data #347

sambeetm opened this issue Jul 24, 2024 · 16 comments
Labels
bug Something isn't working

Comments

@sambeetm
Copy link

The problem

Getting these errors in the logfile..

AttributeError: 'list' object has no attribute 'object_key'
2024-07-24 12:16:33.179 ERROR (MainThread) [custom_components.nest_protect] Unknown exception. Please create an issue on GitHub with your logfile. Updates paused for 5 minutes.
Traceback (most recent call last):
File "/config/custom_components/nest_protect/init.py", line 208, in _async_subscribe_for_data
dict(b, **buckets.get(b.object_key, {})) for b in [data.updated_buckets]

What version of this integration (ha-nest-protect) has the issue?

v0.4.0b5

What version of Home Assistant Core has the issue?

2024.7.3

Device / Model

Topaz-2.7

Diagnostics information

No response

Home Assistant log

Logs
AttributeError: 'list' object has no attribute 'object_key'
2024-07-24 12:16:33.179 ERROR (MainThread) [custom_components.nest_protect] Unknown exception. Please create an issue on GitHub with your logfile. Updates paused for 5 minutes.
Traceback (most recent call last):
  File "/config/custom_components/nest_protect/__init__.py", line 208, in _async_subscribe_for_data
    dict(b, **buckets.get(b.object_key, {})) for b in [data.updated_buckets]

Additional information

No response

@sambeetm sambeetm added the bug Something isn't working label Jul 24, 2024
@jamesbont007
Copy link

+1

4 similar comments
@MikeBP13
Copy link

+1

@helmerzNL
Copy link

+1

@dirixmjm
Copy link

dirixmjm commented Aug 2, 2024

+1

@FeralSquid
Copy link

+1

@dirixmjm
Copy link

dirixmjm commented Aug 3, 2024

I'm not very familiar with python, but I believe the bug is the brackets around 'data.updated_buckets' here:

    objects = [
        dict(b, **buckets.get(b.object_key, {})) for b in [data.updated_buckets]
    ]

Traceback (most recent call last):
File "/home/homeassistant/.homeassistant/custom_components/nest_protect/init.py", line 208, in _async_subscribe_for_data
dict(b, **buckets.get(b.object_key, {})) for b in data.updated_buckets
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: 'Bucket' object is not iterable

@iMicknl
Copy link
Owner

iMicknl commented Aug 3, 2024

Thanks all! Known issue, no need to keep reporting +1 (everyone on the latest version faces this 😉).

At the moment I don't have time to work on this unfortunately, but hope to make some time in the coming weeks. In the mean-time, contributions are appreciated.

@iMicknl iMicknl changed the title Error in the Log file Errors in _async_subscribe_for_data Aug 3, 2024
@FeralSquid
Copy link

yea, I'm having a hard time googling around to help parse that line of code and how it might be fixed, but based on the previous version and the comment above, I suspect the non-one-liner way to write what the intent is there would be:

objects: list[Bucket] = []
for b in updated_buckets:
    new_data = buckets.get(b["object_key"], {})
    if (new_data != {}):
        objects.append(cast(Bucket, new_data)) # not sure if cast is necessary here?
    else:
        objects.append(b) # I believe the intent is to keep around the old data if it isn't in the new result?

does that look right?

@ScottESanDiego
Copy link

ScottESanDiego commented Sep 5, 2024

does that look right?

That looks right to my eyes at first blush (changing updated_buckets to data.updated_buckets of course). Have you had any luck with it working @FeralSquid ? (I don't see a PR, so assuming no time yet)

@therealmrfox
Copy link

Code above isn't quite right either:

Traceback (most recent call last):
  File "/config/custom_components/nest_protect/__init__.py", line 223, in _async_subscribe_for_data
    new_data = buckets.get(b["object_key"], {})
                           ~^^^^^^^^^^^^^^
TypeError: 'Bucket' object is not subscriptable

@ScottESanDiego
Copy link

Here's what seems to be working for me... I'm not sure why it works, but no errors and so far somewhat timely occupancy detection (which is what I'm trying to get):

        # Update buckets with new data, to only receive new updates
        buckets = {d["object_key"]: d for d in result["objects"]}

        LOGGER.debug(buckets)

        objects: list[Bucket] = []
        for b in data.updated_buckets:
            objects.append(b) # I believe the intent is to keep around the old data if it isn't in the new result?

        data.updated_buckets = objects

I'm not 100% convinced this is the right solution (or substantially any different than the original code!).

ScottESanDiego added a commit to ScottESanDiego/ha-nest-protect that referenced this issue Sep 9, 2024
@ScottESanDiego
Copy link

Submitted a PR for this #355 (on the beta branch, although I think the same would apply to main)

@therealmrfox
Copy link

therealmrfox commented Sep 10, 2024

EDIT: Err, never mind. I somehow ended up with 2 integration entries - 1 working happily, and 1 with outdated credentials spamming the logs. Errors went away after deleting the old entry and rebooting.


With the patch above, I now get a different error:

Traceback (most recent call last):
  File "/config/custom_components/nest_protect/__init__.py", line 164, in _async_subscribe_for_data
    auth = await entry_data.client.get_access_token()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/nest_protect/pynest/client.py", line 91, in get_access_token
    await self.get_access_token_from_cookies(self.issue_token, self.cookies)
  File "/config/custom_components/nest_protect/pynest/client.py", line 158, in get_access_token_from_cookies
    raise BadCredentialsException(
custom_components.nest_protect.pynest.exceptions.BadCredentialsException: USER_LOGGED_OUT - No active session found.

Refreshing my issue_token and cookies didn't fix that.

The funny thing is that the integration still works ok - Presence detection happens within a few seconds (with a 10-minute timeout before going back to clear, but I think that's expected?)

Maybe that _async_subscribe_for_data business isn't needed at all?

@thargy
Copy link

thargy commented Sep 29, 2024

@iMicknl in #358 you closed as duplicate saying,

It might be fixed in the main branch of this integration, but I haven't been able to test this myself yet.

However, the main branch has had no commits since January, and the beta hasn't had any commits since August. Where did you mean for us to look?

Perhaps #355?

I have applied the change in 4a12184 manually for now, and can confirm that, so far, the log spam has disappeared.

@iMicknl
Copy link
Owner

iMicknl commented Sep 29, 2024

@thargy sorry, you are correct. It is indeed #355, I thought we already had this in the latest beta branch.

I will merge it now and do a new release.

@ScottESanDiego
Copy link

@iMicknl Ideas on how to fix this the right way? I didn't notice the communication side-effect with my kludge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

10 participants