Skip to content

Commit

Permalink
Move from Nominatim details to Nominatim lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
web-flow authored and Snuffy2 committed Nov 19, 2023
1 parent 95ca1e2 commit ff5902a
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions custom_components/places/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -850,6 +850,14 @@ def get_dict_from_url(self, url, name):
+ f"{name}: {get_dict.get('error_message')}"
)
return {}

if (
isinstance(get_dict, list)
and len(get_dict) == 1
and isinstance(get_dict[0], dict)
):
return get_dict[0]

return get_dict

def get_map_link(self):
Expand Down Expand Up @@ -1779,10 +1787,10 @@ def get_extended_attr(self):
osm_type_abbr = "R"

osm_details_url = (
"https://nominatim.openstreetmap.org/details.php?osmtype="
+ f"{osm_type_abbr}&osmid={self.get_attr(ATTR_OSM_ID)}"
+ "&linkedplaces=1&hierarchy=1&group_hierarchy=1&limit=1&format=json"
+ f"&email={self.get_attr(CONF_API_KEY) if self.is_attr_blank(CONF_API_KEY) else ''}"
"https://nominatim.openstreetmap.org/lookup?osm_ids="
+ f"{osm_type_abbr}{self.get_attr(ATTR_OSM_ID)}"
+ "&format=json&addressdetails=1&extratags=1&namedetails=1"
+ f"&email={self.get_attr(CONF_API_KEY) if not self.is_attr_blank(CONF_API_KEY) else ''}"
+ f"&accept-language={self.get_attr(CONF_LANGUAGE) if not self.is_attr_blank(CONF_LANGUAGE) else ''}"
)
self.set_attr(
Expand Down

0 comments on commit ff5902a

Please sign in to comment.