klali / ha-plejd

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

Error while setting up plejd platform for light #29

Closed davidvirdeforshh closed 4 years ago

davidvirdeforshh commented 4 years ago

I can not get my plejd device to show up in HA. I get the following error in the HA logs:

HA Log

Error while setting up plejd platform for light
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 179, 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 38, in __init__
    super().__init__(bus_address, bus_type, ProxyObject)
  File "/usr/local/lib/python3.7/site-packages/dbus_next/message_bus.py", line 71, in __init__
    self._setup_socket()
  File "/usr/local/lib/python3.7/site-packages/dbus_next/message_bus.py", line 447, in _setup_socket
    raise err
  File "/usr/local/lib/python3.7/site-packages/dbus_next/message_bus.py", line 441, in _setup_socket
    self._sock.connect(filename)
FileNotFoundError: [Errno 2] No such file or directory

Setup

HW: Raspberry Pi 4 SW: Home Assistant Supervised i.e. running Home Assistant on a generic (Raspbian Lite) Linux Dist.

Install

Got the latest branch cloned into: /usr/share/hassio/homeassistant/custom_components/plejd which contains the following files.

drwxr-xr-x 8 root root  4096 Feb 28 23:06 .git
-rw-r--r-- 1 root root    23 Feb 28 23:06 __init__.py
-rw-r--r-- 1 root root 11357 Feb 28 23:06 LICENSE.md
-rw-r--r-- 1 root root 15130 Feb 28 23:06 light.py
-rw-r--r-- 1 root root   202 Feb 28 23:06 manifest.json
drwxr-xr-x 2 root root  4096 Mar  2 10:23 __pycache__
-rw-r--r-- 1 root root  4230 Feb 28 23:06 README.md

hcitool

Running hcitool as user 'pi':

 hcitool dev
Devices:
    hci0    DC:A6:32:3A:5D:EC

configuration.yaml:

logger:
   logs:
     custom_components.plejd: debug
 light:
   - platform: plejd
     crypto_key: '34*************A2'
     devices:
       11:
         name: bathroom

Please help.

I've not moved any. user to bluetooth group. To be honest I 'm not sure which user Home Asssistant is running as.

klali commented 4 years ago

I don't know what you get installed/running with raspbian.

Are you running home-assistant in a container or straight on raspbian?

The file dbus looks for is usually /var/run/dbus/system_bus_socket does that exist for you?

You can check what user home-assistant runs as with something like: ps aux | grep hass username is in first column, that user will have to be in the bluetooth group or have permissions to send dbus messages to bluez.

klali commented 4 years ago

You can also look at #27 for someone else who had similar errors.

davidvirdeforshh commented 4 years ago

Thanks for your swift response @klali !

HA Supervised is running HA as a docker container. @klali You where right: /var/run/dbus/system_bus_socket is available from host system, but not from within the docker container. Even though -v /var/run/dbus:/var/run/dbus is added to the docker run command, as mentioned in #27. I'm at a loss here, but it could be that this issue is on home assistant supervised, rather than ha-plejd.

davidvirdeforshh commented 4 years ago

Reported https://github.com/home-assistant/supervisor/issues/1561

davidvirdeforshh commented 4 years ago

home assistant says that ha-plejd should "look in the right place". I can not see how that would be achieved. Any ideas?

klali commented 4 years ago

I wonder what the right path is.

This is controlled by the dbus implementation in https://github.com/altdesktop/python-dbus-next/blob/master/dbus_next/_private/address.py#L43 and can be pointed at a different location by the environment variable DBUS_SYSTEM_BUS_ADDRESS

klali commented 4 years ago

So it might be that the path inside the supervisor is /run/dbus/system_bus_socket instead, I've just pushed a branch (https://github.com/klali/ha-plejd/tree/dbus_path) that gives the ability to set the dbus address, if you use this branch and add: dbus_address: unix:path=/run/dbus/system_bus_socket to the plejd section of your configuration it might find the bus.

davidvirdeforshh commented 4 years ago

I appreciate you adding that feature @klali. I do believe that line: 420 in light.py should have brackets instead of parentheses: plejdinfo["dbus_address"] = config[CONF_DBUS_ADDRESS]

