dermotduffy / frigate-hass-card

A Lovelace card for Frigate in Home Assistant
MIT License
553 stars 59 forks source link

Entity registry parse error in `v4.1.0` codebase #1016

Closed neuhausf closed 1 year ago

neuhausf commented 1 year ago
image

Card 4.0.0-beta4, Frigate Integration 4.1.0 and Frigate 0.12.0-beta10 with HA 2023.3.5

Javascript errors shown in the web inspector (if applicable):

Received invalid response from Home Assistant for request. Check troubleshooting.
{
  "request": {
    "type": "config/entity_registry/list",
    "id": 92
  },
  "response": [
... // entities omitted due to privacy... do you need these?
      {
      "area_id": null,
      "config_entry_id": "e8387fceedabdbde1d6c46b210c28f80",
      "device_id": "d3f7922f40dbde89970c704bfb720bf4",
      "disabled_by": null,
      "entity_category": "diagnostic",
      "entity_id": "update.frigate_server",
      "has_entity_name": true,
      "hidden_by": null,
      "icon": null,
      "id": "5c0d193cc663093aad9acfc90aa745b1",
      "name": null,
      "options": {},
      "original_name": "Server",
      "platform": "frigate",
      "translation_key": null,
      "unique_id": "e8387fceedabdbde1d6c46b210c28f80:update:frigate_server"
    }
  ],
  "invalid_keys": [
    "311"
  ]
}

Any hints? Which key "311" does the error refer to?

dermotduffy commented 1 year ago

Hmm. Have not seen this before. At first I thought it might be a change made on the HA side since you're running a newer HA instance than I've been testing with, but if I change to exactly HA 2023.3.5 with the stock release v4 card, I still cannot reproduce this. I do not know what "311" refers to. I can only assume there is something in your entity registry list that is (1) valid as per HA, but (2) invalid as to what the card expects.

In your HA config directory, take a look at /config/.storage/core.entity_registry file and see if you can find something with 311 in it? (Take care not to write or modify this file)

neuhausf commented 1 year ago

I'm trying to narrow the problem a bit down. With this version, it still works: https://github.com/dermotduffy/frigate-hass-card/actions/runs/4332693383

dermotduffy commented 1 year ago

That's the new v4.1.0 branch that is significantly different from the currently released v4 branch. Have you tried the head of the v4.1.0 branch? Does that work?

PS: Don't suppose you use openweathermap? That's the only reference to 311 in the HA codebase I could find ;-)

neuhausf commented 1 year ago

No openweathermap in use :) Only MeteoSwiss and AccuWeather.

Here is everything with 311 in my entity_registry:

image

Problem exists when using HEAD of 4.1.0

  1. uninstalled the hass-card from HASS
  2. used the artifact from https://github.com/dermotduffy/frigate-hass-card/actions/runs/4457645893
  3. referenced it with /local/custom/frigate-hass-card-custom/frigate-hass-card.js?cache=9

-> the other versions should be up to date too (see first post)

dermotduffy commented 1 year ago

Thanks, registry looks fine. I wonder if the error you are seeing is getting mangled somehow.

Are you getting anything interesting in your Javascript console?

So it seems like the issue is somewhere, on the v4.1.0 branch between #1741 and #1749. Maybe binary search a little and see if you can narrow it down to a smaller range? Be very sure to clear your cache after changing JS as the browser may aggressively cache otherwise.

neuhausf commented 1 year ago

I guess I found the commit: https://github.com/dermotduffy/frigate-hass-card/actions/runs/4332809782

dermotduffy commented 1 year ago

Weird. That should strictly result in fewer calls to HA, rather than more calls.

neuhausf commented 1 year ago

Javascript console: I think there is the same info, as in the card error itself + an error about media_player.radio not found. I removed the media_player entity, but the error is still the same.

image

About diagnostics: I don't get a diagnostics window in the errourness version.

I just reverted to https://github.com/dermotduffy/frigate-hass-card/actions/runs/4332693383 and it works again. Here I get diagnostics:

