jheling / freeathome

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

Integration stopped working with HA 2022.7.0 #130

Closed bezibaerchen closed 1 year ago

bezibaerchen commented 1 year ago

I read about changes in Python.

Status as of now: "Failed to set up: Import error

bezibaerchen commented 1 year ago

2022-07-07 12:06:39 ERROR (MainThread) [homeassistant.config_entries] Error occurred loading configuration flow for integration freeathome: Exception importing custom_components.freeathome.config_flow

Snipes999 commented 1 year ago

I do get the same error message, since I have installed 2022.7.

miguelcastilho commented 1 year ago

I also see this error in my logs

This error originated from a custom integration.

Logger: homeassistant.loader
Source: custom_components/freeathome/fah/pfreeathome.py:21
Integration: Busch Jaeger/ABB Free@Home (documentation)
First occurred: 13:22:19 (15 occurrences)
Last logged: 14:30:26

Unexpected exception importing platform custom_components.freeathome.config_flow
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/loader.py", line 618, in get_platform
    cache[full_name] = self._import_platform(platform_name)
  File "/usr/src/homeassistant/homeassistant/loader.py", line 635, in _import_platform
    return importlib.import_module(f"{self.pkg_path}.{platform_name}")
  File "/usr/local/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/config/custom_components/freeathome/config_flow.py", line 12, in <module>
    from .fah.pfreeathome import FreeAtHomeSysApp
  File "/config/custom_components/freeathome/fah/pfreeathome.py", line 21, in <module>
    from slixmpp.plugins.xep_0060.stanza.pubsub_event import Event, EventItems, EventItem
  File "/usr/local/lib/python3.10/site-packages/slixmpp/plugins/xep_0060/__init__.py", line 11, in <module>
    from slixmpp.plugins.xep_0060.pubsub import XEP_0060
  File "/usr/local/lib/python3.10/site-packages/slixmpp/plugins/xep_0060/pubsub.py", line 15, in <module>
    from slixmpp.plugins.xep_0060 import stanza
  File "/usr/local/lib/python3.10/site-packages/slixmpp/plugins/xep_0060/stanza/__init__.py", line 9, in <module>
    from slixmpp.plugins.xep_0060.stanza.pubsub import *
  File "/usr/local/lib/python3.10/site-packages/slixmpp/plugins/xep_0060/stanza/pubsub.py", line 11, in <module>
    from slixmpp.plugins import xep_0004
  File "/usr/local/lib/python3.10/site-packages/slixmpp/plugins/xep_0004/__init__.py", line 11, in <module>
    from slixmpp.plugins.xep_0004.stanza import Form
  File "/usr/local/lib/python3.10/site-packages/slixmpp/plugins/xep_0004/stanza/__init__.py", line 10, in <module>
    from slixmpp.plugins.xep_0004.stanza.form import Form
  File "/usr/local/lib/python3.10/site-packages/slixmpp/plugins/xep_0004/stanza/form.py", line 13, in <module>
    from slixmpp.thirdparty import OrderedSet
  File "/usr/local/lib/python3.10/site-packages/slixmpp/thirdparty/__init__.py", line 7, in <module>
    from slixmpp.thirdparty.orderedset import OrderedSet
  File "/usr/local/lib/python3.10/site-packages/slixmpp/thirdparty/orderedset.py", line 25, in <module>
    class OrderedSet(collections.MutableSet):
AttributeError: module 'collections' has no attribute 'MutableSet'
StevenBoelhouwer commented 1 year ago

Looks like the error is not in the freeathome part but in a required package. I wonder if updating the "requirements" to a later version (slixmpp==1.8.2) will fix the issue or raise a couple new ones.

jeroen84 commented 1 year ago

I have created a PR as a first try to fix this issue. Upgraded slixmpp and made a small code change. Please go to #131 to verify the change.

theuzzy commented 1 year ago

Sadly new errors:

This error originated from a custom integration.