But even after changing that I got this error: Error while setting up plejd platform for light Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 179, 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 424, in async_setup_platform await connect(plejdinfo) File "/config/custom_components/plejd/light.py", line 151, in connect bus = await MessageBus(bus_type=BusType.SYSTEM, bus_address=pi["dbus_address"]).connect() File "/usr/local/lib/python3.7/site-packages/dbus_next/aio/message_bus.py", line 38, in __init__ super().__init__(bus_address, bus_type, ProxyObject) File "/usr/local/lib/python3.7/site-packages/dbus_next/message_bus.py", line 71, in __init__ self._setup_socket() File "/usr/local/lib/python3.7/site-packages/dbus_next/message_bus.py", line 447, in _setup_socket raise err File "/usr/local/lib/python3.7/site-packages/dbus_next/message_bus.py", line 441, in _setup_socket self._sock.connect(filename) FileNotFoundError: [Errno 2] No such file or directory

This leads me to believe that setting this this up on supervised HA is non trivial. I will try "normal" HA instead.

klali commented 4 years ago

Yes, that should be [], I pushed that to the branch.

Looking a bit at this (setting it up in a virtual machine), the hassio_supervisor container gets the dbus socket mapped through to it, but in the homeassistant container (where homeassistant actually runs) doesn't get the dbus socket. The code for this is at https://github.com/home-assistant/supervisor/blob/dev/supervisor/docker/homeassistant.py#L49

Emlben commented 3 years ago

Yes, that should be [], I pushed that to the branch.

Looking a bit at this (setting it up in a virtual machine), the hassio_supervisor container gets the dbus socket mapped through to it, but in the homeassistant container (where homeassistant actually runs) doesn't get the dbus socket. The code for this is at https://github.com/home-assistant/supervisor/blob/dev/supervisor/docker/homeassistant.py#L49

That is a dead link nowadays

Chetic commented 3 years ago

Was there ever a solution to this? I'm stuck on exactly this problem. I'm running HA in a container with image homeassistant/raspberrypi3-homeassistant:2021.6.4. Not a clue on what to do. Stacktrace:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 250, in _async_setup_platform
    await asyncio.shield(task)
  File "/config/custom_components/plejd/light.py", line 478, in async_setup_platform
    await connect(plejdinfo)
  File "/config/custom_components/plejd/light.py", line 174, in connect
    bus = await MessageBus(bus_type=BusType.SYSTEM, bus_address=pi["dbus_address"]).connect()
  File "/usr/local/lib/python3.8/site-packages/dbus_next/aio/message_bus.py", line 122, in __init__
    super().__init__(bus_address, bus_type, ProxyObject)
  File "/usr/local/lib/python3.8/site-packages/dbus_next/message_bus.py", line 86, in __init__
    self._setup_socket()
  File "/usr/local/lib/python3.8/site-packages/dbus_next/message_bus.py", line 569, in _setup_socket
    raise err
  File "/usr/local/lib/python3.8/site-packages/dbus_next/message_bus.py", line 542, in _setup_socket
    self._sock.connect(filename)
FileNotFoundError: [Errno 2] No such file or directory
klali commented 3 years ago

You need to check that the dbus socket is mapped through to the container, and as what it's mapped on the inside.

Chetic commented 3 years ago

You need to check that the dbus socket is mapped through to the container, and as what it's mapped on the inside.

Not sure I follow. I did the same thing as @davidvirdeforshh, namely -v /var/run/dbus:/var/run/dbus and I can see the socket file as /var/run/dbus/system_bus_socket both in the container and outside. The stack trace doesn't actually say what file it is attempting to use to connect so what do I do?

klali commented 3 years ago

I changed the default to look for /run/dbus/system_bus_socket so map it as such and it should be found. I guess this could be made better by catching that error and trying to explain what goes wrong and what the solution might be.

https://github.com/klali/ha-plejd/pull/49 would be code for giving a better error here, try it please? =)

Chetic commented 3 years ago

49 did log an error with the file path /run/dbus/system_bus_socket which is super helpful for anyone in my position! I changed -v /var/run/dbus:/var/run/dbus when starting the container to -v /run/dbus:/run/dbus and am no longer getting the error. Thanks!