here_travel_time: Add unique_id and DeviceInfo (#72352)

Co-authored-by: Franck Nijhof <frenck@frenck.nl>
This commit is contained in:
Kevin Stillhammer 2022-05-23 10:47:40 +02:00 committed by GitHub
parent bc6451bd64
commit 793ad568eb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -19,6 +19,8 @@ from homeassistant.const import (
) )
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.device_registry import DeviceEntryType
from homeassistant.helpers.entity import DeviceInfo
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.start import async_at_start from homeassistant.helpers.start import async_at_start
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
@ -144,6 +146,7 @@ async def async_setup_entry(
async_add_entities( async_add_entities(
[ [
HERETravelTimeSensor( HERETravelTimeSensor(
config_entry.entry_id,
config_entry.data[CONF_NAME], config_entry.data[CONF_NAME],
config_entry.options[CONF_TRAFFIC_MODE], config_entry.options[CONF_TRAFFIC_MODE],
hass.data[DOMAIN][config_entry.entry_id], hass.data[DOMAIN][config_entry.entry_id],
@ -157,6 +160,7 @@ class HERETravelTimeSensor(SensorEntity, CoordinatorEntity):
def __init__( def __init__(
self, self,
unique_id_prefix: str,
name: str, name: str,
traffic_mode: str, traffic_mode: str,
coordinator: HereTravelTimeDataUpdateCoordinator, coordinator: HereTravelTimeDataUpdateCoordinator,
@ -166,6 +170,13 @@ class HERETravelTimeSensor(SensorEntity, CoordinatorEntity):
self._traffic_mode = traffic_mode == TRAFFIC_MODE_ENABLED self._traffic_mode = traffic_mode == TRAFFIC_MODE_ENABLED
self._attr_native_unit_of_measurement = TIME_MINUTES self._attr_native_unit_of_measurement = TIME_MINUTES
self._attr_name = name self._attr_name = name
self._attr_unique_id = unique_id_prefix
self._attr_device_info = DeviceInfo(
identifiers={(DOMAIN, unique_id_prefix)},
entry_type=DeviceEntryType.SERVICE,
name=name,
manufacturer="HERE Technologies",
)
async def async_added_to_hass(self) -> None: async def async_added_to_hass(self) -> None:
"""Wait for start so origin and destination entities can be resolved.""" """Wait for start so origin and destination entities can be resolved."""