AlexandrErohin / home-assistant-flightradar24

Flightradar24 integration for Home Assistant
https://community.home-assistant.io/t/custom-component-flightradar24
MIT License
170 stars 16 forks source link

additional_tracked doesn't notify Lovelace #63

Closed gorynychzmey closed 1 month ago

gorynychzmey commented 1 month ago

It looks like the component doesn't notify Lovelace when the data was changed - the markup card doesn't update automatically and will only be updated if I reopen the tab (go to another tab and then back to tab with the markdown with the flight data). I could also stare minutes at the status in Development Tools and don't notify any changes (despite of update interval set to 10s).

AlexandrErohin commented 1 month ago

If there are no changes for tracked flights between sensor updates - there wont be any update in status Development Tools or Lovelace. Is there any error in Logs?

gorynychzmey commented 1 month ago

No, there are no any errors in log. The ongoing flights (which are live updated) must have changed at least their latitude and longitude, but I don't see it in Lovelace and Developer Tools.

AlexandrErohin commented 1 month ago

You may try to update to the latest version v1.20.1

gorynychzmey commented 1 month ago

I've tried with v1.20.1 - nothing changed.

AlexandrErohin commented 1 month ago

If data in Lovelace updates only when you reopen the tab - it means you have problem with frontend data updates.The integration does not interact with frontend

gorynychzmey commented 1 month ago

I don't know very well how the state machine works but I suppose that component somehow partially notifies Home Assistant about it have changed its state (or, to be precise, not the state itself but the attributes). At least states.sensor.flightradar24_additional_tracked.last_updated seems to be changing only when a flight is added or removed, but documentations says that last_updated reflects changes in the state and in the attributes.

AlexandrErohin commented 1 month ago

So said that - Lovelace updates only when you refresh the page or reopen the tab. It means that frontend doesnt get updates.

gorynychzmey commented 1 month ago

The frontend don't get updates from only this component - all other sensors are updated correctly. You could check it yourself by adding latitude, longitude and last_updated to markdown card:

content: >-
  {% set data = state_attr('sensor.flightradar24_additional_tracked', 'flights')
  %} {% for flight in data %}
    <img src="https://content.airhex.com/content/logos/airlines_{{flight.airline_icao}}_20_20_f.png?proportions=keep">{{ flight.flight_number }} - {{ flight.airline_short }} - {{ flight.aircraft_model }}
    {{ flight.airport_origin_city }}{%if flight.airport_origin_city %}<img src="https://flagsapi.com/{{ flight.airport_origin_country_code }}/shiny/16.png" title='{{ flight.airport_origin_country_name }}'/>{% endif %} -> {{ flight.airport_destination_city }}{%
    if flight.airport_destination_country_code %}<img src="https://flagsapi.com/{{ flight.airport_destination_country_code }}/shiny/16.png" title='{{ flight.airport_destination_country_name }}'/>{% endif %}
    Scheduled: {%if flight.time_scheduled_departure %}Departure - {{ flight.time_scheduled_departure | timestamp_custom('%H:%M') }}; {% endif %}{%if flight.time_scheduled_arrival%}Arrival - {{ flight.time_scheduled_arrival | timestamp_custom('%H:%M') }}{% endif %}
    Estimated: {%if flight.time_estimated_departure %}Departure - {{ flight.time_estimated_departure | timestamp_custom('%H:%M') }}; {% endif %}{%if flight.time_estimated_arrival%}Arrival - {{ flight.time_estimated_arrival | timestamp_custom('%H:%M') }}{% endif %}  
    Altitude - {{ flight.altitude }} ft{%if flight.altitude > 0 %} ({{(flight.altitude * 0.3048)| round(0)}} m){% endif%}; Gr. speed - {{ flight.ground_speed }} kts{%if flight.ground_speed > 0 %} ({{(flight.ground_speed * 1.852)| round(0)}} km/h){% endif%}
    Lat: {{ flight.latitude }}, lon: {{ flight.longitude }}
    [Open FlightRadar](https://www.flightradar24.com/{{ flight.callsign }}/{{flight.id }})        
  {% endfor %} {{ states.sensor.flightradar24_additional_tracked.last_updated }}

Then add some flight to tracked and look if it will be updated as expected.

AlexandrErohin commented 1 month ago

@gorynychzmey I have succeeded to reproduce it and I have fixed it. Please try version v1.20.2

gorynychzmey commented 1 month ago

Now it updates as expected.

AlexandrErohin commented 1 month ago

@gorynychzmey Dont forget please to give a star to the repo :)