Card diagnostics. Please review for confidential information prior to sharing
{
  "ha_version": "2023.3.5",
  "card_version": "4.0.0",
  "browser": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36",
  "date": "2023-03-19T16:08:51.272Z",
  "frigate_version": {
    "b432101987bd7fbaa1198c9e722a7c26": "4.0.0-beta4/0.12.0-e454daf"
  },
  "lang": "en",
  "timezone": "Europe/Zurich",
  "git": {
    "build_version": "4.0.0-HEAD+g8333464",
    "build_date": "Sat, 04 Mar 2023 20:22:45 GMT",
    "commit_date": "Sat, 4 Mar 2023 12:21:16 -0800"
  },
  "config": {
    "type": "custom:frigate-card",
    "cameras": [
      {
        "camera_entity": "camera.camera_tuer",
        "live_provider": "go2rtc",
        "webrtc_card": {
          "url": "rtsp://192.168.1.137:8554/camera_tuer"
        }
      },
      {
        "camera_entity": "camera.camera_carport",
        "live_provider": "go2rtc",
        "webrtc_card": {
          "url": "rtsp://192.168.1.137:8554/camera_carport"
        }
      }
    ]
  }
}
neuhausf commented 1 year ago

If I see this correctly, this commit has no build artifact: https://github.com/dermotduffy/frigate-hass-card/commit/9870446a9f2869d0370795162dfa7b247261fab2 -> so maybe the change in src/types.ts could be a problem? or a caching issue?

dermotduffy commented 1 year ago

I think you have at least two issues here (one is something wrong with the parsing of the registry entities, the second is something with a specific media_player).

Can you comment on media_player.radio? What is it and why is it not in the entity registry? (Perhaps this is something manually configured?).

dermotduffy commented 1 year ago

Ah, I think the 311 is obvious in retrospect: can you show me the 311th entry in the response is? You can drill down in the response in the Javascript console, then paste in here what 311th entry is ...

Screenshot from 2023-03-19 10-17-16

neuhausf commented 1 year ago

As I don't know if its 0 based, 310 is also included:

image
neuhausf commented 1 year ago

By the way: I commented out the media_player in configuration.yaml and this error is gone. But the other error still occurs.

neuhausf commented 1 year ago

Here is the full error including all entities: https://gist.github.com/neuhausf/dc1f9561b1e08672f75470a959932cf1

dermotduffy commented 1 year ago

OK -- I think the issue is the unique_id field for the 311th entry is a number, and not a string as the card is expecting. It really should be a string as per the HA expectations:

https://github.com/home-assistant/core/blob/dev/homeassistant/helpers/entity_registry.py#L119

... so this might be feedback to the developers of the "nuki" platform that they are using malformed unique_id in their entity. However, I think the card can also be more tolerant here -- it should not care.

As for the media_player.radio, can you clarify what that entity is? I think I probably also need to harden this logic, but want to know what entity type that is first.

neuhausf commented 1 year ago

Hm, the unique_id is from the Nuki integration. Any chance to change this?

image

As for the media_player: It's from the frontier-silicon platform. I use it like this:

media_player:
  - platform: frontier_silicon
    host: 192.168.1.152
    name: Radio
dermotduffy commented 1 year ago

Hm, the unique_id is from the Nuki integration. Any chance to change this?

You could always shut down your HA instance, modify the entity registry file by hand, and change it to a string. That could very likely break that integration though, since it will be expecting a number. The real fix is (1) for the integration authors to not use a number, and (2) for the card to not care either way!

(2) will be an easy fix for me I suspect, so I wouldn't worry about it, and just give me a few days to get a fix together.

Thanks for the info on the media_player. I'll also fix that.

neuhausf commented 1 year ago

I tried to change the unique_id. Nuki still started, but added a duplicate entry with the wrong formatted ID again. Iā€˜m gonna inform the maintainer. So your fix is very welcome! Thanks a lot for taking the time to track this down! Have a great week šŸ˜ƒ

dermotduffy commented 1 year ago

@neuhausf Try this build artifact and hopefully both of your issues are resolved: https://github.com/dermotduffy/frigate-hass-card/actions/runs/4462902003

neuhausf commented 1 year ago

You are correct: This build fixes both issues - no more errors in Chrome console. Thank you very much for providing a fault-tolerant solution šŸ˜‰ ! P.S. The diagnostics menu seems to be broken in this build?

image
jahegu commented 1 year ago

I do also have the same problem

dermotduffy commented 1 year ago

@jahegu This issue is closed. Please open a new issue with debug information if you'd like assistance. Thanks!