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 <balloob@gmail.com>
Co-authored-by: springstan <46536646+springstan@users.noreply.github.com>
pull/39424/head
Chris Talkington 2020-08-30 09:07:36 -05:00 committed by GitHub
parent 152b6c2d1a
commit 16a0bd7ff3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 24 deletions

View File

@ -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."""