Skip to content

Commit

Permalink
Add option to use input_select/text as parameter for the flight
Browse files Browse the repository at this point in the history
fix bug with icao
  • Loading branch information
vingerha committed Mar 16, 2024
1 parent 9384fdd commit de174ea
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 10 deletions.
33 changes: 29 additions & 4 deletions custom_components/adsb_lol/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
CONF_URL,
CONF_EXTRACT_TYPE,
CONF_EXTRACT_PARAM,
CONF_EXTRACT_PARAM_INPUT,
ATTR_DEFAULT_URL,
CONF_EXTRACT_TYPE,
CONF_RADIUS,
Expand Down Expand Up @@ -52,7 +53,7 @@ async def async_step_user(self, user_input: dict | None = None) -> FlowResult:

return self.async_show_menu(
step_id="user",
menu_options=["flight_details","point_of_interest"],
menu_options=["flight_details","flight_details_input","point_of_interest"],
description_placeholders={
"model": "Example model",
}
Expand All @@ -66,7 +67,7 @@ async def async_step_flight_details(self, user_input: dict | None = None) -> Flo
step_id="flight_details",
data_schema=vol.Schema(
{
vol.Required(CONF_EXTRACT_TYPE): selector.SelectSelector(selector.SelectSelectorConfig(options=["registration", "callsign", "icao_hex"], translation_key="extract_type")),
vol.Required(CONF_EXTRACT_TYPE): selector.SelectSelector(selector.SelectSelectorConfig(options=["registration", "callsign", "icao"], translation_key="extract_type")),
vol.Required(CONF_EXTRACT_PARAM): str,
vol.Required(CONF_URL, default=ATTR_DEFAULT_URL): str,
vol.Required(CONF_NAME): str,
Expand All @@ -77,7 +78,30 @@ async def async_step_flight_details(self, user_input: dict | None = None) -> Flo
_LOGGER.debug(f"UserInputs Start End: {self._user_inputs}")
return self.async_create_entry(
title=user_input[CONF_NAME], data=self._user_inputs
)
)

async def async_step_flight_details_input(self, user_input: dict | None = None) -> FlowResult:
"""Handle the source."""
errors: dict[str, str] = {}
if user_input is None:
return self.async_show_form(
step_id="flight_details_input",
data_schema=vol.Schema(
{
vol.Required(CONF_EXTRACT_TYPE): selector.SelectSelector(selector.SelectSelectorConfig(options=["registration", "callsign", "icao"], translation_key="extract_type")),
vol.Required(CONF_EXTRACT_PARAM_INPUT): selector.EntitySelector(
selector.EntitySelectorConfig(domain=["input_text","input_select"]),
),
vol.Required(CONF_URL, default=ATTR_DEFAULT_URL): str,
vol.Required(CONF_NAME): str,
},
),
)
self._user_inputs.update(user_input)
_LOGGER.debug(f"UserInputs Start End: {self._user_inputs}")
return self.async_create_entry(
title=user_input[CONF_NAME], data=self._user_inputs
)

async def async_step_point_of_interest(self, user_input: dict | None = None) -> FlowResult:
"""Handle the source."""
Expand All @@ -100,9 +124,10 @@ async def async_step_point_of_interest(self, user_input: dict | None = None) ->
user_input[CONF_EXTRACT_TYPE] = "point"
self._user_inputs.update(user_input)
_LOGGER.debug(f"UserInputs Start End: {self._user_inputs}")

return self.async_create_entry(
title=user_input[CONF_NAME], data=self._user_inputs
)
)

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



Expand Down
11 changes: 9 additions & 2 deletions custom_components/adsb_lol/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,18 @@ async def _async_update_data(self) -> dict[str, str]:
_LOGGER.debug("Self data: %s", data)
options = self.config_entry.options

self._url = str(data["url"]) + "/" + str(data["extract_type"]) + "/" + str(data["extract_param"])
if data["input_entity"]:
extract_param = self.hass.states.get(data["input_entity"]).state
else:
extract_param = data["extract_param"]

self._url = str(data["url"]) + "/" + str(data["extract_type"]) + "/" + str(extract_param)

self._flight = await self.hass.async_add_executor_job(
get_flight, self
)
if self._flight["ac"]:

if self._flight.get("ac", None):
self._data = {
"registration": self._flight["ac"][0]["r"],
"callsign": self._flight["ac"][0]["flight"],
Expand All @@ -68,6 +74,7 @@ async def _async_update_data(self) -> dict[str, str]:
"longitude": self._flight["ac"][0]["lon"],
}
else:
_LOGGER.warning("No flights found for: %s", extract_param)
self._data = {
"registration": "Not found",
"callsign": "Not found",
Expand Down
47 changes: 43 additions & 4 deletions custom_components/adsb_lol/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"step": {
"user": {
"menu_options": {
"flight_details": "Search for flight details"
"flight_details": "Search for flight details",
"point_of_interest": "Search aircraft around a point of interest"
},
"description": "Select your choice "
},
Expand All @@ -12,10 +13,48 @@
"extract_type": "Find flight using:",
"url": "Select url",
"name": "Name",
"extract_param": "flight parameter (registration of callsign)"
"extract_param": "flight parameter (registration or callsign)"
},
"description": "Select"
}
},
"flight_details_input": {
"data": {
"extract_type": "Find flight using:",
"url": "Select url",
"name": "Name",
"extract_param": "Entity providing parameter (registration or callsign)"
},
"description": "Select"
},
"point_of_interest": {
"data": {
"point_of_interest": "Search flights around:",
"url": "Select url",
"name": "Name",
"radius": "Radius (km)",
"altitude_limit": "Only aircraft below altitude (km), leave 0 for all"
},
"description": "Seearch for aircraft around a chosen point of interest"
}
}
}
},
"options": {
"step": {
"init": {
"description": "Customize the way the integration works",
"data": {
"refresh_interval": "Data refresh interval (in minutes)"
}
}
}
},
"selector": {
"extract_type": {
"options": {
"registration": "Use the registration of the aircraft",
"callsign": "Use the callsign of the aircraft",
"icao_hex": "Use the icao2 (hex) of the aircraft"
}
}
}
}
10 changes: 10 additions & 0 deletions custom_components/adsb_lol/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"user": {
"menu_options": {
"flight_details": "Search for flight details",
"flight_details_input": "Search for flight details using an input select/text",
"point_of_interest": "Search aircraft around a point of interest"
},
"description": "Select your choice "
Expand All @@ -17,6 +18,15 @@
},
"description": "Select"
},
"flight_details_input": {
"data": {
"extract_type": "Find flight using:",
"url": "Select url",
"name": "Name",
"extract_param": "Entity providing parameter (registration or callsign)"
},
"description": "Select"
},
"point_of_interest": {
"data": {
"point_of_interest": "Search flights around:",
Expand Down

0 comments on commit de174ea

Please sign in to comment.