albertogeniola / meross-homeassistant

Custom component that leverages the Meross IoT library to integrate with Homeassistant
MIT License
730 stars 83 forks source link

Crypto package not found #497

Closed mail4reset closed 6 months ago

mail4reset commented 7 months ago

After upgrading from v1.2.13 (meross_iot==0.4.6.2) to v.1.3.0 (meross_iot==0.4.7.0) the integration stops working with the error detailed in the log. After googling for a while I found the Crypto package seems to be deprecated. I checked in my venv and found:

(homeassistant) homeassistant@raspberrypi:/srv/homeassistant $ pip list | grep crypto
cryptography                 42.0.5
pycryptodomex                3.20.0

So I managed to bypass this problem by changing the line 4 of the file /srv/homeassistant/lib/python3.12/site-packages/meross_iot/controller/mixins/encryption.py from from Crypto.Cipher import AES to from Cryptodome.Cipher import AES. Now the integration is working fine.

Your environment HomeAssistant version: Core 2024.4.3 - Frontend 20240404.2 Hardware environment: Raspberry Pi 4

Logs taken when the issue happened

2024-04-27 09:39:58.969 ERROR (MainThread) [homeassistant.setup] Setup failed for custom integration 'meross_cloud': Unable to import component: No module named 'Crypto'
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.12/site-packages/homeassistant/loader.py", line 979, in async_get_component
    comp = await self.hass.async_add_import_executor_job(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/srv/homeassistant/lib/python3.12/site-packages/homeassistant/loader.py", line 1037, in _get_component
    ComponentProtocol, importlib.import_module(self.pkg_path)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/importlib/__init__.py", line 90, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 995, in exec_module
  File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
  File "/home/homeassistant/.homeassistant/custom_components/meross_cloud/__init__.py", line 17, in <module>
    from meross_iot.manager import MerossManager
  File "/srv/homeassistant/lib/python3.12/site-packages/meross_iot/manager.py", line 21, in <module>
    from meross_iot.device_factory import (
  File "/srv/homeassistant/lib/python3.12/site-packages/meross_iot/device_factory.py", line 10, in <module>
    from meross_iot.controller.mixins.encryption import EncryptionSuiteMixin
  File "/srv/homeassistant/lib/python3.12/site-packages/meross_iot/controller/mixins/encryption.py", line 4, in <module>
    from Crypto.Cipher import AES
ModuleNotFoundError: No module named 'Crypto'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.12/site-packages/homeassistant/setup.py", line 316, in _async_setup_component
    component = await integration.async_get_component()
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/srv/homeassistant/lib/python3.12/site-packages/homeassistant/loader.py", line 997, in async_get_component
    self._component_future.result()
  File "/srv/homeassistant/lib/python3.12/site-packages/homeassistant/loader.py", line 989, in async_get_component
    comp = self._get_component()
           ^^^^^^^^^^^^^^^^^^^^^
  File "/srv/homeassistant/lib/python3.12/site-packages/homeassistant/loader.py", line 1037, in _get_component
    ComponentProtocol, importlib.import_module(self.pkg_path)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/importlib/__init__.py", line 90, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 995, in exec_module
  File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
  File "/home/homeassistant/.homeassistant/custom_components/meross_cloud/__init__.py", line 17, in <module>
    from meross_iot.manager import MerossManager
  File "/srv/homeassistant/lib/python3.12/site-packages/meross_iot/manager.py", line 21, in <module>
    from meross_iot.device_factory import (
  File "/srv/homeassistant/lib/python3.12/site-packages/meross_iot/device_factory.py", line 10, in <module>
    from meross_iot.controller.mixins.encryption import EncryptionSuiteMixin
  File "/srv/homeassistant/lib/python3.12/site-packages/meross_iot/controller/mixins/encryption.py", line 4, in <module>
    from Crypto.Cipher import AES
ModuleNotFoundError: No module named 'Crypto'
albertogeniola commented 6 months ago

Hi @mail4reset , good catch. This is an error on the low MerossIot library, which missed the correct dependency import within setup.py. I'll check on that and report back when a newer beta version is ready for you to test.

albertogeniola commented 6 months ago

Hi @mail4reset ,

v1.3.1 should fix the issue. Can you please test it and report if working as expected now?

mail4reset commented 6 months ago

Hi Alberto, v1.3.1 solved the issue. Thank you very much for your quick answer!