Home Assistant Unofficial Reference
2024.12.1
entity.py
Go to the documentation of this file.
1
"""Entities for FYTA integration."""
2
3
from
fyta_cli.fyta_models
import
Plant
4
5
from
homeassistant.components.sensor
import
SensorEntityDescription
6
from
homeassistant.config_entries
import
ConfigEntry
7
from
homeassistant.helpers.device_registry
import
DeviceInfo
8
from
homeassistant.helpers.update_coordinator
import
CoordinatorEntity
9
10
from
.const
import
DOMAIN
11
from
.coordinator
import
FytaCoordinator
12
13
14
class
FytaPlantEntity
(
CoordinatorEntity
[FytaCoordinator]):
15
"""Base Fyta Plant entity."""
16
17
_attr_has_entity_name =
True
18
19
def
__init__
(
20
self,
21
coordinator: FytaCoordinator,
22
entry: ConfigEntry,
23
description: SensorEntityDescription,
24
plant_id: int,
25
) ->
None
:
26
"""Initialize the Fyta sensor."""
27
super().
__init__
(coordinator)
28
29
self.
plant_id
plant_id = plant_id
30
self.
_attr_unique_id
_attr_unique_id = f
"{entry.entry_id}-{plant_id}-{description.key}"
31
self.
_attr_device_info
_attr_device_info =
DeviceInfo
(
32
manufacturer=
"Fyta"
,
33
model=
"Plant"
,
34
identifiers={(DOMAIN, f
"{entry.entry_id}-{plant_id}"
)},
35
name=self.
plant
plant.name,
36
sw_version=self.
plant
plant.sw_version,
37
)
38
self.
entity_description
entity_description = description
39
40
@property
41
def
plant
(self) -> Plant:
42
"""Get plant data."""
43
return
self.coordinator.data[self.
plant_id
plant_id]
44
45
@property
46
def
available
(self) -> bool:
47
"""Test if entity is available."""
48
return
super().available
and
self.
plant_id
plant_id
in
self.coordinator.data
homeassistant.components.fyta.entity.FytaPlantEntity
Definition:
entity.py:14
homeassistant.components.fyta.entity.FytaPlantEntity.plant_id
plant_id
Definition:
entity.py:29
homeassistant.components.fyta.entity.FytaPlantEntity.plant
Plant plant(self)
Definition:
entity.py:41
homeassistant.components.fyta.entity.FytaPlantEntity._attr_unique_id
_attr_unique_id
Definition:
entity.py:30
homeassistant.components.fyta.entity.FytaPlantEntity.entity_description
entity_description
Definition:
entity.py:38
homeassistant.components.fyta.entity.FytaPlantEntity.__init__
None __init__(self, FytaCoordinator coordinator, ConfigEntry entry, SensorEntityDescription description, int plant_id)
Definition:
entity.py:25
homeassistant.components.fyta.entity.FytaPlantEntity._attr_device_info
_attr_device_info
Definition:
entity.py:31
homeassistant.components.fyta.entity.FytaPlantEntity.available
bool available(self)
Definition:
entity.py:46
homeassistant.helpers.device_registry.DeviceInfo
Definition:
device_registry.py:98
homeassistant.helpers.update_coordinator.CoordinatorEntity
Definition:
update_coordinator.py:568
homeassistant.components.sensor
Definition:
__init__.py:1
homeassistant.config_entries
Definition:
config_entries.py:1
homeassistant.helpers.device_registry
Definition:
device_registry.py:1
homeassistant.helpers.update_coordinator
Definition:
update_coordinator.py:1
core
homeassistant
components
fyta
entity.py
Generated by
1.9.1