Update tile to use CoordinatorEntity (#39439)
This commit is contained in:
parent
d9c9adbc91
commit
d3b845c01a
1 changed files with 7 additions and 16 deletions
|
@ -8,8 +8,11 @@ from pytile.errors import SessionExpiredError, TileError
|
|||
from homeassistant.const import ATTR_ATTRIBUTION, CONF_PASSWORD, CONF_USERNAME
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.helpers import aiohttp_client
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
||||
from homeassistant.helpers.update_coordinator import (
|
||||
CoordinatorEntity,
|
||||
DataUpdateCoordinator,
|
||||
UpdateFailed,
|
||||
)
|
||||
|
||||
from .const import DATA_COORDINATOR, DOMAIN, LOGGER
|
||||
|
||||
|
@ -85,15 +88,15 @@ async def async_unload_entry(hass, config_entry):
|
|||
return unload_ok
|
||||
|
||||
|
||||
class TileEntity(Entity):
|
||||
class TileEntity(CoordinatorEntity):
|
||||
"""Define a generic Tile entity."""
|
||||
|
||||
def __init__(self, coordinator):
|
||||
"""Initialize."""
|
||||
super().__init__(coordinator)
|
||||
self._attrs = {ATTR_ATTRIBUTION: DEFAULT_ATTRIBUTION}
|
||||
self._name = None
|
||||
self._unique_id = None
|
||||
self.coordinator = coordinator
|
||||
|
||||
@property
|
||||
def device_state_attributes(self):
|
||||
|
@ -110,11 +113,6 @@ class TileEntity(Entity):
|
|||
"""Return the name."""
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def should_poll(self):
|
||||
"""Disable polling."""
|
||||
return False
|
||||
|
||||
@property
|
||||
def unique_id(self):
|
||||
"""Return the unique ID of the entity."""
|
||||
|
@ -137,10 +135,3 @@ class TileEntity(Entity):
|
|||
self.async_on_remove(self.coordinator.async_add_listener(update))
|
||||
|
||||
self._update_from_latest_data()
|
||||
|
||||
async def async_update(self):
|
||||
"""Update the entity.
|
||||
|
||||
Only used by the generic entity update service.
|
||||
"""
|
||||
await self.coordinator.async_request_refresh()
|
||||
|
|
Loading…
Add table
Reference in a new issue