home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
71.69k stars 29.96k forks source link

Can't add "bluetooth" integration #126436

Open dkm opened 3 hours ago

dkm commented 3 hours ago

The problem

I'm installing homeassistant via a simple python venv (I have very limited usage of HA). The installation from a few months back was working correctly, but after a recent update (and then from scratch), the bluetooth integration can't be loaded.

What version of Home Assistant Core has the issue?

core-2024.9.2

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant Core

Integration causing the issue

bluetooth

Link to integration documentation on our website

https://www.home-assistant.io/integrations/bluetooth/

Diagnostics information

No response

Example YAML snippet

bluetooth:

Anything in the logs that might be useful for us?

2024-09-22 15:28:01.881 ERROR (MainThread) [homeassistant.setup] Setup failed for 'bluetooth': Unable to import component: Exception importing homeassistant.components.bluetooth                                                              
Traceback (most recent call last):                         
  File "/home/hass/hass/venv/lib/python3.12/site-packages/homeassistant/loader.py", line 1067, in _get_component                                                                                                                               
    ComponentProtocol, importlib.import_module(self.pkg_path)                                                          
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                                          
  File "/home/hass/hass/venv/lib/python3.12/site-packages/homeassistant/util/loop.py", line 200, in protected_loop_func                                                                                                                        
    return func(*args, **kwargs)                                                                                       
           ^^^^^^^^^^^^^^^^^^^^^                                                                                       
  File "/usr/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/hass/hass/venv/lib/python3.12/site-packages/homeassistant/components/bluetooth/__init__.py", line 27, in <module>                                                                                                                
    from habluetooth import (                                                                                          
  File "/home/hass/hass/venv/lib/python3.12/site-packages/habluetooth/__init__.py", line 3, in <module>                                                                                                                                        
    from .advertisement_tracker import (                                                                                                                                                                                                       
  File "src/habluetooth/advertisement_tracker.py", line 1, in init habluetooth.advertisement_tracker                                                                                                                                           
AttributeError: module 'habluetooth.models' has no attribute '__pyx_capi__'                                                                                                                                                                    

The above exception was the direct cause of the following exception:                                                   

Traceback (most recent call last):                         
  File "/home/hass/hass/venv/lib/python3.12/site-packages/homeassistant/loader.py", line 1007, in async_get_component                                                                                                                                                            
    comp = await self.hass.async_add_import_executor_job(                                                                               
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                                                               
  File "/usr/lib/python3.12/concurrent/futures/thread.py", line 58, in run                                                              
    result = self.fn(*self.args, **self.kwargs)                                                                                         
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                                                                         
  File "/home/hass/hass/venv/lib/python3.12/site-packages/homeassistant/loader.py", line 1078, in _get_component                                                                                                                                                                 
    raise ImportError(f"Exception importing {self.pkg_path}") from err                                                                  
ImportError: Exception importing homeassistant.components.bluetooth                                                                     

During handling of the above exception, another exception occurred:                                                                     

Traceback (most recent call last):                                  
  File "/home/hass/hass/venv/lib/python3.12/site-packages/homeassistant/loader.py", line 1067, in _get_component                                                                                                                                                                 
    ComponentProtocol, importlib.import_module(self.pkg_path)                                                                           
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                                                           
  File "/home/hass/hass/venv/lib/python3.12/site-packages/homeassistant/util/loop.py", line 200, in protected_loop_func                                                                                                                                                          
    return func(*args, **kwargs)                                    
           ^^^^^^^^^^^^^^^^^^^^^                                    
  File "/usr/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/hass/hass/venv/lib/python3.12/site-packages/homeassistant/components/bluetooth/__init__.py", line 27, in <module>                                                                                                                                                  
    from habluetooth import (                                       
  File "/home/hass/hass/venv/lib/python3.12/site-packages/habluetooth/__init__.py", line 3, in <module>                                                                                                                                                                          
    from .advertisement_tracker import (                            
  File "src/habluetooth/advertisement_tracker.py", line 1, in init habluetooth.advertisement_tracker                                                                                                                                                                             
AttributeError: module 'habluetooth.models' has no attribute '__pyx_capi__'                                                             


### Additional information

I recreated the python venv, but kept the `~/.homeassistant` directory (I didn't restart all config from scratch).
I'm running on Debian Sid, on raspi4 (python 3.12.3)
home-assistant[bot] commented 3 hours ago

Hey there @bdraco, mind taking a look at this issue as it has been labeled with an integration (bluetooth) you are listed as a code owner for? Thanks!

Code owner commands Code owners of `bluetooth` can trigger bot actions by commenting: - `@home-assistant close` Closes the issue. - `@home-assistant rename Awesome new title` Renames the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign bluetooth` Removes the current integration label and assignees on the issue, add the integration domain after the command. - `@home-assistant add-label needs-more-information` Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue. - `@home-assistant remove-label needs-more-information` Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


bluetooth documentation bluetooth source (message by IssueLinks)

bdraco commented 2 hours ago

Its likely that you have an old verison of habluetooth installed somewhre

dkm commented 43 minutes ago

Hmm, maybe, but I don't know how to really check that. Here's a small session where I check I don't have any existing module installed, and then create a new venv.

hass@hasspi:~$ python3.12 -c "import habluetooth"                                                         
Traceback (most recent call last):                                                                        
  File "<string>", line 1, in <module>                                                                    
ModuleNotFoundError: No module named 'habluetooth'  
hass@hasspi:~$ python3.12 -m venv new                                                                      
hass@hasspi:~$ . ./new/bin/activate                                                                       
(new) hass@hasspi:~$ python3.12 -c "import habluetooth"            
Traceback (most recent call last):                                                                        
  File "<string>", line 1, in <module>             
ModuleNotFoundError: No module named 'habluetooth'                                                        
(new) hass@hasspi:~$ pip install habluetooth                                                              
Collecting habluetooth                                                                                    
  Using cached habluetooth-3.4.0-cp312-cp312-manylinux_2_38_aarch64.whl
....
Successfully installed PyRIC-0.1.6.3 aiooui-0.1.6 async-interrupt-1.2.0 bleak-0.22.2 bleak-retry-connector-3.5.0 bluetooth-adapters-0.19.4 bluetooth-auto-recovery-1.4.2 bluetooth-data-tools-1.20.0 btsocket-0.3.0 cffi-1.17.1 cryptography-43.0.1 dbus-fast-2.24.2 habluetooth-3.4.0 pycparser-2.22 uart-devices-0.1.0 usb-devices-0.4.5
(new) hass@hasspi:~$ pip show habluetooth
Name: habluetooth
Version: 3.4.0
Summary: High availability Bluetooth
Home-page: https://github.com/bluetooth-devices/habluetooth
Author: J. Nick Koston
Author-email: bluetooth@koston.org
License: 
Location: /home/hass/new/lib/python3.12/site-packages
Requires: async-interrupt, bleak, bleak-retry-connector, bluetooth-adapters, bluetooth-auto-recovery, bluetooth-data-tools
Required-by: 
(new) hass@hasspi:~$ python3.12 -c "import habluetooth"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/hass/new/lib/python3.12/site-packages/habluetooth/__init__.py", line 3, in <module>
    from .advertisement_tracker import (
  File "src/habluetooth/advertisement_tracker.py", line 1, in init habluetooth.advertisement_tracker
AttributeError: module 'habluetooth.models' has no attribute '__pyx_capi__'
dkm commented 38 minutes ago

Maybe I should report it on their github project instead. I only realize now that habluetooth is not hosted in home-assistant.

dkm commented 23 minutes ago

3.3.2 doesn't have this behavior, but I'm not sure I can force this version...

dkm commented 17 minutes ago

Yes, installing 3.3.2 doesn't help, hass seems to be auto-updating the module to 3.4.0.

(venv) hass@hasspi:~/hass/venv$ pip show habluetooth                                                                                                                                                                
Name: habluetooth                                                                                                                                                                                                   
Version: 3.3.2                                                                                                                                                                                                      
Summary: High availability Bluetooth                                                                                                                                                                                
Home-page: https://github.com/bluetooth-devices/habluetooth                                                                                                                                                         
Author: J. Nick Koston                                                                                                                                                                                              
Author-email: bluetooth@koston.org                                                                                                                                                                                  
License:                                                                                                                                                                                                            
Location: /home/hass/hass/venv/lib/python3.12/site-packages                                                                                                                                                         
Requires: async-interrupt, bleak, bleak-retry-connector, bluetooth-adapters, bluetooth-auto-recovery, bluetooth-data-tools                                                                                          
Required-by: home-assistant-bluetooth                                                                                                                                                                               
(venv) hass@hasspi:~/hass/venv$ hass                                                 
...
KeyboardInterrupt: 
^C
(venv) hass@hasspi:~/hass/venv$ pip show habluetooth
Name: habluetooth
Version: 3.4.0
Summary: High availability Bluetooth
Home-page: https://github.com/bluetooth-devices/habluetooth
Author: J. Nick Koston
Author-email: bluetooth@koston.org
License: 
Location: /home/hass/hass/venv/lib/python3.12/site-packages
Requires: async-interrupt, bleak, bleak-retry-connector, bluetooth-adapters, bluetooth-auto-recovery, bluetooth-data-tools
Required-by: home-assistant-bluetooth
bdraco commented 8 minutes ago

Which cython version are you using to do the build?

Are you sure you don't have multiple copies of the habluetooth.models shared object on your system, and its loading the wrong one?

AttributeError: module 'habluetooth.models' has no attribute '__pyx_capi__' seems to indicate you have mismatched versions