Logger: homeassistant.loader
Source: custom_components/freeathome/fah/crypto.py:2
Integration: Busch Jaeger/ABB Free@Home (documentation)
First occurred: 8:21:33 PM (4 occurrences)
Last logged: 8:21:58 PM

Unexpected exception importing platform custom_components.freeathome.config_flow
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/loader.py", line 618, in get_platform
    cache[full_name] = self._import_platform(platform_name)
  File "/usr/src/homeassistant/homeassistant/loader.py", line 635, in _import_platform
    return importlib.import_module(f"{self.pkg_path}.{platform_name}")
  File "/usr/local/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/config/custom_components/freeathome/config_flow.py", line 12, in <module>
    from .fah.pfreeathome import FreeAtHomeSysApp
  File "/config/custom_components/freeathome/fah/pfreeathome.py", line 39, in <module>
    from .saslhandler import SaslHandler
  File "/config/custom_components/freeathome/fah/saslhandler.py", line 7, in <module>
    from .crypto import Crypto, loginSaslPayload, buildSaslResponse
  File "/config/custom_components/freeathome/fah/crypto.py", line 2, in <module>
    import libnacl
  File "/usr/local/lib/python3.10/site-packages/libnacl/__init__.py", line 85, in <module>
    nacl = _get_nacl()
  File "/usr/local/lib/python3.10/site-packages/libnacl/__init__.py", line 81, in _get_nacl
    raise OSError(msg)
OSError: Could not locate nacl lib, searched for libsodium.so, libsodium.so.23, libsodium.so.18, libsodium.so.17, libsodium.so.13, libsodium.so.10, libsodium.so.5, libsodium.so.4, 
AStenzel commented 1 year ago

Sadly new errors:

This error originated from a custom integration.

Logger: homeassistant.loader
Source: custom_components/freeathome/fah/crypto.py:2
Integration: Busch Jaeger/ABB Free@Home (documentation)
First occurred: 8:21:33 PM (4 occurrences)
Last logged: 8:21:58 PM

Unexpected exception importing platform custom_components.freeathome.config_flow
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/loader.py", line 618, in get_platform
    cache[full_name] = self._import_platform(platform_name)
  File "/usr/src/homeassistant/homeassistant/loader.py", line 635, in _import_platform
    return importlib.import_module(f"{self.pkg_path}.{platform_name}")
  File "/usr/local/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/config/custom_components/freeathome/config_flow.py", line 12, in <module>
    from .fah.pfreeathome import FreeAtHomeSysApp
  File "/config/custom_components/freeathome/fah/pfreeathome.py", line 39, in <module>
    from .saslhandler import SaslHandler
  File "/config/custom_components/freeathome/fah/saslhandler.py", line 7, in <module>
    from .crypto import Crypto, loginSaslPayload, buildSaslResponse
  File "/config/custom_components/freeathome/fah/crypto.py", line 2, in <module>
    import libnacl
  File "/usr/local/lib/python3.10/site-packages/libnacl/__init__.py", line 85, in <module>
    nacl = _get_nacl()
  File "/usr/local/lib/python3.10/site-packages/libnacl/__init__.py", line 81, in _get_nacl
    raise OSError(msg)
OSError: Could not locate nacl lib, searched for libsodium.so, libsodium.so.23, libsodium.so.18, libsodium.so.17, libsodium.so.13, libsodium.so.10, libsodium.so.5, libsodium.so.4, 

I also had this error. It seems as if the APK for "libsodium" was removed in the "Home Assistant Operation System".

If you apply the PullRequest #131 from @jeroen84 in the code and run the integration in the Docker image (latest), then everything is found correctly and free@home integration is working fine.

As a workaround, I can only recommend the following (for "Home Assistant Operation System"-Users):

theuzzy commented 1 year ago

Another error:

This error originated from a custom integration.

Logger: slixmpp.basexmpp
Source: custom_components/freeathome/fah/pfreeathome.py:308 
Integration: Busch Jaeger/ABB Free@Home (documentation) 
First occurred: 22:50:31 (1 occurrences) 
Last logged: 22:50:31

