YunoHost-Apps / homeassistant_ynh

Home automation platform package for YunoHost
https://www.home-assistant.io/
Apache License 2.0
20 stars 15 forks source link

Permissions errors trying to add Zigbee radio -- adding `homeassistant` to `dialout` group seemed to fix #311

Closed grahamalama closed 4 months ago

grahamalama commented 4 months ago

Describe the bug

Permissions errors trying to add Zigbee radio. Running usermod -a -G dialout homeassistant seemed to fix.

Context

Steps to reproduce

I enabled debug logging for ZHA:

cat configuration.yaml
...
logger:
  logs:
    zigpy: debug
    zigpy_deconz.zigbee.application: debug
    zigpy_deconz.api: debug
    zigpy_xbee.zigbee.application: debug
    zigpy_xbee.api: debug
    zigpy_zigate: debug
    zigpy_znp: debug
    zhaquirks: debug
...

Then tried adding a USB Zigbee radio through the UI:

image

(I also tried with the /dev/ttyACM0 path)

Expected behavior

Home assistant successfully adds the radio

Logs

Logs

``` 2024-04-01 14:26:34.589 DEBUG (MainThread) [zigpy.ota] Registering new OTA provider: 2024-04-01 14:26:34.590 DEBUG (MainThread) [zigpy.ota] Registering new OTA provider: 2024-04-01 14:26:34.590 DEBUG (MainThread) [zigpy.ota] Registering new OTA provider: 2024-04-01 14:26:34.590 DEBUG (MainThread) [zigpy.ota] Registering new OTA provider: 2024-04-01 14:26:34.590 DEBUG (MainThread) [zigpy.ota] Registering new OTA provider: 2024-04-01 14:26:34.598 DEBUG (bellows.thread_0) [zigpy.serial] Opening a serial connection to '/dev/serial/by-id/usb-ITEAD_SONOFF_Zigbee_3.0_USB_Dongle_Plus_V2_20231120104922-if00' (57600 baudrate) 2024-04-01 14:26:34.603 DEBUG (MainThread) [zigpy.application] Failed to probe with config {'path': '/dev/serial/by-id/usb-ITEAD_SONOFF_Zigbee_3.0_USB_Dongle_Plus_V2_20231120104922-if00', 'baudrate': 57600, 'flow_control': 'software'} Traceback (most recent call last): File "/var/www/homeassistant/lib/python3.11/site-packages/serial/serialposix.py", line 322, in open self.fd = os.open(self.portstr, os.O_RDWR | os.O_NOCTTY | os.O_NONBLOCK) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PermissionError: [Errno 13] Permission denied: '/dev/serial/by-id/usb-ITEAD_SONOFF_Zigbee_3.0_USB_Dongle_Plus_V2_20231120104922-if00' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/var/www/homeassistant/lib/python3.11/site-packages/zigpy/application.py", line 631, in probe await app.connect() File "/var/www/homeassistant/lib/python3.11/site-packages/bellows/zigbee/application.py", line 145, in connect await ezsp.connect(use_thread=self.config[CONF_USE_THREAD]) File "/var/www/homeassistant/lib/python3.11/site-packages/bellows/ezsp/__init__.py", line 145, in connect self._gw = await bellows.uart.connect(self._config, self, use_thread=use_thread) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/var/www/homeassistant/lib/python3.11/site-packages/bellows/uart.py", line 470, in connect protocol, connection_done = await thread.run_coroutine_threadsafe( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/var/www/homeassistant/lib/python3.11/site-packages/bellows/uart.py", line 449, in _connect transport, protocol = await zigpy.serial.create_serial_connection( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/var/www/homeassistant/lib/python3.11/site-packages/zigpy/serial.py", line 48, in create_serial_connection transport, protocol = await pyserial_asyncio.create_serial_connection( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/var/www/homeassistant/lib/python3.11/site-packages/serial_asyncio_fast/__init__.py", line 508, in create_serial_connection serial_instance = await loop.run_in_executor(None, callback) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/concurrent/futures/thread.py", line 58, in run result = self.fn(*self.args, **self.kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/var/www/homeassistant/lib/python3.11/site-packages/serial/__init__.py", line 90, in serial_for_url instance.open() File "/var/www/homeassistant/lib/python3.11/site-packages/serial/serialposix.py", line 325, in open raise SerialException(msg.errno, "could not open port {}: {}".format(self._port, msg)) serial.serialutil.SerialException: [Errno 13] could not open port /dev/serial/by-id/usb-ITEAD_SONOFF_Zigbee_3.0_USB_Dongle_Plus_V2_20231120104922-if00: [Errno 13] Permission denied: '/dev/serial/by-id/usb-ITEAD_SONOFF_Zigbee_3.0_USB_Dongle_Plus_V2_20231120104922-if00' 2024-04-01 14:31:11.683 DEBUG (MainThread) [zigpy.ota] Registering new OTA provider: 2024-04-01 14:31:11.684 DEBUG (MainThread) [zigpy.ota] Registering new OTA provider: 2024-04-01 14:31:11.684 DEBUG (MainThread) [zigpy.ota] Registering new OTA provider: 2024-04-01 14:31:11.684 DEBUG (MainThread) [zigpy.ota] Registering new OTA provider: 2024-04-01 14:31:11.685 DEBUG (MainThread) [zigpy.ota] Registering new OTA provider: 2024-04-01 14:31:11.693 DEBUG (bellows.thread_0) [zigpy.serial] Opening a serial connection to '/dev/ttyACM0' (57600 baudrate) 2024-04-01 14:31:11.696 DEBUG (MainThread) [zigpy.application] Failed to probe with config {'path': '/dev/ttyACM0', 'baudrate': 57600, 'flow_control': 'software'} Traceback (most recent call last): File "/var/www/homeassistant/lib/python3.11/site-packages/serial/serialposix.py", line 322, in open self.fd = os.open(self.portstr, os.O_RDWR | os.O_NOCTTY | os.O_NONBLOCK) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PermissionError: [Errno 13] Permission denied: '/dev/ttyACM0' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/var/www/homeassistant/lib/python3.11/site-packages/zigpy/application.py", line 631, in probe await app.connect() File "/var/www/homeassistant/lib/python3.11/site-packages/bellows/zigbee/application.py", line 145, in connect await ezsp.connect(use_thread=self.config[CONF_USE_THREAD]) File "/var/www/homeassistant/lib/python3.11/site-packages/bellows/ezsp/__init__.py", line 145, in connect self._gw = await bellows.uart.connect(self._config, self, use_thread=use_thread) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/var/www/homeassistant/lib/python3.11/site-packages/bellows/uart.py", line 470, in connect protocol, connection_done = await thread.run_coroutine_threadsafe( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/var/www/homeassistant/lib/python3.11/site-packages/bellows/uart.py", line 449, in _connect transport, protocol = await zigpy.serial.create_serial_connection( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/var/www/homeassistant/lib/python3.11/site-packages/zigpy/serial.py", line 48, in create_serial_connection transport, protocol = await pyserial_asyncio.create_serial_connection( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/var/www/homeassistant/lib/python3.11/site-packages/serial_asyncio_fast/__init__.py", line 508, in create_serial_connection serial_instance = await loop.run_in_executor(None, callback) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/concurrent/futures/thread.py", line 58, in run result = self.fn(*self.args, **self.kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/var/www/homeassistant/lib/python3.11/site-packages/serial/__init__.py", line 90, in serial_for_url instance.open() File "/var/www/homeassistant/lib/python3.11/site-packages/serial/serialposix.py", line 325, in open raise SerialException(msg.errno, "could not open port {}: {}".format(self._port, msg)) serial.serialutil.SerialException: [Errno 13] could not open port /dev/ttyACM0: [Errno 13] Permission denied: '/dev/ttyACM0' ```

This seems related to https://github.com/YunoHost-Apps/homeassistant_ynh/issues/40. Similar output as was done in that issue:

$ groups homeassistant
homeassistant : homeassistant
$ ls -la /dev/serial/by-id/usb-ITEAD_SONOFF_Zigbee_3.0_USB_Dongle_Plus_V2_20231120104922-if00
lrwxrwxrwx 1 root root 13 Apr  1 13:24 /dev/serial/by-id/usb-ITEAD_SONOFF_Zigbee_3.0_USB_Dongle_Plus_V2_20231120104922-if00 -> ../../ttyACM0
$ ls -la /dev/ttyACM0
crw-rw---- 1 root dialout 166, 0 Apr  1 13:24 /dev/ttyACM0

I also verified that DevicePolicy=closed is commented out:

$ cat /etc/systemd/system/homeassistant.service | grep DevicePolicy
#CANT BE ACTIVATED FOR homeassistant (see issue #40) #DevicePolicy=closed

This time though, unlike in #40, adding homeassistant to the dialout group and restarting home assistant seemed to fix things:

usermod -a -G dialout homeassistant

then, add radio with the /dev/ttyACM0 path.

ewilly commented 4 months ago

Thanks ! Fixed with #312