Unable to use bleak within appdaemon script

Hey, just after some pointers to get bleak and dbus working within a python script I’m running out of appdaemon.

Setup is a RPI4 x64 - install was done through docker using the supervised install.

tried adding to the config:

init_commands: []
python_packages:
  - bleak
system_packages:
  - dbus

code snippets:

import bleak
from bleak import BleakScanner, BleakClient

devices = await BleakScanner.discover()
        if not devices:
            self.log("No devices found.")
            return
    
        # Print available devices
        for i, device in enumerate(devices):
            self.log("{}: {}".format(i, device))

Log is:

  File "/usr/lib/python3.10/site-packages/appdaemon/threading.py", line 826, in async_worker
    await funcref(
  File "/config/appdaemon/apps/my_script.py", line 24, in button_callback
    await self.run_script()
  File "/config/appdaemon/apps/my_script.py", line 35, in run_script
    devices = await BleakScanner.discover()
  File "/usr/lib/python3.10/site-packages/bleak/__init__.py", line 216, in discover
    async with cls(**kwargs) as scanner:
  File "/usr/lib/python3.10/site-packages/bleak/__init__.py", line 126, in __aenter__
    await self._backend.start()
  File "/usr/lib/python3.10/site-packages/bleak/backends/bluezdbus/scanner.py", line 174, in start
    manager = await get_global_bluez_manager()
  File "/usr/lib/python3.10/site-packages/bleak/backends/bluezdbus/manager.py", line 896, in get_global_bluez_manager
    await instance.async_init()
  File "/usr/lib/python3.10/site-packages/bleak/backends/bluezdbus/manager.py", line 190, in async_init
    bus = MessageBus(bus_type=BusType.SYSTEM)
  File "/usr/lib/python3.10/site-packages/dbus_fast/aio/message_bus.py", line 172, in __init__
    super().__init__(bus_address, bus_type, ProxyObject, negotiate_unix_fd)
  File "src/dbus_fast/message_bus.py", line 186, in dbus_fast.message_bus.BaseMessageBus.__init__
  File "src/dbus_fast/message_bus.py", line 740, in dbus_fast.message_bus.BaseMessageBus._setup_socket
  File "src/dbus_fast/message_bus.py", line 713, in dbus_fast.message_bus.BaseMessageBus._setup_socket
FileNotFoundError: [Errno 2] No such file or directory```

I ended up giving in and swapping over to docker/docker composer.

Added /var/run/dbus:/var/run/dbus to docker-compose.yaml and it seems okay to use.

    volumes:
      # Set which local directory will contain all your app daemon configuration
      - /opt/appdaemon:/conf
      - /var/run/dbus:/var/run/dbus

Hello @mishaVee
Running into the same issue now. Can you share your docker-compose.yaml file config if you still have that somewhere?
I’ve mounted volumes and ran as privileged, still getting the same error.