local variable 'node_jid' referenced before assignment
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/slixmpp/xmlstream/xmlstream.py", line 1094, in handler_callback_routine
    await cb(data)
  File "/config/custom_components/freeathome/fah/pfreeathome.py", line 308, in start
    self['xep_0030'].static.add_identity(self.boundjid.full, capsversion, '', identity)
  File "/usr/local/lib/python3.10/site-packages/slixmpp/plugins/xep_0030/static.py", line 318, in add_identity
    new_node = self.add_node(jid, node)
  File "/usr/local/lib/python3.10/site-packages/slixmpp/plugins/xep_0030/static.py", line 88, in add_node
    if (node_jid, node, node_ifrom) not in self.nodes:
UnboundLocalError: local variable 'node_jid' referenced before assignment
AStenzel commented 1 year ago

Another error:

This error originated from a custom integration.

Logger: slixmpp.basexmpp
Source: custom_components/freeathome/fah/pfreeathome.py:308 
Integration: Busch Jaeger/ABB Free@Home (documentation) 
First occurred: 22:50:31 (1 occurrences) 
Last logged: 22:50:31

local variable 'node_jid' referenced before assignment
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/slixmpp/xmlstream/xmlstream.py", line 1094, in handler_callback_routine
    await cb(data)
  File "/config/custom_components/freeathome/fah/pfreeathome.py", line 308, in start
    self['xep_0030'].static.add_identity(self.boundjid.full, capsversion, '', identity)
  File "/usr/local/lib/python3.10/site-packages/slixmpp/plugins/xep_0030/static.py", line 318, in add_identity
    new_node = self.add_node(jid, node)
  File "/usr/local/lib/python3.10/site-packages/slixmpp/plugins/xep_0030/static.py", line 88, in add_node
    if (node_jid, node, node_ifrom) not in self.nodes:
UnboundLocalError: local variable 'node_jid' referenced before assignment

Has the complete PR #131 also been applied? This error reads like the 2nd fixed error in the PR (file: custom_components/freeathome/fah/pfreeathome.py)!

rsegers commented 1 year ago

Applied PR #131 but that (alone) didn't work. Installing libsodium as mentioned above by AStenzel solved the issue. So now I have PR #131 and libsodium. Haven't tried it without the PR.

I'm running Home Assistant OS

theuzzy commented 1 year ago

Applied PR #131 but that (alone) didn't work. Installing libsodium as mentioned above by AStenzel solved the issue. So now I have PR #131 and libsodium. Haven't tried it without the PR.

Same here, its working again (Had to reboot the Busch Jaeger / Free@Home).

