From 16a0bd7ff32c344ae4c22a2748f1f5a6fde1a30a Mon Sep 17 00:00:00 2001 From: Chris Talkington Date: Sun, 30 Aug 2020 09:07:36 -0500 Subject: [PATCH] Update ipp to use CoordinatorEntity (#39412) * update ipp to use CoordinatorEntity * Update homeassistant/components/ipp/__init__.py Co-authored-by: springstan <46536646+springstan@users.noreply.github.com> * Solve isort and black Co-authored-by: Paulus Schoutsen Co-authored-by: springstan <46536646+springstan@users.noreply.github.com> --- homeassistant/components/ipp/__init__.py | 31 ++++++------------------ 1 file changed, 7 insertions(+), 24 deletions(-) diff --git a/homeassistant/components/ipp/__init__.py b/homeassistant/components/ipp/__init__.py index 1f9a616dc4f..9f522b086fc 100644 --- a/homeassistant/components/ipp/__init__.py +++ b/homeassistant/components/ipp/__init__.py @@ -18,8 +18,11 @@ from homeassistant.const import ( from homeassistant.core import HomeAssistant from homeassistant.exceptions import ConfigEntryNotReady from homeassistant.helpers.aiohttp_client import async_get_clientsession -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 ( ATTR_IDENTIFIERS, @@ -124,7 +127,7 @@ class IPPDataUpdateCoordinator(DataUpdateCoordinator[IPPPrinter]): raise UpdateFailed(f"Invalid response from API: {error}") from error -class IPPEntity(Entity): +class IPPEntity(CoordinatorEntity): """Defines a base IPP entity.""" def __init__( @@ -138,12 +141,12 @@ class IPPEntity(Entity): enabled_default: bool = True, ) -> None: """Initialize the IPP entity.""" + super().__init__(coordinator) self._device_id = device_id self._enabled_default = enabled_default self._entry_id = entry_id self._icon = icon self._name = name - self.coordinator = coordinator @property def name(self) -> str: @@ -155,31 +158,11 @@ class IPPEntity(Entity): """Return the mdi icon of the entity.""" return self._icon - @property - def available(self) -> bool: - """Return True if entity is available.""" - return self.coordinator.last_update_success - @property def entity_registry_enabled_default(self) -> bool: """Return if the entity should be enabled when first added to the entity registry.""" return self._enabled_default - @property - def should_poll(self) -> bool: - """Return the polling requirement of the entity.""" - return False - - async def async_added_to_hass(self) -> None: - """Connect to dispatcher listening for entity data notifications.""" - self.async_on_remove( - self.coordinator.async_add_listener(self.async_write_ha_state) - ) - - async def async_update(self) -> None: - """Update an IPP entity.""" - await self.coordinator.async_request_refresh() - @property def device_info(self) -> Dict[str, Any]: """Return device information about this IPP device."""