Add entity translations to HERE Travel time (#95412)

This commit is contained in:
Joost Lekkerkerker 2023-06-27 23:35:12 +02:00 committed by GitHub
parent 4e05205174
commit aaa4ee79b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 6 deletions

View File

@ -52,21 +52,21 @@ def sensor_descriptions(travel_mode: str) -> tuple[SensorEntityDescription, ...]
"""Construct SensorEntityDescriptions."""
return (
SensorEntityDescription(
name="Duration",
translation_key="duration",
icon=ICONS.get(travel_mode, ICON_CAR),
key=ATTR_DURATION,
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=UnitOfTime.MINUTES,
),
SensorEntityDescription(
name="Duration in traffic",
translation_key="duration_in_traffic",
icon=ICONS.get(travel_mode, ICON_CAR),
key=ATTR_DURATION_IN_TRAFFIC,
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=UnitOfTime.MINUTES,
),
SensorEntityDescription(
name="Distance",
translation_key="distance",
icon=ICONS.get(travel_mode, ICON_CAR),
key=ATTR_DISTANCE,
state_class=SensorStateClass.MEASUREMENT,
@ -110,6 +110,8 @@ class HERETravelTimeSensor(
):
"""Representation of a HERE travel time sensor."""
_attr_has_entity_name = True
def __init__(
self,
unique_id_prefix: str,
@ -128,7 +130,6 @@ class HERETravelTimeSensor(
name=name,
manufacturer="HERE Technologies",
)
self._attr_has_entity_name = True
async def _async_restore_state(self) -> None:
"""Restore state."""
@ -174,7 +175,7 @@ class OriginSensor(HERETravelTimeSensor):
) -> None:
"""Initialize the sensor."""
sensor_description = SensorEntityDescription(
name="Origin",
translation_key="origin",
icon="mdi:store-marker",
key=ATTR_ORIGIN_NAME,
)
@ -202,7 +203,7 @@ class DestinationSensor(HERETravelTimeSensor):
) -> None:
"""Initialize the sensor."""
sensor_description = SensorEntityDescription(
name="Destination",
translation_key="destination",
icon="mdi:store-marker",
key=ATTR_DESTINATION_NAME,
)

View File

@ -85,5 +85,24 @@
}
}
}
},
"entity": {
"sensor": {
"duration": {
"name": "Duration"
},
"duration_in_traffic": {
"name": "Duration in traffic"
},
"distance": {
"name": "Distance"
},
"origin": {
"name": "Origin"
},
"destination": {
"name": "Destination"
}
}
}
}