How do I git clone the fix because when I do a git clone I get the old files without the fix. :(

Anyway, thank you for the fix and help!

sstadlberger commented 1 year ago

If you just want to get it working quickly again you can do a rollback to HA version 2022.6.7 with

ha core update --version 2022.6.7

bartdorlandt commented 1 year ago

Or if using docker, set the tag to 2022.6

Apologies for the introduced errors by autocorrection on my mobile device.

On Sat, 9 Jul 2022, 11:58 Stefan Stadlberger @.***> wrote:

If you just want to get it working quickly again you can do a rollback to HA version 2022.6.7 with

ha core update --version 2022.6.7

— Reply to this email directly, view it on GitHub https://github.com/jheling/freeathome/issues/130#issuecomment-1179516090, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAHT3H75P3DIGGLM7SNKUITVTFEM3ANCNFSM5243YSTQ . You are receiving this because you are subscribed to this thread.Message ID: @.***>

AStenzel commented 1 year ago

As I'm lazy to repeat those steps each time after an update, I've create a simple script, that can be triggered via automation. So all I have to do after an update is to initiate a restart of the system (via UI).

For all other lazy people, here are my scripts and settings respectively:

Shell-Script (_/config/custom_components/freeathome/scripts/fahrequirements.sh):

#!/bin/bash
LIB_EXISTS=$(apk info | grep 'libsodium')
if [[ -z $LIB_EXISTS ]]; then
  apk add libsodium
fi

EDIT Ensure that you set the executable bits! chmod +x /config/custom_components/freeathome/scripts/fah_requirements.sh

Entry in global configuration.yaml:

shell_command:
  fah_requirements: '/config/custom_components/freeathome/scripts/fah_requirements.sh'

Entry in global automations.yaml:

- alias: fah_system_start
  trigger:
    platform: homeassistant
    event: start
  action:
    - service: shell_command.fah_requirements

Short explanation:

When Home Assistant is started/restarted, the automation 'fah_system_start' is triggered, this executes the shell command 'fah_requirements' which triggers our script. The script itself first checks whether the apk is already installed and only installs it if this is not the case.

bezibaerchen commented 1 year ago

I can also confirm applying the PR and apk adding libsodium brings FAH integration back to life and functionality

bezibaerchen commented 1 year ago

As I'm lazy to repeat those steps each time after an update, I've create a simple script, that can be triggered via automation. So all I have to do after an update is to initiate a restart of the system (via UI).

For all other lazy people, here are my scripts and settings respectively:

Shell-Script (_/config/custom_components/freeathome/scripts/fahrequirements.sh):

#!/bin/bash
LIB_EXISTS=$(apk info | grep 'libsodium')
if [[ -z $LIB_EXISTS ]]; then
  apk add libsodium
fi

Entry in global configuration.yaml:

shell_command:
  fah_requirements: '/config/custom_components/freeathome/scripts/fah_requirements.sh'

Entry in global automations.yaml:

- alias: fah_system_start
  trigger:
    platform: homeassistant
    event: start
  action:
    - service: shell_command.fah_requirements

Short explanation:

When Home Assistant is started/restarted, the automation 'fah_system_start' is triggered, this executes the shell command 'fah_requirements' which triggers our script. The script itself first checks whether the apk is already installed and only installs it if this is not the case.

Thanks for this. As I tend to be a lazy person as well I also added that. Cheers mate.

mrVoltrix commented 1 year ago

Hi Guys,

I don't know what i'm doing wrong but i can't get it working. I added the changes from PR #131 and I also integrated the script to adding libsodium again. I'm running Home Assistant OS.

jeroen84 commented 1 year ago

Looks like this change breaks the integration: https://github.com/home-assistant/docker/commit/e926373887e789b48945e14118de9134da1be195

This removed libsodium from the build of the Home Assistant base image. Home Assistant OS and Docker images are affected.

Not sure how to make a structural solution for this, other than adding libsodium as explained above.

mrVoltrix commented 1 year ago

Yes but when I try to do it like above, then I get this response back from the logbook:

Logger: homeassistant.components.shell_command Source: /usr/src/homeassistant/homeassistant/components/shell_command/init.py:115 Integration: Shell Command (documentation, issues) First occurred: 13:36:07 (1 occurrences) Last logged: 13:36:07

Error running command: /config/custom_components/freeathome/scripts/fah_requirements.sh, return code: 126 NoneType: None

jeroen84 commented 1 year ago

After a brief search a potential solution is switching to https://github.com/pyca/pynacl/ as a replacement for libnacl. This package is a standard dependency in Home Assistant https://github.com/home-assistant/core/blob/3429a75cc5d9be8560dfef5c2619d21273e2bffe/requirements_all.txt#L27

Tho85 commented 1 year ago

I also don't see an easy way to solve this. As @jeroen84 mentioned, the library was removed from the docker image, and since no other official component relies on it, chances are low that it will be re-added by the core team.

My workaround is to build a custom Docker image on my machine, however this may not be possible for everyone:

FROM homeassistant/home-assistant:2022.7.2
RUN apk add libsodium

The cleanest solution would be to replace libnacl with pynacl as outlined by @jeroen84, but this is not an easy switch. It would require to completely rewrite fah/crypto.py. Also, some methods would have to be added upstream to pynacl, i.e. the crypto_box_easy stuff added by @jheling in saltstack/libnacl#114

AStenzel commented 1 year ago

Yes but when I try to do it like above, then I get this response back from the logbook:

Logger: homeassistant.components.shell_command Source: /usr/src/homeassistant/homeassistant/components/shell_command/init.py:115 Integration: Shell Command (documentation, issues) First occurred: 13:36:07 (1 occurrences) Last logged: 13:36:07

Error running command: /config/custom_components/freeathome/scripts/fah_requirements.sh, return code: 126 NoneType: None

Seems that you don't have the correct permissions on "fah_requirements.sh"... Try to set the executable bits and run again:

chmod +x /config/custom_components/freeathome/scripts/fah_requirements.sh

AStenzel commented 1 year ago

Looks like this change breaks the integration: home-assistant/docker@e926373

This removed libsodium from the build of the Home Assistant base image. Home Assistant OS and Docker images are affected.

Not sure how to make a structural solution for this, other than adding libsodium as explained above.

In fact, they have removed a number of libs. Someone could try to add a request to add them back? The mariadb-connector was also removed and added back 1 hour ago.... Just give it a try! ;-)

