AlexandrErohin / home-assistant-flightradar24

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

Some issues with v1.20.2 #68

Open sheminasalam opened 2 weeks ago

sheminasalam commented 2 weeks ago

First of all, I really appreciate this addon. Was looking for such an addon for some time. I use node red to get notifications from the current area entity. It has been working fine till the latest version. In the latest version, I am getting the following type of outputs from the entities.

{{"payload":"1","data":{"entity_id":"sensor.flightradar24_current_in_area","old_state":{"entity_id":"sensor.flightradar24_current_in_area","state":"unknown","attributes":{"state_class":"total","icon":"mdi:airplane","friendly_name":"FlightRadar24 Current in area"},"last_changed":"2024-10-04T13:22:18.824787+00:00","last_reported":"2024-10-04T13:22:18.824787+00:00","last_updated":"2024-10-04T13:22:18.824787+00:00","context":{"id":"01J9BV42J8Y5AD36A7N5D57CNX","parent_id":null,"user_id":null}},"new_state":{"entity_id":"sensor.flightradar24_current_in_area","state":"1","attributes":{"state_class":"total","flights":{},"icon":"mdi:airplane","friendly_name":"FlightRadar24 Current in area"},"last_changed":"2024-10-04T13:22:29.403044+00:00","last_reported":"2024-10-04T13:22:29.403044+00:00","last_updated":"2024-10-04T13:22:29.403044+00:00","context":{"id":"01J9BV4CWVYQCK8A2BANC7QTFS","parent_id":null,"user_id":null},"timeSinceChangedMs":54}},"topic":"sensor.flightradar24_current_in_area","_msgid":"a08a1989bd60edce"}"}
{"payload":"0","data":{"entity_id":"sensor.flightradar24_current_in_area","old_state":{"entity_id":"sensor.flightradar24_current_in_area","state":"1","attributes":{"state_class":"total","flights":[{"id":"3763ec3a","flight_number":"3L248","callsign":"ADY248","aircraft_registration":"A6-AUK","aircraft_photo_small":"https://cdn.jetphotos.com/200/5/458619_1706285542_tb.jpg?v=0","aircraft_photo_medium":"https://cdn.jetphotos.com/400/5/458619_1706285542.jpg?v=0","aircraft_photo_large":"https://cdn.jetphotos.com/640cb/5/458619_1706285542.jpg?v=0","aircraft_model":"Airbus A320-214","aircraft_code":"A320","airline":"Air Arabia","airline_short":"Air Arabia","airline_iata":"G9","airline_icao":"ABY","airport_origin_name":"Abu Dhabi Zayed International Airport","airport_origin_code_iata":"AUH","airport_origin_code_icao":"OMAA","airport_origin_country_name":"United Arab Emirates","airport_origin_country_code":"AE","airport_origin_city":"Abu Dhabi","airport_destination_name":"Trivandrum International Airport","airport_destination_code_iata":"TRV","airport_destination_code_icao":"VOTV","airport_destination_country_name":"India","airport_destination_country_code":"IN","airport_destination_city":"Thiruvananthapuram","time_scheduled_departure":1728033300,"time_scheduled_arrival":1728048600,"time_real_departure":1728034613,"time_real_arrival":null,"time_estimated_departure":null,"time_estimated_arrival":1728048483,"latitude":8.5038,"longitude":77.0061,"altitude":3625,"heading":144,"ground_speed":251,"squawk":"","vertical_speed":-832,"distance":14.237107239688598}],"icon":"mdi:airplane","friendly_name":"FlightRadar24 Current in area"},"last_changed":"2024-10-04T13:22:29.403044+00:00","last_reported":"2024-10-04T13:23:19.492495+00:00","last_updated":"2024-10-04T13:23:19.492495+00:00","context":{"id":"01J9BV5XT4BEJ8JEM28TPRZEZA","parent_id":null,"user_id":null}},"new_state":{"entity_id":"sensor.flightradar24_current_in_area","state":"0","attributes":{"state_class":"total","flights":{},"icon":"mdi:airplane","friendly_name":"FlightRadar24 Current in area"},"last_changed":"2024-10-04T13:23:29.413345+00:00","last_reported":"2024-10-04T13:23:29.413345+00:00","last_updated":"2024-10-04T13:23:29.413345+00:00","context":{"id":"01J9BV67G5N97A6YFY6RJMSB41","parent_id":null,"user_id":null},"timeSinceChangedMs":55}},"topic":"sensor.flightradar24_current_in_area","_msgid":"5d50201f7aa26b9a"}

The main issue is that majority of the time when the payload is 1, there is no flight attributes. at times even when the payload is 0, there is flight attributes.

AlexandrErohin commented 2 weeks ago

It is because of this https://github.com/AlexandrErohin/home-assistant-flightradar24/blob/main/custom_components/flightradar24/sensor.py#L107 Sensor is updated twice - with empty flights and then with full data. Without the first empty update - HA doesnt update sensor if only some flight fields are updated (altitude, latitude/longitude, speed and ect.) and in flight info would be outdated parameters altitude, latitude/longitude ...