FreshlyBrewedCode / pymee

a python library to interact with homee
MIT License
8 stars 4 forks source link

An error occurred: 'list' object is not an iterator #7

Closed Taraman17 closed 10 months ago

Taraman17 commented 1 year ago

After the last update, my HA logs show the following:

2023-06-26 13:01:20.559 ERROR (MainThread) [pymee] An error occurred: invalid state 2023-06-26 13:01:25.918 ERROR (MainThread) [pymee] An error occurred: 'list' object is not an iterator

The second line gets repeated then every 5 seconds for about 20 minutes Not sure yet where it comes from - I keep investigating.

Taraman17 commented 1 year ago

The debug log from pymee shows (I truncated the {'all': message, since it may contain personal information):

2023-06-26 16:58:04.909 ERROR (MainThread) [pymee] An error occurred: invalid state
2023-06-26 16:58:09.930 INFO (MainThread) [pymee] Opening websocket...
2023-06-26 16:58:09.957 INFO (MainThread) [pymee] Connection to websocket successfull
2023-06-26 16:58:09.960 DEBUG (MainThread) [pymee] PING!
2023-06-26 16:58:10.078 DEBUG (MainThread) [pymee] {'all': {'users': [{'id': 1, 'username': ...
2023-06-26 16:58:10.149 ERROR (MainThread) [pymee] An error occurred: 'list' object is not an iterator
2023-06-26 16:58:15.154 INFO (MainThread) [pymee] Opening websocket...
2023-06-26 16:58:15.189 INFO (MainThread) [pymee] Connection to websocket successfull
2023-06-26 16:58:15.191 DEBUG (MainThread) [pymee] PING!
2023-06-26 16:58:15.323 DEBUG (MainThread) [pymee] {'all': {'users': [{'id': 1, 'username': ...
2023-06-26 16:58:15.399 ERROR (MainThread) [pymee] An error occurred: 'list' object is not an iterator
2023-06-26 16:58:23.831 INFO (MainThread) [pymee] Opening websocket...
2023-06-26 16:58:24.236 INFO (MainThread) [pymee] Connection to websocket successfull
2023-06-26 16:58:24.245 DEBUG (MainThread) [pymee] PING!

In the received message the "options" collections look all correct and in other cases do not lead to this error. The "invalid state" error followed by a new connection to websockets makes me think it might be related to frequent disconnects from Homee I get in Homeassistant. unfortunately I'm not able to reprocduce this error in my devcontainer where I could debug.

A first idea to cope with this error is to change model.py to following:

import logging

_LOGGER = logging.getLogger(__name__)

class HomeeAttributeOptions:
    def __init__(self, attributeOptions):
        try:
            iterator = iter(attributeOptions)
        except TypeError:
            _LOGGER.warn("options are not Iterable: " + attributeOptions)
            raise TypeError("options are not Iterable.")
        else:
            self._data = attributeOptions
Taraman17 commented 1 year ago

After downgrading to pymee 1.7.1, the error still occurs - so it does not seem to be linked to the latest additions.

Taraman17 commented 1 year ago

I'm starting to get another error at the same time, the above happens:

2023-07-01 13:27:23.723 ERROR (MainThread) [homeassistant] Error doing job: Error on transport creation for incoming connection
Traceback (most recent call last):
File "/usr/local/lib/python3.11/asyncio/selector_events.py", line 222, in _accept_connection2
await waiter
File "/usr/local/lib/python3.11/asyncio/sslproto.py", line 575, in _on_handshake_complete
raise handshake_exc
ConnectionResetError
thargy commented 1 year ago

I have the same issue, in that my log viewer is getting spammed with ERROR (MainThread) [pymee] An error occurred: 'list' object is not an iterator

Taraman17 commented 10 months ago

I was able to narrow it down to the

_update_or_create_relationships(self, data: dict)

function.

With try/except and logging I got: 2023-11-03 22:37:56.451 WARNING (MainThread) [pymee] Could not iterate over relationships: [{'id': 1, 'group_id': 1, 'node_id': 3, 'homeegram_id': 0, 'order': 0}, {'id': 2, 'group_id': 1, 'node_id': 9, 'homeegram_id': 0, 'order': 0}] Most interestingly, the data which is logged IS iterable, so I don't know why it throws on the for/in call. Will have to investigate further.

With the upcoming update however, the exception will be caught and at least the connection stays intact. Not sure yet which side-effects it may have, that this update of the relationships is not done then.