mrVoltrix commented 1 year ago

I give now all permits to fah_requirements.sh But now I got another failure:

Error running command: `/config/custom_components/freeathome/scripts/fah_requirements.sh`, return code: 127
NoneType: None

I tried to add the libsodium manually: it looks like its added OK: 95 MiB in 97 packages

But when I restart home assistant I get again faillures;

Deze fout is ontstaan door een aangepaste integratie.

Logger: homeassistant.loader
Source: custom_components/freeathome/fah/crypto.py:2
Integration: Busch Jaeger/ABB Free@Home (documentation)
First occurred: 21:16:03 (6 occurrences)
Last logged: 21:16:27

Unexpected exception importing platform custom_components.freeathome.config_flow
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/loader.py", line 618, in get_platform
    cache[full_name] = self._import_platform(platform_name)
  File "/usr/src/homeassistant/homeassistant/loader.py", line 635, in _import_platform
    return importlib.import_module(f"{self.pkg_path}.{platform_name}")
  File "/usr/local/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/config/custom_components/freeathome/config_flow.py", line 12, in <module>
    from .fah.pfreeathome import FreeAtHomeSysApp
  File "/config/custom_components/freeathome/fah/pfreeathome.py", line 39, in <module>
    from .saslhandler import SaslHandler
  File "/config/custom_components/freeathome/fah/saslhandler.py", line 7, in <module>
    from .crypto import Crypto, loginSaslPayload, buildSaslResponse
  File "/config/custom_components/freeathome/fah/crypto.py", line 2, in <module>
    import libnacl
  File "/usr/local/lib/python3.10/site-packages/libnacl/__init__.py", line 85, in <module>
    nacl = _get_nacl()
  File "/usr/local/lib/python3.10/site-packages/libnacl/__init__.py", line 81, in _get_nacl
    raise OSError(msg)
OSError: Could not locate nacl lib, searched for libsodium.so, libsodium.so.23, libsodium.so.18, libsodium.so.17, libsodium.so.13, libsodium.so.10, libsodium.so.5, libsodium.so.4, 
bezibaerchen commented 1 year ago

I had an update for freeathome yesterday, everything still worked afterwards. libsodium and script still applied and changes from PR.

Now 2022-07.3 came up and it's broken again...

I guess HA guys don't make too many friends this time. I read that Homematic seems to be broken as well...

bezibaerchen commented 1 year ago

Update: Script stopped working for me as well now. manually apk adding in shell and restarting HA brought integration back to life again

AStenzel commented 1 year ago

Update: Script stopped working for me as well now. manually apk adding in shell and restarting HA brought integration back to life again

Was broken for me after update to 2022-07.3. I did a restart of HA only and fah is working again.

My script tries to add the apk after every HA restart, but this trigger is handled after integration tries to start, that's why I have to do a 2nd restart after each update!

AStenzel commented 1 year ago

I give now all permits to fah_requirements.sh But now I got another failure:

