Skip to content

Commit

Permalink
add route details to the flights
Browse files Browse the repository at this point in the history
  • Loading branch information
vingerha committed May 31, 2024
1 parent 41b6a18 commit 0202993
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
22 changes: 20 additions & 2 deletions custom_components/adsb_lol/adsb_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
CONF_ENTITY_PICTURE,
CONF_ENTITY_PICTURE_ASC,
CONF_ENTITY_PICTURE_DESC,
CONF_ENTITY_PICTURE_HELI
CONF_ENTITY_PICTURE_HELI,
ATTR_DEFAULT_URL_ROUTE
)

_LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -44,6 +45,7 @@ def get_point_of_interest(self):
aircraft["latitude"] = ac.get("lat", None)
aircraft["longitude"] = ac.get("lon", None)
aircraft["category"] = ac.get("category", None)
aircraft["route"] = get_route(ac.get("flight", None))
aircraft[CONF_EXTRACT_TYPE] = self._CONF_EXTRACT_TYPE
aircraft[CONF_ENTITY_PICTURE] = self._CONF_ENTITY_PICTURE
aircraft[CONF_ENTITY_PICTURE_ASC] = self._CONF_ENTITY_PICTURE_ASC
Expand All @@ -64,4 +66,20 @@ def get_entity_pictures(hass, path) -> dict[str]:
for file in files:
entity_pictures.append(file)
_LOGGER.debug(f"Icons in folder: {entity_pictures}")
return entity_pictures
return entity_pictures

def get_route(callsign):
_url = ATTR_DEFAULT_URL_ROUTE
_callsign = callsign.strip()
_headers = {"accept": "application/json","Content-Type": "application/json"}
if callsign:
_data = '{"planes": [{"callsign": "' + _callsign + '","lat": 0,"lng": 0}]}'
response = requests.post(_url, headers = _headers, data = _data)
if response.status_code == 200:
_LOGGER.debug("Route details: %s", response.json())
return response.json()
return {}
else:
return {}


1 change: 1 addition & 0 deletions custom_components/adsb_lol/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
CONF_EXTRACT_TYPE = "extract_type"
CONF_URL = "url"
ATTR_DEFAULT_URL = "https://api.adsb.lol/v2"
ATTR_DEFAULT_URL_ROUTE = "https://api.adsb.lol/api/0/routeset"
CONF_EXTRACT_PARAM = "extract_param"
CONF_EXTRACT_PARAM_INPUT = "input_entity"

Expand Down
2 changes: 1 addition & 1 deletion custom_components/adsb_lol/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
"iot_class": "local_polling",
"issue_tracker": "https://github.com/vingerha/ha_adsb_lol/issues",
"requirements": [],
"version": "0.0.9"
"version": "0.1.0"
}

0 comments on commit 0202993

Please sign in to comment.