From e29c75a68e398e3734e0ff55e785632234cade7b Mon Sep 17 00:00:00 2001 From: Aaron Bach Date: Sat, 3 Jul 2021 11:29:52 -0500 Subject: [PATCH] Remove redundant property definitions in Tile (#52448) --- homeassistant/components/tile/__init__.py | 7 +--- .../components/tile/device_tracker.py | 39 ++++--------------- 2 files changed, 9 insertions(+), 37 deletions(-) diff --git a/homeassistant/components/tile/__init__.py b/homeassistant/components/tile/__init__.py index 7faefe4d275..d8a592a2f09 100644 --- a/homeassistant/components/tile/__init__.py +++ b/homeassistant/components/tile/__init__.py @@ -24,14 +24,9 @@ DEFAULT_UPDATE_INTERVAL = timedelta(minutes=2) CONF_SHOW_INACTIVE = "show_inactive" -async def async_setup(hass, config): - """Set up the Tile component.""" - hass.data[DOMAIN] = {DATA_COORDINATOR: {}, DATA_TILE: {}} - return True - - async def async_setup_entry(hass, entry): """Set up Tile as config entry.""" + hass.data.setdefault(DOMAIN, {DATA_COORDINATOR: {}, DATA_TILE: {}}) hass.data[DOMAIN][DATA_COORDINATOR][entry.entry_id] = {} hass.data[DOMAIN][DATA_TILE][entry.entry_id] = {} diff --git a/homeassistant/components/tile/device_tracker.py b/homeassistant/components/tile/device_tracker.py index add6e5f94a0..ea1b853d9ae 100644 --- a/homeassistant/components/tile/device_tracker.py +++ b/homeassistant/components/tile/device_tracker.py @@ -63,35 +63,22 @@ async def async_setup_scanner(hass, config, async_see, discovery_info=None): class TileDeviceTracker(CoordinatorEntity, TrackerEntity): """Representation of a network infrastructure device.""" + _attr_icon = DEFAULT_ICON + def __init__(self, entry, coordinator, tile): """Initialize.""" super().__init__(coordinator) - self._attrs = {ATTR_ATTRIBUTION: DEFAULT_ATTRIBUTION} + + self._attr_extra_state_attributes = {ATTR_ATTRIBUTION: DEFAULT_ATTRIBUTION} + self._attr_name = tile.name + self._attr_unique_id = f"{entry.data[CONF_USERNAME]}_{tile.uuid}" self._entry = entry self._tile = tile @property def available(self): """Return if entity is available.""" - return self.coordinator.last_update_success and not self._tile.dead - - @property - def battery_level(self): - """Return the battery level of the device. - - Percentage from 0-100. - """ - return None - - @property - def extra_state_attributes(self): - """Return the device state attributes.""" - return self._attrs - - @property - def icon(self): - """Return the icon.""" - return DEFAULT_ICON + return super().available and not self._tile.dead @property def location_accuracy(self): @@ -111,16 +98,6 @@ class TileDeviceTracker(CoordinatorEntity, TrackerEntity): """Return longitude value of the device.""" return self._tile.longitude - @property - def name(self): - """Return the name.""" - return self._tile.name - - @property - def unique_id(self): - """Return the unique ID of the entity.""" - return f"{self._entry.data[CONF_USERNAME]}_{self._tile.uuid}" - @property def source_type(self): """Return the source type, eg gps or router, of the device.""" @@ -135,7 +112,7 @@ class TileDeviceTracker(CoordinatorEntity, TrackerEntity): @callback def _update_from_latest_data(self): """Update the entity from the latest data.""" - self._attrs.update( + self._attr_extra_state_attributes.update( { ATTR_ALTITUDE: self._tile.altitude, ATTR_IS_LOST: self._tile.lost,