Error running command: `/config/custom_components/freeathome/scripts/fah_requirements.sh`, return code: 127
NoneType: None

Check your path and try running the command via terminal or ssh. If it works, you perhaps misspelled it in shell_command (configuration.yaml)...

fahhome123 commented 1 year ago

where is the shell script on source code directories? I can not find it.

derjoerg commented 1 year ago

where is the shell script on source code directories? I can not find it.

Nowhere. You have to create it on your own. Also the location is just a proposal. E.g. I have put it in /config/scripts/ where I have all my scripts.

Joerg

JvD12 commented 1 year ago

I give now all permits to fah_requirements.sh But now I got another failure:

Error running command: `/config/custom_components/freeathome/scripts/fah_requirements.sh`, return code: 127
NoneType: None

I tried to add the libsodium manually: it looks like its added OK: 95 MiB in 97 packages

But when I restart home assistant I get again faillures;

Deze fout is ontstaan door een aangepaste integratie.

Logger: homeassistant.loader
Source: custom_components/freeathome/fah/crypto.py:2
Integration: Busch Jaeger/ABB Free@Home (documentation)
First occurred: 21:16:03 (6 occurrences)
Last logged: 21:16:27

Unexpected exception importing platform custom_components.freeathome.config_flow
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/loader.py", line 618, in get_platform
    cache[full_name] = self._import_platform(platform_name)
  File "/usr/src/homeassistant/homeassistant/loader.py", line 635, in _import_platform
    return importlib.import_module(f"{self.pkg_path}.{platform_name}")
  File "/usr/local/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/config/custom_components/freeathome/config_flow.py", line 12, in <module>
    from .fah.pfreeathome import FreeAtHomeSysApp
  File "/config/custom_components/freeathome/fah/pfreeathome.py", line 39, in <module>
    from .saslhandler import SaslHandler
  File "/config/custom_components/freeathome/fah/saslhandler.py", line 7, in <module>
    from .crypto import Crypto, loginSaslPayload, buildSaslResponse
  File "/config/custom_components/freeathome/fah/crypto.py", line 2, in <module>
    import libnacl
  File "/usr/local/lib/python3.10/site-packages/libnacl/__init__.py", line 85, in <module>
    nacl = _get_nacl()
  File "/usr/local/lib/python3.10/site-packages/libnacl/__init__.py", line 81, in _get_nacl
    raise OSError(msg)
OSError: Could not locate nacl lib, searched for libsodium.so, libsodium.so.23, libsodium.so.18, libsodium.so.17, libsodium.so.13, libsodium.so.10, libsodium.so.5, libsodium.so.4, 

Do you already have a solution? I also installed libsodium but I still get this error.

RichardvanGestel commented 1 year ago

After udate HA from 2022.6.7 to 2022.7,5 freeathome could not be loaded Fix component setup in HA 2022.07 didn't help. Please help

mrVoltrix commented 1 year ago

I give now all permits to fah_requirements.sh But now I got another failure:

Error running command: `/config/custom_components/freeathome/scripts/fah_requirements.sh`, return code: 127
NoneType: None

I tried to add the libsodium manually: it looks like its added OK: 95 MiB in 97 packages But when I restart home assistant I get again faillures;

Deze fout is ontstaan door een aangepaste integratie.

Logger: homeassistant.loader
Source: custom_components/freeathome/fah/crypto.py:2
Integration: Busch Jaeger/ABB Free@Home (documentation)
First occurred: 21:16:03 (6 occurrences)
Last logged: 21:16:27

