hass-core/homeassistant/components/ipp/entity.py
Chris Talkington 6a528acafe
Use attrs instead of properties for ipp (#52270)
* use attrs instead of properties for ipp

* Update __init__.py

* Create entity.py

* Update __init__.py

* Create coordinator.py

* Update coordinator.py

* Update __init__.py

* Update entity.py

* Update sensor.py

* Update sensor.py

* Update __init__.py

* Update __init__.py

* Update coordinator.py

* Update entity.py

* Update entity.py

* Update entity.py

* Update sensor.py

* Update sensor.py
2021-06-29 10:02:49 +02:00

51 lines
1.5 KiB
Python

"""Entities for The Internet Printing Protocol (IPP) integration."""
from __future__ import annotations
from homeassistant.const import ATTR_NAME
from homeassistant.helpers.entity import DeviceInfo
from homeassistant.helpers.update_coordinator import CoordinatorEntity
from .const import (
ATTR_IDENTIFIERS,
ATTR_MANUFACTURER,
ATTR_MODEL,
ATTR_SOFTWARE_VERSION,
DOMAIN,
)
from .coordinator import IPPDataUpdateCoordinator
class IPPEntity(CoordinatorEntity):
"""Defines a base IPP entity."""
def __init__(
self,
*,
entry_id: str,
device_id: str,
coordinator: IPPDataUpdateCoordinator,
name: str,
icon: str,
enabled_default: bool = True,
) -> None:
"""Initialize the IPP entity."""
super().__init__(coordinator)
self._device_id = device_id
self._entry_id = entry_id
self._attr_name = name
self._attr_icon = icon
self._attr_entity_registry_enabled_default = enabled_default
@property
def device_info(self) -> DeviceInfo:
"""Return device information about this IPP device."""
if self._device_id is None:
return None
return {
ATTR_IDENTIFIERS: {(DOMAIN, self._device_id)},
ATTR_NAME: self.coordinator.data.info.name,
ATTR_MANUFACTURER: self.coordinator.data.info.manufacturer,
ATTR_MODEL: self.coordinator.data.info.model,
ATTR_SOFTWARE_VERSION: self.coordinator.data.info.version,
}