home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
72.09k stars 30.18k forks source link

Pizigate not loading #43110

Closed printzlau closed 3 years ago

printzlau commented 3 years ago

The problem

After upgrading to 0.118.b0 - ZHA is not able to load pizigate

Environment

installation_type: Home Assistant OS version: 0.118.0b0 dev: false virtualenv: false python_version: 3.8.6 docker: true arch: armv7l timezone: Europe/Copenhagen os_name: Linux os_version: 4.19.127-v7 supervisor: 2020.11.0 host_os: HassOS 4.16 docker_version: 19.03.12 chassis: embedded

Problem-relevant configuration.yaml

zha:
  zigpy_config:
    topology_scan_enabled: False

Traceback/Error logs

Logger: homeassistant.config_entries
Source: components/zha/core/gateway.py:147
First occurred: 10:43:22 PM (1 occurrences)
Last logged: 10:43:22 PM

Error setting up entry pizigate:/dev/ttyAMA0 for zha
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/serial/serialposix.py", line 265, in open
    self.fd = os.open(self.portstr, os.O_RDWR | os.O_NOCTTY | os.O_NONBLOCK)
FileNotFoundError: [Errno 2] No such file or directory: '/config/pizigate:/dev/ttyAMA0'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/zigpy/application.py", line 68, in new
    await app.startup(auto_form)
  File "/usr/local/lib/python3.8/site-packages/zigpy_zigate/zigbee/application.py", line 38, in startup
    self._api = await ZiGate.new(self._config[CONF_DEVICE], self)
  File "/usr/local/lib/python3.8/site-packages/zigpy_zigate/api.py", line 94, in new
    await api.connect()
  File "/usr/local/lib/python3.8/site-packages/zigpy_zigate/api.py", line 100, in connect
    self._uart = await zigpy_zigate.uart.connect(self._config, self)
  File "/usr/local/lib/python3.8/site-packages/zigpy_zigate/uart.py", line 151, in connect
    _, protocol = await serial_asyncio.create_serial_connection(
  File "/usr/local/lib/python3.8/asyncio/coroutines.py", line 124, in coro
    res = func(*args, **kw)
  File "/usr/local/lib/python3.8/site-packages/serial_asyncio/__init__.py", line 410, in create_serial_connection
    ser = serial.serial_for_url(*args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/serial/__init__.py", line 88, in serial_for_url
    instance.open()
  File "/usr/local/lib/python3.8/site-packages/serial/serialposix.py", line 268, in open
    raise SerialException(msg.errno, "could not open port {}: {}".format(self._port, msg))
serial.serialutil.SerialException: [Errno 2] could not open port /config/pizigate:/dev/ttyAMA0: [Errno 2] No such file or directory: '/config/pizigate:/dev/ttyAMA0'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 236, in async_setup
    result = await component.async_setup_entry(hass, self)  # type: ignore
  File "/usr/src/homeassistant/homeassistant/components/zha/__init__.py", line 100, in async_setup_entry
    await zha_gateway.async_initialize()
  File "/usr/src/homeassistant/homeassistant/components/zha/core/gateway.py", line 147, in async_initialize
    self.application_controller = await app_controller_cls.new(
  File "/usr/local/lib/python3.8/site-packages/zigpy/application.py", line 71, in new
    await app.pre_shutdown()
  File "/usr/local/lib/python3.8/site-packages/zigpy/application.py", line 80, in pre_shutdown
    await self.shutdown()
  File "/usr/local/lib/python3.8/site-packages/zigpy_zigate/zigbee/application.py", line 63, in shutdown
    self._api.close()
AttributeError: 'NoneType' object has no attribute 'close'

Additional information

probot-home-assistant[bot] commented 3 years ago

Hey there @dmulcahey, @adminiuga, mind taking a look at this issue as its been labeled with an integration (zha) you are listed as a codeowner for? Thanks! (message by CodeOwnersMention)

Adminiuga commented 3 years ago

@doudz Apparently latest zigpy_zigate does not handle ports with pizigate:/dev/ttyAMA0 any more. I assume there are going to be some folks using it with pizigate:/dev/ttyAMA0 so zigpy-zigate either needs to maintain backwards compatibility or provide a migration for those use cases.

IMO in https://github.com/zigpy/zigpy-zigate/blob/a378a831ee22b86c15ceec2256059903c06f3a27/zigpy_zigate/uart.py#L143-L142 should first check if it is a pizigate and then try and do an absolute path???

doudz commented 3 years ago

I have removed that syntax but you're right we need to provide backward compatibility, I'll provide a fix soon

doudz commented 3 years ago

it has been fixed in zigpy-zigate v0.7.1

printzlau commented 3 years ago

Unfortunately, it does not seem to have fixed the problem. Version 0.118.0b2

Logger: homeassistant.components.zha.core.gateway
Source: components/zha/core/gateway.py:147
Integration: Zigbee Home Automation (documentation, issues)
First occurred: 12:03:11 AM (3 occurrences)
Last logged: 12:03:35 AM

Couldn't start ZiGate = ZiGate Zigbee radios: PiZiGate, ZiGate USB-TTL, ZiGate WiFi coordinator
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/serial/serialposix.py", line 265, in open
    self.fd = os.open(self.portstr, os.O_RDWR | os.O_NOCTTY | os.O_NONBLOCK)
FileNotFoundError: [Errno 2] No such file or directory: 'pizigate:/dev/ttyAMA0'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/zha/core/gateway.py", line 147, in async_initialize
    self.application_controller = await app_controller_cls.new(
  File "/usr/local/lib/python3.8/site-packages/zigpy/application.py", line 68, in new
    await app.startup(auto_form)
  File "/usr/local/lib/python3.8/site-packages/zigpy_zigate/zigbee/application.py", line 38, in startup
    self._api = await ZiGate.new(self._config[CONF_DEVICE], self)
  File "/usr/local/lib/python3.8/site-packages/zigpy_zigate/api.py", line 94, in new
    await api.connect()
  File "/usr/local/lib/python3.8/site-packages/zigpy_zigate/api.py", line 100, in connect
    self._uart = await zigpy_zigate.uart.connect(self._config, self)
  File "/usr/local/lib/python3.8/site-packages/zigpy_zigate/uart.py", line 149, in connect
    _, protocol = await serial_asyncio.create_serial_connection(
  File "/usr/local/lib/python3.8/asyncio/coroutines.py", line 124, in coro
    res = func(*args, **kw)
  File "/usr/local/lib/python3.8/site-packages/serial_asyncio/__init__.py", line 410, in create_serial_connection
    ser = serial.serial_for_url(*args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/serial/__init__.py", line 88, in serial_for_url
    instance.open()
  File "/usr/local/lib/python3.8/site-packages/serial/serialposix.py", line 268, in open
    raise SerialException(msg.errno, "could not open port {}: {}".format(self._port, msg))
serial.serialutil.SerialException: [Errno 2] could not open port pizigate:/dev/ttyAMA0: [Errno 2] No such file or directory: 'pizigate:/dev/ttyAMA0'

Is there a simple way to reconfigure my coordinator to workaround this issue?

Adminiuga commented 3 years ago

make back up of /config/.storage/core.config_entries and edit ZHA config entry, strip pizigate from the "path" value

                "data": {
                    "radio_type": "deconz",
                    "device": {
                        "path": "pizigate:/dev/ttyUSB.deconz"
                    }
                },
printzlau commented 3 years ago

Thank you. That did the trick.

doudz commented 3 years ago

Previous fix was incomplete, sorry for that it's now fixed in zigpy-zigate 0.7.2