Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move from Nominatim details to Nominatim lookup #248

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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