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
69.03k stars 28.28k forks source link

SkyConnect Integration - Startup Error but SkyConnect works just fine. #116823

Open tommyjlong opened 1 week ago

tommyjlong commented 1 week ago

The problem

SkyConnect Integration throws a log error at startup (See below), but nevertheless SkyConnect w. OTBR AddOn works just fine.

Have been using SkyConnect with OTBR AddOn for several releases, and don't recall ever seeing this error until migrating to 2024.5. ZHA integration is an ignored integration in my system thus not being used so there is no need for a migration.

What version of Home Assistant Core has the issue?

core-2024.5.1

What was the last working version of Home Assistant Core?

core-2024.4.3

What type of installation are you running?

Home Assistant OS

Integration causing the issue

homeassistant_sky_connect

Link to integration documentation on our website

No response

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

Migrating from version 1:1
Error migrating entry Home Assistant SkyConnect for homeassistant_sky_connect
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 880, in async_migrate
    result = await component.async_migrate_entry(hass, self)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/homeassistant_sky_connect/__init__.py", line 37, in async_migrate_entry
    firmware_guess = await guess_firmware_type(
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/homeassistant_sky_connect/util.py", line 96, in guess_firmware_type
    zha_path = get_zha_device_path(zha_config_entry)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/homeassistant_sky_connect/util.py", line 55, in get_zha_device_path
    return cast(str, config_entry.data["device"]["path"])
                     ~~~~~~~~~~~~~~~~~^^^^^^^^^^
KeyError: 'device'

Additional information

There is a separate but related error also thrown by the SkyConnect Integration:

ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [140246252137664] Error handling message: Unknown error (unknown_error) User-blah from IP-address-blah (Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36)
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/decorators.py", line 27, in _handle_async_response
    await func(hass, connection, msg)
  File "/usr/src/homeassistant/homeassistant/components/hardware/websocket_api.py", line 65, in ws_info
    hardware_info.extend([asdict(hw) for hw in platform.async_info(hass)])
                                               ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/homeassistant_sky_connect/hardware.py", line 28, in async_info
    description=entry.data["product"],
                ~~~~~~~~~~^^^^^^^^^^^
KeyError: 'product'
home-assistant[bot] commented 1 week ago

Hey there @home-assistant/core, mind taking a look at this issue as it has been labeled with an integration (homeassistant_sky_connect) you are listed as a code owner for? Thanks!

Code owner commands Code owners of `homeassistant_sky_connect` can trigger bot actions by commenting: - `@home-assistant close` Closes the issue. - `@home-assistant rename Awesome new title` Renames the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign homeassistant_sky_connect` Removes the current integration label and assignees on the issue, add the integration domain after the command. - `@home-assistant add-label needs-more-information` Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue. - `@home-assistant remove-label needs-more-information` Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


homeassistant_sky_connect documentation homeassistant_sky_connect source (message by IssueLinks)

tommyjlong commented 1 week ago

Just to add a little more info, here is dmesg:

[    1.360348] usb 2-1: new full-speed USB device number 2 using uhci_hcd
[    1.519622] usb 2-1: New USB device found, idVendor=10c4, idProduct=ea60, bcdDevice= 1.00
[    1.521288] usb 2-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[    1.522784] usb 2-1: Product: SkyConnect v1.0
[    1.524331] usb 2-1: Manufacturer: Nabu Casa
[    1.525810] usb 2-1: SerialNumber: 2ebablahblahblah580b

And here is the output from UI->System->Hardware->ttyUSB0

Subsystem:
tty
Device path:
/dev/ttyUSB0
ID:
/dev/serial/by-id/usb-Nabu_Casa_SkyConnect_v1.0_2ebablahblah580b-if00-port0
Attributes:
DEVLINKS: >-
  /dev/serial/by-id/usb-Nabu_Casa_SkyConnect_v1.0_2ebablahblahblah580b-if00-port0
  /dev/serial/by-path/pci-0000:00:05.0-usb-0:1:1.0-port0
  /dev/serial/by-path/pci-0000:00:05.0-usbv1-0:1:1.0-port0
DEVNAME: /dev/ttyUSB0
DEVPATH: /devices/pci0000:00/0000:00:05.0/usb2/2-1/2-1:1.0/ttyUSB0/tty/ttyUSB0
ID_BUS: usb
ID_MODEL: SkyConnect_v1.0
ID_MODEL_ENC: SkyConnect\x20v1.0
ID_MODEL_ID: ea60
ID_PATH: pci-0000:00:05.0-usb-0:1:1.0
ID_PATH_TAG: pci-0000_00_05_0-usb-0_1_1_0
ID_PATH_WITH_USB_REVISION: pci-0000:00:05.0-usbv1-0:1:1.0
ID_REVISION: '0100'
ID_SERIAL: Nabu_Casa_SkyConnect_v1.0_2ebablahblahblah580b
ID_SERIAL_SHORT: 2ebablahblahblah580b
ID_TYPE: generic
ID_USB_DRIVER: cp210x
ID_USB_INTERFACES: ':ff0000:'
ID_USB_INTERFACE_NUM: '00'
ID_USB_MODEL: SkyConnect_v1.0
ID_USB_MODEL_ENC: SkyConnect\x20v1.0
ID_USB_MODEL_ID: ea60
ID_USB_REVISION: '0100'
ID_USB_SERIAL: Nabu_Casa_SkyConnect_v1.0_2eba2b499514ed11a6d5b68be054580b
ID_USB_SERIAL_SHORT: 2eba2b499514ed11a6d5b68be054580b
ID_USB_TYPE: generic
ID_USB_VENDOR: Nabu_Casa
ID_USB_VENDOR_ENC: Nabu\x20Casa
ID_USB_VENDOR_ID: 10c4
ID_VENDOR: Nabu_Casa
ID_VENDOR_ENC: Nabu\x20Casa
ID_VENDOR_ID: 10c4
MAJOR: '188'
MINOR: '0'
SUBSYSTEM: tty
TAGS: ':systemd:'
USEC_INITIALIZED: '4245083'
tommyjlong commented 19 hours ago

Hi @emontnemery, I apologize if you are not the correct person, but do you mind taking a look at this issue? It looks like there is some problem migrating the config, and there were some recent changes made in this area of the code. Best Regards.

tommyjlong commented 3 hours ago

To add some more information, I do not use ZHA, only OTBR (however I started with Multiprotocol and later migrated to OTBR) with SkyConnect.

Also, here is the .storage/core.config_entries for my Sky Connect:

     {
        "entry_id": "d3c3bdc96c9dabda28e031ba447249c5",
        "version": 1,
        "minor_version": 1,
        "domain": "homeassistant_sky_connect",
        "title": "Home Assistant SkyConnect",
        "data": {
          "device": "/dev/serial/by-id/usb-Nabu_Casa_SkyConnect_v1.0_2eba2b499514ed11a6d5b68be054580b-if00-port0",
          "vid": "10C4",
          "pid": "EA60",
          "serial_number": "2eba2b499514ed11a6d5b68be054580b",
          "manufacturer": "Nabu Casa",
          "description": "SkyConnect v1.0"
        },
        "options": {},
        "pref_disable_new_entities": false,
        "pref_disable_polling": false,
        "source": "usb",
        "unique_id": "10C4:EA60_2eba2b499514ed11a6d5b68be054580b_Nabu Casa_SkyConnect v1.0",
        "disabled_by": null
      }

I did however find this config entry for zha:

      {
        "entry_id": "617ed0e3256b186aa6c5573e046e486b",
        "version": 3,
        "minor_version": 1,
        "domain": "zha",
        "title": "SkyConnect Multiprotocol",
        "data": {
          "device": {
            "path": "socket://core-silabs-multiprotocol:9999"
          }
        },
        "options": {},
        "pref_disable_new_entities": false,
        "pref_disable_polling": false,
        "source": "ignore",
        "unique_id": "SkyConnect Multiprotocol_ezsp_socket://core-silabs-multiprotocol:9999",
        "disabled_by": null
      },

Oh wow, here is another one I found for zha (could this be the problem?):

      {
        "entry_id": "6a0bffe50725640d222588b65e7817dd",
        "version": 3,
        "minor_version": 1,
        "domain": "zha",
        "title": "Sonoff Zigbee 3.0 USB Dongle Plus",
        "data": {},
        "options": {},
        "pref_disable_new_entities": false,
        "pref_disable_polling": false,
        "source": "ignore",
        "unique_id": "10C4:EA60_de59715f6345ed11ad29cf8f0a86e0b4_ITead_Sonoff Zigbee 3.0 USB Dongle Plus",
        "disabled_by": null
      },
home-assistant[bot] commented 2 hours ago

Hey there @dmulcahey, @adminiuga, @puddly, @thejulianjes, mind taking a look at this issue as it has been labeled with an integration (zha) you are listed as a code owner for? Thanks!

Code owner commands Code owners of `zha` can trigger bot actions by commenting: - `@home-assistant close` Closes the issue. - `@home-assistant rename Awesome new title` Renames the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign zha` Removes the current integration label and assignees on the issue, add the integration domain after the command. - `@home-assistant add-label needs-more-information` Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue. - `@home-assistant remove-label needs-more-information` Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


zha documentation zha source (message by IssueLinks)

puddly commented 1 hour ago

The SkyConnect integration itself won't interact with ZHA. It's sort of self contained. Your config entry seems to have a device key. I'll see if I can replicate this.

tommyjlong commented 50 minutes ago

Kinda glancing through the code for skyconnect integration:

__init__.py:

async def async_migrate_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool:
    """Migrate old entry."""
   ....

    if config_entry.version == 1:
        if config_entry.minor_version == 1:

            firmware_guess = await guess_firmware_type(   <== this part
                hass, config_entry.data["device"]
            )

util.py:

async def guess_firmware_type(hass: HomeAssistant, device_path: str) -> FirmwareGuess:
    """Guess the firmware type based on installed addons and other integrations."""
    device_guesses: defaultdict[str | None, list[FirmwareGuess]] = defaultdict(list)

    for zha_config_entry in hass.config_entries.async_entries(ZHA_DOMAIN):  <== This part
        zha_path = get_zha_device_path(zha_config_entry)                                 <== This part
        device_guesses[zha_path].append(
            FirmwareGuess(
                is_running=(zha_config_entry.state == ConfigEntryState.LOADED),
                firmware_type=ApplicationType.EZSP,
                source="zha",
            )
        )

Looks like it is going through ZHA domain looking for all the ZHA config entries, and for each it calls:

def get_zha_device_path(config_entry: ConfigEntry) -> str:
    """Get the device path from a ZHA config entry."""
    return cast(str, config_entry.data["device"]["path"])  

So I think its hitting that zha config entry I showed earlier with empty data (Sonoff Zigbee 3.0 USB Dongle Plus), and this is probably what's causing the failure. Would it be as simple as hand editing the core.config_entries and removing the zha config entry for the Sonoff Zigbee 3.0 USB Dongle Plus, and restarting core?