jheling / freeathome

Free@Home component for Home Assistant
103 stars 37 forks source link

Connection with SysAP lost #142

Closed lbeumann closed 1 year ago

lbeumann commented 1 year ago

Hey,

I'm facing an issue when connection my SysAP Version 1 (3.0.0 / 3.1.0) to home assistant. I can create a new integration but I directly get to follwoing error messages. Any idea what it might be? If I enter a wrong IP or a wrong User I get a meaningful error message. So I would assume the the SysAP is generally found.

2022-10-07 11:17:02.955 WARNING (MainThread) [custom_components.freeathome.fah.pfreeathome] Connection with SysAP lost 2022-10-07 11:17:27.692 ERROR (MainThread) [homeassistant.config_entries] Error setting up entry 192.168.2.103 for freeathome File "/config/custom_components/freeathome/init.py", line 77, in async_setup_entry File "/config/custom_components/freeathome/fah/pfreeathome.py", line 891, in find_devices File "/config/custom_components/freeathome/fah/pfreeathome.py", line 628, in find_devices

Thanks a lot

jheling commented 1 year ago

Hello, the component downloads a big xml file with all the setting from the sysap. After that it tries to parse the xml file. This is the line 628 in the error message. It seems that the xml is corrupt and crashes the parser. Can you try if the dumping, described in the debugging session, still works? Then we can take a look at the xml file

lbeumann commented 1 year ago

Thanks a lot for the response. I would really love to share the XML file but the service freeathome.dump is not available. Even if I enter it in the box and click on call service I get an error message that the service is not available. Any idea if I can get the file in a different way?

lbeumann commented 1 year ago

Hey,

I finally found the reason for this issue. I have a secure@home integration with free@home and it could happen that the attribute "imaginary" appears twice which causes an error in the xml. It seems to be the same topic as for the name attribute. To fix this I just added the same logic like for the name attribute to the code. On top I need to ignore the device of the secure@home central as this causes another error.

After ignoring it, everything is working fine. Would it be possible to add at least the first topic regarding the invalid xml to the main code and maybe add a feature which allows to igenore specific devices based on thier id?

Thanks again for the hint with the XML

DaveMyska commented 1 year ago

Hey, I'm having a similar problem after updating my SysAP to version 3.1. I'm getting an error:

Error setting up entry 192.168.1.2 for freeathome Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/config_entries.py", line 339, in async_setup result = await component.async_setup_entry(hass, self) File "/config/custom_components/freeathome/init.py", line 77, in async_setup_entry await sysap.find_devices() File "/config/custom_components/freeathome/fah/pfreeathome.py", line 891, in find_devices await self.xmpp.find_devices(self._use_room_names) File "/config/custom_components/freeathome/fah/pfreeathome.py", line 748, in find_devices room_suffix = ' (' + roomnames[floor_id][room_id] + ')' TypeError: can only concatenate str (not "NoneType") to str

Any advice on what I'm doing wrong?

Many thanks

jheling commented 1 year ago

@lbeumann what is the exact line you used for the attribute 'imaginary' as i can't reproduce the error?

@DaveMyska. With the option use_room_names the component combines the room name defined in FAH with the device name. But in this case one of the room names seems to be empty or not existing. Can you try to modify line 747 to this? : if floor_id != '' and room_id != '' and self.use_room_names and roomnames[floor_id][room_id] is not None:

lbeumann commented 1 year ago

@jheling: I've added the following everywhere (3 times) where you did the same for the "name" attribute. config_without_imaginary = re.sub(r'imaginary="[^"]" ([^>])imaginary="[^"]*"', r'\1', config_without_names)

And I change to use config_without_imaginary in the follwoing steps. If it would be helpful for you I can share my XML for debugging.

jheling commented 1 year ago

@lbeumann . I have just created a new pull request. Can you try it in your environment? After that i will merge the PR.

lbeumann commented 1 year ago

@jheling: It is not fully working as you missed in line 557 two times the *. Currently it is:

xml_without_imaginary = re.sub(r'imaginary="[^"]" ([^>])imaginary="[^"]*"', r'\1', xml_without_names)

and it needs to be: xml_without_imaginary = re.sub(r'imaginary="[^"]*" ([^>]*)imaginary="[^"]*"', r'\1', xml_without_names)

If you change that it works fine for me.

jheling commented 1 year ago

@lbeumann Thanks, i have added the two *.

@DaveMyska . Does the suggested change work for you?

lbeumann commented 1 year ago

Working fine. Thanks