Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bluetooth component doesn't cope when the host doesn't have bluetooth #75706

Closed
Djelibeybi opened this issue Jul 25, 2022 · 12 comments
Closed

Bluetooth component doesn't cope when the host doesn't have bluetooth #75706

Djelibeybi opened this issue Jul 25, 2022 · 12 comments
Milestone

Comments

@Djelibeybi
Copy link
Contributor

The problem

There doesn't seem to be a way to run Home Assistant (dev) on an instance without Bluetooth, as homeassistant.components.bluetooth throws an error if bluetoothctl isn't installed.

I'm working in an WSL2 instance that has no access to Bluetooth. This then has cascading impact on the HomeKit Controller (which now depends on the bluetooth component).

What version of Home Assistant Core has the issue?

2022.8.0.dev0

What was the last working version of Home Assistant Core?

2022.7.6

What type of installation are you running?

Home Assistant Core

Integration causing the issue

No response

Link to integration documentation on our website

No response

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

Logger: homeassistant.loader
Source: components/bluetooth/__init__.py:12
First occurred: 3:11:57 PM (1 occurrences)
Last logged: 3:11:57 PM

Unexpected exception importing component homeassistant.components.bluetooth
Traceback (most recent call last):
  File "/home/amiller/Git/Hass/src/homeassistant/loader.py", line 638, in get_component
    cache[self.domain] = importlib.import_module(self.pkg_path)
  File "/usr/lib64/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 850, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "/home/amiller/Git/Hass/src/homeassistant/components/bluetooth/__init__.py", line 12, in <module>
    from bleak import BleakError
  File "/home/amiller/Git/Hass/src/venv/lib64/python3.9/site-packages/bleak/__init__.py", line 41, in <module>
    if not _on_ci and not check_bluez_version(5, 43):
  File "/home/amiller/Git/Hass/src/venv/lib64/python3.9/site-packages/bleak/backends/bluezdbus/__init__.py", line 17, in check_bluez_version
    p = subprocess.Popen(["bluetoothctl", "--version"], stdout=subprocess.PIPE)
  File "/usr/lib64/python3.9/subprocess.py", line 951, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/usr/lib64/python3.9/subprocess.py", line 1821, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'bluetoothctl'

Additional information

No response

@thecode thecode added this to the 2022.8.0b0 milestone Jul 26, 2022
@frenck frenck modified the milestones: 2022.8.0b0, 2022.8.0 Jul 27, 2022
@gregg098
Copy link

I'm running Home Assistant container ( 2022.8.0b1 - but it also happened on b0) on top of Debian 11 with the privileged flag and Bluez installed on the host, so I should meet the pre-reqs listed HERE. I know the Bluetooth adapter is available in the container, but I get a similar error, shown below.

Running a NUC6 using integrated Bluetooth adapter. Maybe that's the issue? Any other Bluetooth integration I test does work and can see the adapter. I made sure to disable all bluetooth integrations and restart Home Assistant prior to testing this integration.

Here's the error:

WARNING (MainThread) [homeassistant.config_entries] Config entry 'Bluetooth' for bluetooth integration not ready yet: Failed to start Bluetooth: [Errno 2] No such file or directory; Retrying in background

This is what my integration page looks like:

image

This is what I see when I click Configure:

image

Docker Compose:

  homeassistant:
    container_name: homeassistant
#    image: ghcr.io/home-assistant/home-assistant:2022.7
    image: homeassistant/home-assistant:rc
    restart: unless-stopped
    network_mode: host
    privileged: true
    depends_on:
      - mosquitto
    environment:
      - TZ=${TIMEZONE}
    volumes:
      - ${DOCKERDIR}/homeassistant/config:/config
      - ${DOCKERDIR}/homeassistant/db:/db

Result of lsusb from host (removed non-applicable devices):
Bus 003 Device 003: ID 8087:0aa7 Intel Corp. Wireless-AC 3168 Bluetooth

Result of lsusb inside of the container:
Bus 003 Device 003: ID 8087:0aa7

@balloob
Copy link
Member

balloob commented Jul 30, 2022

Fixed in #75941

@balloob balloob closed this as completed Jul 30, 2022
@ghost
Copy link

ghost commented Aug 5, 2022

Do I have the same issue? I have just updated from 2022.7.7 to 2022.8.1 and have the following in my logs:

Unexpected exception importing component homeassistant.components.bluetooth
12:01:39 – (ERROR) deps/lib/python3.9/site-packages/bleak/backends/bluezdbus/__init__.py
Setup failed for bluetooth: Unable to import component: Exception importing homeassistant.components.bluetooth
12:01:39 – (ERROR) setup.py
Unable to set up dependencies of default_config. Setup failed for dependencies: bluetooth
12:02:00 – (ERROR) setup.py
Setup failed for default_config: (DependencyError(...), 'Could not setup dependencies: bluetooth')
12:02:00 – (ERROR) setup.py
Error doing job: Task exception was never retrieved
12:02:20 – (ERROR) setup.py - message first occurred at 12:02:11 and shows up 2 times
Unable to set up dependencies of homekit_controller. Setup failed for dependencies: bluetooth
12:02:20 – (ERROR) setup.py - message first occurred at 12:02:11 and shows up 4 times

I do not (believe I have) have any BT devices on my R-Pi

@Djelibeybi
Copy link
Contributor Author

Which RPi is it? Some, like the 4B, have Bluetooth built-in.

@ghost
Copy link

ghost commented Aug 5, 2022

Agh, yes it's a 4b - thanks for explaining that.

What is my best course of action?

If it helps, I am running HA Core on DietPi (light Debian image) but can change to Docker if necessary

@Djelibeybi
Copy link
Contributor Author

Honestly, if the Pi is dedicated to running Home Assistant, just install Home Assistant OS. It gets the most testing.

@ghost
Copy link

ghost commented Aug 5, 2022

Hi,

It isn't. I am running other things (AdBlockPlus, Unbound).

Do you think Docker is worth a shot?

@Djelibeybi
Copy link
Contributor Author

Depends on how well you know Docker, I guess. If you don't need Bluetooth, I'd look into disabling it completely via /boot/config.txt on the Pi instead.

@ghost
Copy link

ghost commented Aug 5, 2022

agh - good idea - thanks!

@ghost
Copy link

ghost commented Aug 5, 2022

Just checked - Bluetooth is already disabled.

...very odd, but I'll try docker.

@ghost
Copy link

ghost commented Aug 5, 2022

OK, posting for anyone else that has this issue. Turning my Pi's Bluetooth on (and restarting HA) fixes it.

This is repeatable. Turning Bluetooth off brings the problem back.

This is using HA Core running on a Pi-4b with DietPi OS.

@ghost
Copy link

ghost commented Aug 6, 2022

...and just for completion, HA works fine when running in Docker with my Pi's Bluetooth disabled.

@github-actions github-actions bot locked and limited conversation to collaborators Sep 5, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants