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>
This commit is contained in:
parent
152b6c2d1a
commit
16a0bd7ff3
1 changed files with 7 additions and 24 deletions
|
@ -18,8 +18,11 @@ from homeassistant.const import (
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.exceptions import ConfigEntryNotReady
|
from homeassistant.exceptions import ConfigEntryNotReady
|
||||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||||
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 (
|
from .const import (
|
||||||
ATTR_IDENTIFIERS,
|
ATTR_IDENTIFIERS,
|
||||||
|
@ -124,7 +127,7 @@ class IPPDataUpdateCoordinator(DataUpdateCoordinator[IPPPrinter]):
|
||||||
raise UpdateFailed(f"Invalid response from API: {error}") from error
|
raise UpdateFailed(f"Invalid response from API: {error}") from error
|
||||||
|
|
||||||
|
|
||||||
class IPPEntity(Entity):
|
class IPPEntity(CoordinatorEntity):
|
||||||
"""Defines a base IPP entity."""
|
"""Defines a base IPP entity."""
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
|
@ -138,12 +141,12 @@ class IPPEntity(Entity):
|
||||||
enabled_default: bool = True,
|
enabled_default: bool = True,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize the IPP entity."""
|
"""Initialize the IPP entity."""
|
||||||
|
super().__init__(coordinator)
|
||||||
self._device_id = device_id
|
self._device_id = device_id
|
||||||
self._enabled_default = enabled_default
|
self._enabled_default = enabled_default
|
||||||
self._entry_id = entry_id
|
self._entry_id = entry_id
|
||||||
self._icon = icon
|
self._icon = icon
|
||||||
self._name = name
|
self._name = name
|
||||||
self.coordinator = coordinator
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self) -> str:
|
def name(self) -> str:
|
||||||
|
@ -155,31 +158,11 @@ class IPPEntity(Entity):
|
||||||
"""Return the mdi icon of the entity."""
|
"""Return the mdi icon of the entity."""
|
||||||
return self._icon
|
return self._icon
|
||||||
|
|
||||||
@property
|
|
||||||
def available(self) -> bool:
|
|
||||||
"""Return True if entity is available."""
|
|
||||||
return self.coordinator.last_update_success
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def entity_registry_enabled_default(self) -> bool:
|
def entity_registry_enabled_default(self) -> bool:
|
||||||
"""Return if the entity should be enabled when first added to the entity registry."""
|
"""Return if the entity should be enabled when first added to the entity registry."""
|
||||||
return self._enabled_default
|
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
|
@property
|
||||||
def device_info(self) -> Dict[str, Any]:
|
def device_info(self) -> Dict[str, Any]:
|
||||||
"""Return device information about this IPP device."""
|
"""Return device information about this IPP device."""
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue