1010 ScannerEntity ,
1111)
1212from homeassistant .core import HomeAssistant
13+ from homeassistant .helpers import device_registry as dr
1314from homeassistant .helpers .entity_platform import AddConfigEntryEntitiesCallback
1415from homeassistant .helpers .update_coordinator import CoordinatorEntity
1516from homeassistant .util import dt as dt_util
1617
17- from .const import CONF_IMPORTED_BY
18+ from .const import CONF_IMPORTED_BY , DOMAIN
1819from .coordinator import PingConfigEntry , PingUpdateCoordinator
1920
2021
@@ -24,7 +25,7 @@ async def async_setup_entry(
2425 async_add_entities : AddConfigEntryEntitiesCallback ,
2526) -> None :
2627 """Set up a Ping config entry."""
27- async_add_entities ([PingDeviceTracker (entry , entry .runtime_data )])
28+ async_add_entities ([PingDeviceTracker (hass , entry , entry .runtime_data )])
2829
2930
3031class PingDeviceTracker (CoordinatorEntity [PingUpdateCoordinator ], ScannerEntity ):
@@ -33,7 +34,10 @@ class PingDeviceTracker(CoordinatorEntity[PingUpdateCoordinator], ScannerEntity)
3334 _last_seen : datetime | None = None
3435
3536 def __init__ (
36- self , config_entry : PingConfigEntry , coordinator : PingUpdateCoordinator
37+ self ,
38+ hass : HomeAssistant ,
39+ config_entry : PingConfigEntry ,
40+ coordinator : PingUpdateCoordinator ,
3741 ) -> None :
3842 """Initialize the Ping device tracker."""
3943 super ().__init__ (coordinator )
@@ -46,6 +50,13 @@ def __init__(
4650 )
4751 )
4852
53+ if (
54+ device := dr .async_get (hass ).async_get_device (
55+ identifiers = {(DOMAIN , config_entry .entry_id )}
56+ )
57+ ) is not None :
58+ self .device_entry = device
59+
4960 @property
5061 def ip_address (self ) -> str :
5162 """Return the primary ip address of the device."""
0 commit comments