1
mirror of https://github.com/home-assistant/core synced 2024-07-30 21:18:57 +02:00

Update tile to use CoordinatorEntity (#39439)

This commit is contained in:
springstan 2020-08-30 18:32:32 +02:00 committed by GitHub
parent d9c9adbc91
commit d3b845c01a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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()