Skip to content

Commit

Permalink
Merge pull request #248 from Snuffy2/Move-from-Nominatim-details-to-N…
Browse files Browse the repository at this point in the history
…ominatim-lookup

Move from Nominatim details to Nominatim lookup
  • Loading branch information
Snuffy2 committed Nov 20, 2023
2 parents 95ca1e2 + ff5902a commit e9cced8
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 e9cced8

Please sign in to comment.