hass-core/homeassistant/components/fyta/entity.py
dontinelli 8a110abc82
Bump fyta_cli to 0.6.0 (#123816)
* Bump fyta_cli to 0.5.1

* Code adjustments to enable strit typing

* Update homeassistant/components/fyta/__init__.py

Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>

* Update diagnostics

* Update config_flow + init (ruff)

* Update sensor

* Update coordinator

* Update homeassistant/components/fyta/diagnostics.py

Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>

* Update homeassistant/components/fyta/diagnostics.py

Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>

* Update homeassistant/components/fyta/sensor.py

Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>

* Set one ph sensor to null/none

* Update sensor

* Clean-up (ruff)

---------

Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
2024-08-16 17:46:37 +02:00

48 lines
1.5 KiB
Python

"""Entities for FYTA integration."""
from fyta_cli.fyta_models import Plant
from homeassistant.components.sensor import SensorEntityDescription
from homeassistant.config_entries import ConfigEntry
from homeassistant.helpers.device_registry import DeviceInfo
from homeassistant.helpers.update_coordinator import CoordinatorEntity
from .const import DOMAIN
from .coordinator import FytaCoordinator
class FytaPlantEntity(CoordinatorEntity[FytaCoordinator]):
"""Base Fyta Plant entity."""
_attr_has_entity_name = True
def __init__(
self,
coordinator: FytaCoordinator,
entry: ConfigEntry,
description: SensorEntityDescription,
plant_id: int,
) -> None:
"""Initialize the Fyta sensor."""
super().__init__(coordinator)
self.plant_id = plant_id
self._attr_unique_id = f"{entry.entry_id}-{plant_id}-{description.key}"
self._attr_device_info = DeviceInfo(
manufacturer="Fyta",
model="Plant",
identifiers={(DOMAIN, f"{entry.entry_id}-{plant_id}")},
name=self.plant.name,
sw_version=self.plant.sw_version,
)
self.entity_description = description
@property
def plant(self) -> Plant:
"""Get plant data."""
return self.coordinator.data[self.plant_id]
@property
def available(self) -> bool:
"""Test if entity is available."""
return super().available and self.plant_id in self.coordinator.data