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.const import ATTR_ATTRIBUTION, CONF_PASSWORD, CONF_USERNAME
|
||||||
from homeassistant.core import callback
|
from homeassistant.core import callback
|
||||||
from homeassistant.helpers import aiohttp_client
|
from homeassistant.helpers import aiohttp_client
|
||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.update_coordinator import (
|
||||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
CoordinatorEntity,
|
||||||
|
DataUpdateCoordinator,
|
||||||
|
UpdateFailed,
|
||||||
|
)
|
||||||
|
|
||||||
from .const import DATA_COORDINATOR, DOMAIN, LOGGER
|
from .const import DATA_COORDINATOR, DOMAIN, LOGGER
|
||||||
|
|
||||||
|
@ -85,15 +88,15 @@ async def async_unload_entry(hass, config_entry):
|
||||||
return unload_ok
|
return unload_ok
|
||||||
|
|
||||||
|
|
||||||
class TileEntity(Entity):
|
class TileEntity(CoordinatorEntity):
|
||||||
"""Define a generic Tile entity."""
|
"""Define a generic Tile entity."""
|
||||||
|
|
||||||
def __init__(self, coordinator):
|
def __init__(self, coordinator):
|
||||||
"""Initialize."""
|
"""Initialize."""
|
||||||
|
super().__init__(coordinator)
|
||||||
self._attrs = {ATTR_ATTRIBUTION: DEFAULT_ATTRIBUTION}
|
self._attrs = {ATTR_ATTRIBUTION: DEFAULT_ATTRIBUTION}
|
||||||
self._name = None
|
self._name = None
|
||||||
self._unique_id = None
|
self._unique_id = None
|
||||||
self.coordinator = coordinator
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def device_state_attributes(self):
|
def device_state_attributes(self):
|
||||||
|
@ -110,11 +113,6 @@ class TileEntity(Entity):
|
||||||
"""Return the name."""
|
"""Return the name."""
|
||||||
return self._name
|
return self._name
|
||||||
|
|
||||||
@property
|
|
||||||
def should_poll(self):
|
|
||||||
"""Disable polling."""
|
|
||||||
return False
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unique_id(self):
|
def unique_id(self):
|
||||||
"""Return the unique ID of the entity."""
|
"""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.async_on_remove(self.coordinator.async_add_listener(update))
|
||||||
|
|
||||||
self._update_from_latest_data()
|
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