nathan-gs / ha-map-card

A Map Card for Home Assistant
https://community.home-assistant.io/t/map-card-a-slightly-improved-map-card/693088
MIT License
33 stars 11 forks source link

Unavailable device_tracker causes map to not draw anything #91

Open realzoulou opened 1 week ago

realzoulou commented 1 week ago

Issue description: When device_tracker has state Unavailable, no map is drawn at all

Expected: Map is drawn still but without the unavailable device_trackers (same behavior as with the HA included Map Card)

Symptom: ha-map-card shows "Error found in first run. check Console" Console highlights map-card.js line https://github.com/nathan-gs/ha-map-card/blob/1cd63018e7a8723f6da54b29b62505471a033915/src/components/MapCard.js#L240

238     // Get lat lng
239      let latLng = HaMapUtilities.getEntityLatLng(configEntity.id, hass.states);
240      const latitude = latLng[0] ?? null;
241      const longitude = latLng[1] ?? null;

map card configuration:

type: custom:map-card
title: Location history 24h
card_size: 6
zoom: 19
x: "11.000000"
"y": "48.000000"
tile_layer_url: >-
  https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}
tile_layer_attribution: >-
  Tiles © Esri — Source: Esri, i-cubed, USDA, USGS, AEX, GeoEye,
  Getmapping, Aerogrid, IGN, IGP, UPR-EGP, and the GIS User Community
tile_layer_options:
  maxZoom: 19
  referrerPolicy: strict-origin-when-cross-origin
theme_mode: light
entities:
  - entity: device_tracker.uwb_anchor_a1
    display: marker
    size: 16
    color: grey
    z_index_offset: 0
  - entity: device_tracker.uwb_anchor_a3
    display: marker
    size: 16
    color: grey
    z_index_offset: 0
  - entity: device_tracker.uwb_anchor_a4
    display: marker
    size: 16
    color: grey
    z_index_offset: 0
  - entity: device_tracker.uwb_tag
    history_start: 1 hours ago
    focus_on_fit: false
    display: marker
    size: 20
    color: green
    z_index_offset: 40
    fallback_x: "11.00000"
    fallback_y: "48.00000"

image

nathan-gs commented 13 hours ago

@realzoulou what behavior would you prefer? Ignore items without lat/long? The current idea is to give a quick error.

ildar170975 commented 12 hours ago

@nathan-gs Imho the card should post a message in console & show available entities. If none of them can be shown -> show a home position.

Use case: Assume there are meteorological data (temperature, pressure) provided by some integrations; and sensors have latitude/longitude. Then I would add on a card zone.my_castle & sensors with meteo data in this region. Due to some reasons, this meteo integration does not create a sensor (or it becomes unavailable) -> a card does not show available data (or at least my castle).

realzoulou commented 12 hours ago

@nathan-gs I would not necessarily need to see any error message indicating a sensor is not available. But agree with @ildar170975 that for some use cases it would be beneficial to get some sort of indication about why the card is not showing expected data.

ildar170975 commented 12 hours ago

I would choose a "log a message to console" - but a user (esp. a beginner) may not notice it if a Code inspector (or whatever it is called in a particular browser) is not shown. Another way could be displaying an error badge on a map - here is a poor mockup made in MS Paint: image with a tooltip like "Some errors, check browser's console for details".