Unexpected exception importing platform custom_components.freeathome.config_flow
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/loader.py", line 618, in get_platform
    cache[full_name] = self._import_platform(platform_name)
  File "/usr/src/homeassistant/homeassistant/loader.py", line 635, in _import_platform
    return importlib.import_module(f"{self.pkg_path}.{platform_name}")
  File "/usr/local/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/config/custom_components/freeathome/config_flow.py", line 12, in <module>
    from .fah.pfreeathome import FreeAtHomeSysApp
  File "/config/custom_components/freeathome/fah/pfreeathome.py", line 39, in <module>
    from .saslhandler import SaslHandler
  File "/config/custom_components/freeathome/fah/saslhandler.py", line 7, in <module>
    from .crypto import Crypto, loginSaslPayload, buildSaslResponse
  File "/config/custom_components/freeathome/fah/crypto.py", line 2, in <module>
    import libnacl
  File "/usr/local/lib/python3.10/site-packages/libnacl/__init__.py", line 85, in <module>
    nacl = _get_nacl()
  File "/usr/local/lib/python3.10/site-packages/libnacl/__init__.py", line 81, in _get_nacl
    raise OSError(msg)
OSError: Could not locate nacl lib, searched for libsodium.so, libsodium.so.23, libsodium.so.18, libsodium.so.17, libsodium.so.13, libsodium.so.10, libsodium.so.5, libsodium.so.4, 

Do you already have a solution? I also installed libsodium but I still get this error.

No I still don't have a solution for it yet.

mrVoltrix commented 1 year ago

Somebody have some other solution yet? image

I'm sure I added Libsodium but the intigration still give an import error after restarting HA

rsegers commented 1 year ago

Somebody have some other solution yet? image

I'm sure I added Libsodium but the intigration still give an import error after restarting HA

You should add libsodium to HA Core, not HA OS. Instructions were posted here: https://github.com/jheling/freeathome/issues/130#issuecomment-1179329066

mrVoltrix commented 1 year ago
  • homeassistant

I tried to do that, but when I login via SHH and following the instructions I get:

[core-ssh ~]$ docker exec -it homeassistant /bin/bash -bash: docker: command not found

derjoerg commented 1 year ago
  • homeassistant

I tried to do that, but when I login via SHH and following the instructions I get:

[core-ssh ~]$ docker exec -it homeassistant /bin/bash -bash: docker: command not found

Have you disabled safe-mode of your ssh-plugin?

derjoerg commented 1 year ago
  • homeassistant

I tried to do that, but when I login via SHH and following the instructions I get: [core-ssh ~]$ docker exec -it homeassistant /bin/bash -bash: docker: command not found

Have you disabled safe-mode of your ssh-plugin?

It looks like you use the "ssh" addon from the official repository. Remove it and use the "ssh" addon from the community store. This has docker installed.

mrVoltrix commented 1 year ago
  • homeassistant

I tried to do that, but when I login via SHH and following the instructions I get: [core-ssh ~]$ docker exec -it homeassistant /bin/bash -bash: docker: command not found

Have you disabled safe-mode of your ssh-plugin?

It looks like you use the "ssh" addon from the official repository. Remove it and use the "ssh" addon from the community store. This has docker installed.

Thanks, This was the problem. Now everything is working again ;)

RichardvanGestel commented 1 year ago

Also with the update to 2022.6.7 freeathome does not work... Will this be resolved?

NeoBlack commented 1 year ago

I also run into this issue, I have installed a fresh 2022.7.6 and are not able to get free@home running :( I killed my old home bridge raspberry to start over with Home Assistant, and now I have nothing :D (yes, I know... you better have a backup)

RichardvanGestel commented 1 year ago

Also with the update to 2022.7.7 freeathome does not work... Backup is my best friend..;)

derjoerg commented 1 year ago

Hi,

as I see a lot of "F@H isn't working" messages in this issue I wanted to share my experience with it. Perhaps it helps ...

Main thanks goes to @bezibaerchen and the following comment https://github.com/jheling/freeathome/issues/130#issuecomment-1179549783, which helped me to get F@H working in 2022.7 (from 2022.7.1 to 20.22.7.7).

Pre-Info:

Root cause:

Pre-Step (for troubleshooting and so on):

