JoDehli / PyLoxone

Python Loxone binding
Apache License 2.0
164 stars 40 forks source link

TypeError: string indices must be integers #158

Closed bitcrumb closed 1 year ago

bitcrumb commented 1 year ago

Which Model do you use from loxone? Miniserver? Gen1 or Gen2?

Miniserver Gen1

Which software version does your loxone use?

How did you install HomeAssistant? Over Hassio oder manual install?

HassOS

Which Version do you use of HomeAssistant?

2023.1.4

Describe the bug

Errors happen after setting up the integration. Credentials are correct. Tried with local IP & duckdns.org as hostname.

Second error log seems to indicate that the API returns a string, where the code assumes an object (e.g. value['key']).

Not sure why "Config entry has already been setup" appears, since this error is shown after setting up the integration for the first time (and consecutive edits of the config as well).

❗️Note that the integration does seem to create devices & entities. But they are not functional.

Error log 1:

Logger: homeassistant.config_entries
Source: helpers/entity_component.py:166
First occurred: 19:54:41 (8 occurrences)
Last logged: 19:54:41

Error setting up entry PyLoxone for cover
Error setting up entry PyLoxone for fan
Error setting up entry PyLoxone for light
Error setting up entry PyLoxone for climate
Error setting up entry PyLoxone for alarm_control_panel
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 382, in async_setup
    result = await component.async_setup_entry(hass, self)
  File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 573, in async_setup_entry
    return await component.async_setup_entry(entry)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 166, in async_setup_entry
    raise ValueError("Config entry has already been setup!")
ValueError: Config entry has already been setup!

Error log2:

