Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when card is displayed before the sensor gets updated for the first time #46

Open
viktak opened this issue Mar 29, 2022 · 0 comments

Comments

@viktak
Copy link

viktak commented Mar 29, 2022

I created custom mqtt sensor which gets its data on a regular basis, i.e. every minute. If I visit the page with the list-card before the first update of the sensor, I get the following error in the HA logs:

Logger: frontend.js.latest.202203012
Source: components/system_log/__init__.py:190
First occurred: 10:28:10 AM (1 occurrences)
Last logged: 10:28:10 AM

http://192.168.1.111:8123/hacsfiles/list-card/list-card.js:92:71 TypeError: can't convert undefined to object

Once the sensor is updated this error doesn't happen.

This is my sensor:

- platform: mqtt
  name: hostnames
  state_topic: "viktak/network/dhcp"
  value_template: >
    {{ value_json.hosts | length }}
  json_attributes_topic: "viktak/network/dhcp"
  json_attributes_template: >-
      {{
        {
        'hosts' : value_json.hosts
        } | tojson        
      }}

This is my card:

  - type: custom:list-card
    entity: sensor.hostnames
    title: Hostnames
    feed_attribute: hosts
    columns:
      - title: Hostname
        field: field4
      - title: IP Address
        field: field3
      - title: MAC Address
        field: field2

This is a sample JSON arriving:

{"hosts":[
  {
    "field1": "1648590673",
    "field2": "00:24:8c:66:7f:54",
    "field3": "192.168.1.222",
    "field4": "test",
    "field5": "01:00:24:8c:66:7f:54"
  },
  {
    "field1": "1648586977",
    "field2": "5c:cf:7f:18:d6:94",
    "field3": "192.168.1.147",
    "field4": "officehall-18D694",
    "field5": "*"
  },
  {
    "field1": "1648585868",
    "field2": "5c:cf:7f:2b:b3:78",
    "field3": "192.168.1.105",
    "field4": "bedroomhall-2BB378",
    "field5": "*"
  }
]}

I think, the correct behavior should be no error message, just the card with the header, but no rows.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant