klali / ha-plejd

Plejd component for Home Assistant
Apache License 2.0
69 stars 15 forks source link

FileNotFound #31

Closed mist0706 closed 4 years ago

mist0706 commented 4 years ago

Hi,

I'm using the standard homeassistant docker container (not hass.io). After creating the custom components folder, cloning in the files and adding the configuration.yaml section i get the following error in the log:


2020-05-04 20:47:38 ERROR (MainThread) [homeassistant.components.light] Error while setting up plejd platform for light
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 178, in _async_setup_platform
    await asyncio.wait_for(asyncio.shield(task), SLOW_SETUP_MAX_WAIT)
  File "/usr/local/lib/python3.7/asyncio/tasks.py", line 442, in wait_for
    return fut.result()
  File "/config/custom_components/plejd/light.py", line 417, in async_setup_platform
    await connect(plejdinfo)
  File "/config/custom_components/plejd/light.py", line 149, in connect
    bus = await MessageBus(bus_type=BusType.SYSTEM).connect()
  File "/usr/local/lib/python3.7/site-packages/dbus_next/aio/message_bus.py", line 39, in __init__
    super().__init__(bus_address, bus_type, ProxyObject)
  File "/usr/local/lib/python3.7/site-packages/dbus_next/message_bus.py", line 72, in __init__
    self._setup_socket()
  File "/usr/local/lib/python3.7/site-packages/dbus_next/message_bus.py", line 499, in _setup_socket
    raise err
  File "/usr/local/lib/python3.7/site-packages/dbus_next/message_bus.py", line 493, in _setup_socket
    self._sock.connect(filename)
FileNotFoundError: [Errno 2] No such file or directory

When i run hcitool lescan inside the container i get the expected output:

bash-5.0# hcitool lescan
LE Scan ...
33:DE:F5:9F:FE:58 (unknown)
FA:43:4E:45:BD:A4 P mesh
FA:43:4E:45:BD:A4 (unknown)
CC:D3:19:98:B5:EF P mesh
33:DE:F5:9F:FE:58 (unknown)

What would be the next step be in troubleshooting? It seems to me like there is some dbus issue but it's beyond my debugging capabilities

klali commented 4 years ago

This sounds like the same thing as #27 which is that the dbus socket is not in the expected place. Can you check if you have that as /run/dbus/system_bus_socket (inside the container)?

I have a branch at https://github.com/klali/ha-plejd/tree/dbus_path that lets this be specified, if you have that file I should merge that and make that path the default.

mist0706 commented 4 years ago

That path didn't exist in the container but did exist in the host OS so i tried a volume mapping with no success. The error message changed to this instead:

2020-05-05 12:21:54 ERROR (MainThread) [root] adding match to "NameOwnerChanged" failed 2020-05-05 12:21:54 ERROR (MainThread) [root] adding match to "NameOwnerChanged" failed 2020-05-05 12:21:54 ERROR (MainThread) [root] adding match to "NameOwnerChanged" failed 2020-05-05 12:21:54 ERROR (MainThread) [root] adding match to "NameOwnerChanged" failed 2020-05-05 12:21:54 ERROR (MainThread) [root] adding match to "NameOwnerChanged" failed 2020-05-05 12:21:54 ERROR (MainThread) [root] adding match to "NameOwnerChanged" failed 2020-05-05 12:21:54 ERROR (MainThread) [root] adding match to "NameOwnerChanged" failed 2020-05-05 12:21:54 ERROR (MainThread) [root] adding match to "NameOwnerChanged" failed 2020-05-05 12:21:54 ERROR (MainThread) [root] got unexpected error processing a message: maximum recursion depth exceeded. Traceback (most recent call last): File "/usr/local/lib/python3.7/site-packages/dbus_next/message_bus.py", line 545, in _on_message self._process_message(msg) File "/usr/local/lib/python3.7/site-packages/dbus_next/message_bus.py", line 638, in _process_message handler(msg, None) File "/usr/local/lib/python3.7/site-packages/dbus_next/aio/message_bus.py", line 91, in on_match_added self._finalize(DBusError._from_message(reply)) File "/usr/local/lib/python3.7/site-packages/dbus_next/message_bus.py", line 415, in _finalize handler(None, err) File "/usr/local/lib/python3.7/site-packages/dbus_next/aio/message_bus.py", line 87, in on_match_added self._finalize(err) File "/usr/local/lib/python3.7/site-packages/dbus_next/message_bus.py", line 415, in _finalize handler(None, err)

mist0706 commented 4 years ago

Actually reading through issue #27 i can see my dbus is available in /var/run/dbus/system_bus_socket but mounting it in the container doesn't help

klali commented 4 years ago

So after mounting it in the container, can you run dbus-monitor --system and see if that works?

Are you running this as a user that has permissions to the dbus socket? The location of the socket file shouldn't really matter as long as it can be found.

mist0706 commented 4 years ago

So docker is running as root. I've always had issues with permissions in linux so this might be the case but root really should have access to everything right?

uid=0(root) gid=0(root) groups=0(root),1(bin),2(daemon),3(sys),4(adm),6(disk),10(wheel),11(floppy),20(dialout),26(tape),27(video)
bash-5.0# dbus-monitor --system
Failed to open connection to system bus: An AppArmor policy prevents this sender from sending this message to this recipient; type="method_call", sender="(null)" (inactive) interface="org.freedesktop.DBus" member="Hello" error name="(unset)" requested_reply="0" destination="org.freedesktop.DBus" (bus)
mist0706 commented 4 years ago

Okay so it seems i had to put the container into privileged mode, that was my mistake (See AppArmor policy message). After adding that it started working. Now instead it's unable to find devices but that's a completely separate issue i guess. Feel free to close

klali commented 4 years ago

Yeah, that sounds like a separate issue, if running as the root user there should be full permissions to the bluetooth subsystem. Feel free to open a new issue (with logs) if you need help troubleshooting.