Test-Step:

  1. SSH to your HA-instance
  2. Switch to the homeassistant-docker-instance docker exec -ti homeassistant bash
  3. Execute the following command apk info | grep 'libsodium'
  4. You should see no output, which means that the package libsodium is not installed
  5. Execute the command apk add libsodium
  6. After the command has finished restart HA (Settings - System - Restart [in the upper right corner)
  7. After the restart F@H should work again as expected a. If not, sorry, I'm out :( b. If yes, read on :)

So if you come to this point your F@H integration should work as expected. You can restart HA and still F@H should work. The drawback of this is, that, because of the nature of a docker-image, each update of HA will override this modification and you have to do the steps above again.

Making it permanent:

  1. SSH to your HA-instance
  2. Switch to the homeassistant-docker-instance docker exec -ti homeassistant bash a. You are now in the 'config' directory. I created a sub-directory 'scripts', which contains all my shell-scripts, but this isn't necessary. You just need to remember where you are :)
  3. Create an empty file touch fah_requirements.sh a. Make the file executable chmod +x fah_requirements.sh b. When doing a ls -l I see that existing files below to an user:group 911 and my newly created file belows to an user:group root c. I don't know if it is important, but it doesn't hurt, so I change the user:group to 911 chown 911: fah_requirements.sh
  4. Put the following lines in the file as outlined by @bezibaerchen in the above linked comment
    #!/bin/bash
    LIB_EXISTS=$(apk info | grep 'libsodium')
    if [[ -z $LIB_EXISTS ]]; then
    apk add libsodium
    fi
  5. Save and close the file
  6. Test the file by executing it ./fah_requirements.sh
  7. You should see no output and a echo $? should return 0, which means: no error
  8. Display the full path of the file by executing realpath fah_requirements.sh a. This display in my environment /config/scripts/fah_requirements.sh but may be different in your environment (see above step 2) b. Save this output somewhere
  9. You can now leave the ssh-session and use your prefered method to modify configuration.yaml
  10. Add the following lines to your configuration (and don't forget to save):
    shell_command:
    fah_requirements: /config/scripts/fah_requirements.sh

    (Replace the directory and filename with your setup you collected in step 8)

  11. Restart HA
  12. Create a new automation:
    Trigger type: Home Assistant (Event: Start)
    Action type: Call service (Shell Command: fah_requirements)
    - id: fah_requirements
    alias: FAH System Start
    trigger:
    - platform: homeassistant
    event: start
    action:
    - service: shell_command.fah_requirements
    data: {}
    mode: single

Final consideration:

I hope this write-down helps somebody to get the F@H-integration working again. For sure, this is not a permanent fix (I don't have the technical knowledge to propose a permanent fix), but it is working [at least for me]. I successfully upgraded HA all the way from 2022.7.1 till the current 2022.7.7 with just this one additional restart required.

Regards

NeoBlack commented 1 year ago

Thanks for the summary, I started from scratch and followed your instructions, and now it works for me too.

miguelcastilho commented 1 year ago

The guide from @derjoerg also works for me. Thank you so much. As for a permanent solution, let's hope this integration can be modified to work without the libsodium package.

NeoBlack commented 1 year ago

As for a permanent solution, let's hope this integration can be modified to work without the libsodium package. I am not familiar with the programming language behind this integration, but is it not possible to define and deliver the missing dependency directly with the integration?

jeroen84 commented 1 year ago

As a permanent solution I think we have two options:

  1. Switch from libnacl to pynacl package.
  2. Make a fork of libnacl and include libsodium in the pypi package build.

For 1, this is complex as outlined by @Tho85 .

For 2, this is a similar approach as how pynacl is build - it is dependent on libsodium as well - and the reason why this package works with HA.

Any other thoughts?

derjoerg commented 1 year ago

2 sounds for me like the way, which would result in less effort.

I would be happy to test :)

Gersh1970 commented 1 year ago

The guide worked for me too. Thanks a lot! Just one small thing to pay attention to: be a little patient, it can take up a minute before you see the switches in your dashboard appear again. I was al little too impatient and restored a backup twice thinking I had done something wrong.

RichardvanGestel commented 1 year ago

Also with version 2022.8 free@home does not work. I'm seriously concerned now.