Logger: homeassistant.config_entries
Source: custom_components/loxone/api.py:1022
Integration: PyLoxone ([documentation](https://github.com/JoDehli/PyLoxone), [issues](https://github.com/JoDehli/PyLoxone/issues))
First occurred: 19:54:42 (1 occurrences)
Last logged: 19:54:42

Error setting up entry PyLoxone for loxone
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 382, in async_setup
    result = await component.async_setup_entry(hass, self)
  File "/config/custom_components/loxone/__init__.py", line 361, in async_setup_entry
    res = await miniserver.start_ws()
  File "/config/custom_components/loxone/miniserver.py", line 126, in start_ws
    res = await self.api.async_init()
  File "/config/custom_components/loxone/api.py", line 452, in async_init
    res = await self.acquire_token()
  File "/config/custom_components/loxone/api.py", line 708, in acquire_token
    key_and_salt.read_user_salt_responce(message)
  File "/config/custom_components/loxone/api.py", line 1022, in read_user_salt_responce
    self.key = value["key"]
TypeError: string indices must be integers
JoDehli commented 1 year ago

Have you tried restarting home assistant?

bitcrumb commented 1 year ago

After rebooting this error still remains:

Logger: homeassistant.config_entries
Source: custom_components/loxone/api.py:1022
Integration: PyLoxone ([documentation](https://github.com/JoDehli/PyLoxone), [issues](https://github.com/JoDehli/PyLoxone/issues))
First occurred: 21:33:00 (2 occurrences)
Last logged: 21:34:23

Error setting up entry PyLoxone for loxone
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 382, in async_setup
    result = await component.async_setup_entry(hass, self)
  File "/config/custom_components/loxone/__init__.py", line 361, in async_setup_entry
    res = await miniserver.start_ws()
  File "/config/custom_components/loxone/miniserver.py", line 126, in start_ws
    res = await self.api.async_init()
  File "/config/custom_components/loxone/api.py", line 452, in async_init
    res = await self.acquire_token()
  File "/config/custom_components/loxone/api.py", line 708, in acquire_token
    key_and_salt.read_user_salt_responce(message)
  File "/config/custom_components/loxone/api.py", line 1022, in read_user_salt_responce
    self.key = value["key"]
TypeError: string indices must be integers

Also note that certainly not all devices are reported by the integration (even though I mentioned that devices & entities are being imported). A lot of switches are missing for instance.

JoDehli commented 1 year ago

Have you tried to remove the pyloxone and install and setup again?

bitcrumb commented 1 year ago

Yes, multiple times. The error keeps returning. Which seems logical, since it is an error while parsing the API response. And I set it up using the same config each time.

As I said:

bitcrumb commented 1 year ago

I see that somebody else reported the same error in the past, but its unclear to me from the discussion if there was a solution?

See: https://github.com/JoDehli/PyLoxone/issues/54

JoDehli commented 1 year ago

Strange I use the same code on my miniserver.

Can you try to delete the toke file in the main config folder. It is the folder where your configuration yaml is normally. I do not exactly know how it is called it something with token in the naming.

It this does not work you can try (if you familiar with git) you can download the new branch I have created a view weeks ago and override the sources it the pyloxone install folder. Do you know what I mean?

This is the newest implementation which is completely different in the way how it is communicating with the Miniserver

JoDehli commented 1 year ago

I can not remember. Sorry. What port do you use. Please use not 80.

bitcrumb commented 1 year ago

I can not remember. Sorry. What port do you use. Please use not 80.

I see... I did indeed configure with port 80.

This has to be the port of the web interface right or is this some other port?

bitcrumb commented 1 year ago

Strange I use the same code on my miniserver.

Can you try to delete the toke file in the main config folder. It is the folder where your configuration yaml is normally. I do not exactly know how it is called it something with token in the naming.

It this does not work you can try (if you familiar with git) you can download the new branch I have created a view weeks ago and override the sources it the pyloxone install folder. Do you know what I mean?

This is the newest implementation which is completely different in the way how it is communicating with the Miniserver

I'll see what I can do, it's actually not my own setup, but the one from my brother. So I don't have unlimited access.

What I can also do: run my local Home Assistant development setup (I'm working on an integration myself) & debug from there by copying the custom_components/loxone folder over. This way I might even be able to provide you with example API response.

I'll keep you posted.

JoDehli commented 1 year ago

Of course this would be great. It is always very difficult to help if I do not have access to the system.

The port is used also from the app. The integration uses the same API which the app uses. And by default it is 80. The actual integration was written for my system years ago and has some major limitations which I want to eliminate with the newest implementation. But is is not ready to release by now. So I would try the new branch when you debug it.

bitcrumb commented 1 year ago

Thanks for the info, I'll see what I can do. I might find some time this evening.

Appreciate you replying this fast 🙏🏻

bitcrumb commented 1 year ago

Had a quick look at what API call is executed. And it seems fairly simple?

The URL requested is: http://xxx/jdev/cfg/apiKey with xxx being the hostname/ip.

Tried this out in my brower & this was the response:

{
  "LL": {
    "control": "dev/cfg/apiKey",
    "value": "{'snr': 'XX:XX:XX:XX:XX:XX', 'version':'8.3.3.21', 'key':'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'}",
    "Code": "200"
  }
}

Seems to me that the issue here is that value doesn't contain a proper JSON object, but rather a string containing JSON? So you could make this fail-safe by parsing it first if you detect that value is a string?

Ot is this something that already happens? Didn't look through the code yet (or the new version of this integration), but wanted to let you know already :)

jevanhove commented 1 year ago

Strange I use the same code on my miniserver.

Can you try to delete the toke file in the main config folder. It is the folder where your configuration yaml is normally. I do not exactly know how it is called it something with token in the naming.

It this does not work you can try (if you familiar with git) you can download the new branch I have created a view weeks ago and override the sources it the pyloxone install folder. Do you know what I mean?

This is the newest implementation which is completely different in the way how it is communicating with the Miniserver

Hi there!

this is the brother -_-

Didn't find the token file you were talking about. Tried deleting and installing again, same problem. Only 7 devices and 7 entities...

JoDehli commented 1 year ago

@jevanhove you can try the new beta release. You can install it from HACS.

I close the issue and if you still have a problem you can reopen it.