hass-core/homeassistant/components/arve/entity.py
Illia cbaef096fa
Add Arve integration (#113156)
* add Arve integration

* Update homeassistant/components/arve/config_flow.py

Co-authored-by: Josef Zweck <24647999+zweckj@users.noreply.github.com>

* Various fixes, changed scan interval to one minute

* coordinator implementation

* Code cleanup

* Moved device info to the entity.py, ArveDeviceEntityDescription to sensor.py

* delete refresh before adding entities

Co-authored-by: Josef Zweck <24647999+zweckj@users.noreply.github.com>

* Update tests/components/arve/test_config_flow.py

Co-authored-by: Josef Zweck <24647999+zweckj@users.noreply.github.com>

* Update tests/components/arve/conftest.py

Co-authored-by: Josef Zweck <24647999+zweckj@users.noreply.github.com>

* Changed value_fn in sensors.py, added typing to description

* Code cleanups, platfrom test implementation

* New code cleanups, first two working tests

* Created platform test, generated snapshots

* Reworked integration to get all of the customer devices

* new fixes

* Added customer id, small cleanups

* Logic of setting unique_id to the config flow

* Added test of abortion on duplicate config_flow id

* Added "available" and "device" properties fro ArveDeviceEntity

* small _attr_unique_id fix

* Added new test, improved mocking, various fixes

* Various cleanups and fixes

* microfix

* Update homeassistant/components/arve/strings.json

* ruff fix

---------

Co-authored-by: Josef Zweck <24647999+zweckj@users.noreply.github.com>
Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
2024-04-08 17:24:32 +02:00

53 lines
1.5 KiB
Python

"""Arve base entity."""
from __future__ import annotations
from asyncarve import ArveDeviceInfo
from homeassistant.helpers.device_registry import DeviceInfo
from homeassistant.helpers.entity import EntityDescription
from homeassistant.helpers.update_coordinator import CoordinatorEntity
from .const import DOMAIN
from .coordinator import ArveCoordinator
class ArveDeviceEntity(CoordinatorEntity[ArveCoordinator]):
"""Defines a base Arve device entity."""
_attr_has_entity_name = True
def __init__(
self,
coordinator: ArveCoordinator,
description: EntityDescription,
serial_number: str,
) -> None:
"""Initialize the Arve device entity."""
super().__init__(coordinator)
self.device_serial_number = serial_number
self.entity_description = description
self._attr_unique_id = f"{serial_number}_{description.key}"
self._attr_device_info = DeviceInfo(
identifiers={(DOMAIN, serial_number)},
manufacturer="Calanda Air AG",
model="Arve Sens Pro",
serial_number=serial_number,
name=self.device.info.name,
)
@property
def available(self) -> bool:
"""Check if device is available."""
return super()._attr_available and (
self.device_serial_number in self.coordinator.data
)
@property
def device(self) -> ArveDeviceInfo:
"""Returns device instance."""
return self.coordinator.data[self.device_serial_number]