Handle GeoJSON int to str conversion when the name is an int (#108937)

Co-authored-by: Chris Roberts <NasaGeek@users.noreply.github.com>
pull/109460/head^2
Cody C 2024-02-05 09:26:05 +13:00 committed by GitHub
parent 7cc0b8a2fe
commit 770119c8ad
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 5 deletions

View File

@ -105,7 +105,8 @@ class GeoJsonLocationEvent(GeolocationEvent):
def _update_from_feed(self, feed_entry: GenericFeedEntry) -> None:
"""Update the internal state from the provided feed entry."""
if feed_entry.properties and "name" in feed_entry.properties:
self._attr_name = feed_entry.properties.get("name")
# The entry name's type can vary, but our own name must be a string
self._attr_name = str(feed_entry.properties["name"])
else:
self._attr_name = feed_entry.title
self._attr_distance = feed_entry.distance_to_home

View File

@ -58,7 +58,9 @@ async def test_entity_lifecycle(
(-31.0, 150.0),
{ATTR_NAME: "Properties 1"},
)
mock_entry_2 = _generate_mock_feed_entry("2345", "Title 2", 20.5, (-31.1, 150.1))
mock_entry_2 = _generate_mock_feed_entry(
"2345", "271310188", 20.5, (-31.1, 150.1), {ATTR_NAME: 271310188}
)
mock_entry_3 = _generate_mock_feed_entry("3456", "Title 3", 25.5, (-31.2, 150.2))
mock_entry_4 = _generate_mock_feed_entry("4567", "Title 4", 12.5, (-31.3, 150.3))
@ -89,14 +91,14 @@ async def test_entity_lifecycle(
}
assert round(abs(float(state.state) - 15.5), 7) == 0
state = hass.states.get(f"{GEO_LOCATION_DOMAIN}.title_2")
state = hass.states.get(f"{GEO_LOCATION_DOMAIN}.271310188")
assert state is not None
assert state.name == "Title 2"
assert state.name == "271310188"
assert state.attributes == {
ATTR_EXTERNAL_ID: "2345",
ATTR_LATITUDE: -31.1,
ATTR_LONGITUDE: 150.1,
ATTR_FRIENDLY_NAME: "Title 2",
ATTR_FRIENDLY_NAME: "271310188",
ATTR_UNIT_OF_MEASUREMENT: UnitOfLength.KILOMETERS,
ATTR_SOURCE: "geo_json_events",
}