hass-core/homeassistant/components/aprilaire/entity.py
Matthew FitzGerald-Chamberlain ce8cf314f9
Add Aprilaire integration (#95093)
* Add Aprilaire integration

* Fix test errors

* Update constants

* Code review cleanup

* Reuse coordinator from config flow

* Code review fixes

* Remove unneeded tests

* Improve translation

* Code review fixes

* Remove unneeded fixture

* Code review fixes

* Code review updates

* Use base data coordinator

* Deduplicate based on MAC

* Fix tests

* Check mac address on init

* Fix mypy error

* Use config entry ID for entity unique ID

* Fix tests

* Code review updates

* Fix mypy errors

* Code review updates

* Add data_description

* Update homeassistant/components/aprilaire/coordinator.py

Co-authored-by: Jon Oberheide <506986+jonoberheide@users.noreply.github.com>

* Update .coveragerc

* Update homeassistant/components/aprilaire/coordinator.py

---------

Co-authored-by: Erik Montnemery <erik@montnemery.com>
Co-authored-by: Jon Oberheide <506986+jonoberheide@users.noreply.github.com>
2024-02-16 08:30:51 +01:00

46 lines
1.3 KiB
Python

"""Base functionality for Aprilaire entities."""
from __future__ import annotations
import logging
from pyaprilaire.const import Attribute
from homeassistant.helpers.update_coordinator import BaseCoordinatorEntity
from .coordinator import AprilaireCoordinator
_LOGGER = logging.getLogger(__name__)
class BaseAprilaireEntity(BaseCoordinatorEntity[AprilaireCoordinator]):
"""Base for Aprilaire entities."""
_attr_available = False
_attr_has_entity_name = True
def __init__(
self, coordinator: AprilaireCoordinator, unique_id: str | None
) -> None:
"""Initialize the entity."""
super().__init__(coordinator)
self._attr_device_info = coordinator.device_info
self._attr_unique_id = f"{unique_id}_{self.translation_key}"
self._update_available()
def _update_available(self):
"""Update the entity availability."""
connected: bool = self.coordinator.data.get(
Attribute.CONNECTED, None
) or self.coordinator.data.get(Attribute.RECONNECTING, None)
stopped: bool = self.coordinator.data.get(Attribute.STOPPED, None)
self._attr_available = connected and not stopped
async def async_update(self) -> None:
"""Implement abstract base method."""