Migrate geofency to has entity name (#96592)

This commit is contained in:
Joost Lekkerkerker 2023-07-18 09:43:29 +02:00 committed by GitHub
parent bc6a41fb94
commit 8d048c4cfa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -50,6 +50,9 @@ async def async_setup_entry(
class GeofencyEntity(TrackerEntity, RestoreEntity):
"""Represent a tracked device."""
_attr_has_entity_name = True
_attr_name = None
def __init__(self, device, gps=None, location_name=None, attributes=None):
"""Set up Geofency entity."""
self._attributes = attributes or {}
@ -79,11 +82,6 @@ class GeofencyEntity(TrackerEntity, RestoreEntity):
"""Return a location name for the current location of the device."""
return self._location_name
@property
def name(self):
"""Return the name of the device."""
return self._name
@property
def unique_id(self):
"""Return the unique ID."""
@ -92,7 +90,10 @@ class GeofencyEntity(TrackerEntity, RestoreEntity):
@property
def device_info(self) -> DeviceInfo:
"""Return the device info."""
return DeviceInfo(identifiers={(GF_DOMAIN, self._unique_id)}, name=self._name)
return DeviceInfo(
identifiers={(GF_DOMAIN, self._unique_id)},
name=self._name,
)
@property
def source_type(self) -> SourceType:
@ -125,7 +126,7 @@ class GeofencyEntity(TrackerEntity, RestoreEntity):
@callback
def _async_receive_data(self, device, gps, location_name, attributes):
"""Mark the device as seen."""
if device != self.name:
if device != self._name:
return
self._attributes.update(attributes)