Fix device tracker TrackerEntity defaults (#32459)

This commit is contained in:
Paulus Schoutsen 2020-03-04 00:43:52 -08:00 committed by GitHub
parent af76a336af
commit 7678d66464
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 26 additions and 42 deletions

View file

@ -61,10 +61,15 @@ class BaseTrackerEntity(Entity):
class TrackerEntity(BaseTrackerEntity):
"""Represent a tracked device."""
@property
def should_poll(self):
"""No polling for entities that have location pushed."""
return False
@property
def force_update(self):
"""All updates need to be written to the state machine."""
return True
"""All updates need to be written to the state machine if we're not polling."""
return not self.should_poll
@property
def location_accuracy(self):

View file

@ -84,11 +84,6 @@ class GeofencyEntity(TrackerEntity, RestoreEntity):
"""Return the name of the device."""
return self._name
@property
def should_poll(self):
"""No polling needed."""
return False
@property
def unique_id(self):
"""Return the unique ID."""

View file

@ -107,11 +107,6 @@ class GPSLoggerEntity(TrackerEntity, RestoreEntity):
"""Return the name of the device."""
return self._name
@property
def should_poll(self):
"""No polling needed."""
return False
@property
def unique_id(self):
"""Return the unique ID."""

View file

@ -107,11 +107,6 @@ class IcloudTrackerEntity(TrackerEntity):
"model": self._device.device_model,
}
@property
def should_poll(self) -> bool:
"""No polling needed."""
return False
async def async_added_to_hass(self):
"""Register state update callback."""
self._unsub_dispatcher = async_dispatcher_connect(

View file

@ -61,11 +61,6 @@ class LocativeEntity(TrackerEntity):
"""Return the name of the device."""
return self._name
@property
def should_poll(self):
"""No polling needed."""
return False
@property
def source_type(self):
"""Return the source type, eg gps or router, of the device."""

View file

@ -100,11 +100,6 @@ class MobileAppEntity(TrackerEntity, RestoreEntity):
"""Return the name of the device."""
return self._entry.data[ATTR_DEVICE_NAME]
@property
def should_poll(self):
"""No polling needed."""
return False
@property
def source_type(self):
"""Return the source type, eg gps or router, of the device."""

View file

@ -118,11 +118,6 @@ class OwnTracksEntity(TrackerEntity, RestoreEntity):
"""Return the name of the device."""
return self._data.get("host_name")
@property
def should_poll(self):
"""No polling needed."""
return False
@property
def source_type(self):
"""Return the source type, eg gps or router, of the device."""

View file

@ -68,8 +68,3 @@ class TeslaDeviceEntity(TeslaDevice, TrackerEntity):
def source_type(self):
"""Return the source type, eg gps or router, of the device."""
return SOURCE_TYPE_GPS
@property
def force_update(self):
"""All updates do not need to be written to the state machine."""
return False

View file

@ -371,11 +371,6 @@ class TraccarEntity(TrackerEntity, RestoreEntity):
"""Return the name of the device."""
return self._name
@property
def should_poll(self):
"""No polling needed."""
return False
@property
def unique_id(self):
"""Return the unique ID."""

View file

@ -0,0 +1,19 @@
"""Test Device Tracker config entry things."""
from homeassistant.components.device_tracker import config_entry
def test_tracker_entity():
"""Test tracker entity."""
class TestEntry(config_entry.TrackerEntity):
"""Mock tracker class."""
should_poll = False
instance = TestEntry()
assert instance.force_update
instance.should_poll = True
assert not instance.force_update