-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
entity.py
59 lines (46 loc) · 1.66 KB
/
entity.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
"""BermudaEntity class"""
from __future__ import annotations
from typing import TYPE_CHECKING
from homeassistant.helpers import area_registry
from homeassistant.helpers.update_coordinator import CoordinatorEntity
from .const import ATTRIBUTION
from .const import DOMAIN
from .const import NAME
if TYPE_CHECKING:
from . import BermudaDataUpdateCoordinator
# from . import BermudaDevice
class BermudaEntity(CoordinatorEntity):
"""Co-ordinator for Bermuda data.
Gathers the device infor for receivers and transmitters, calculates
distances etc.
"""
def __init__(
self, coordinator: BermudaDataUpdateCoordinator, config_entry, address: str
):
super().__init__(coordinator)
self.coordinator = coordinator
self.config_entry = config_entry
self._device = coordinator.devices[address]
self.area_reg = area_registry.async_get(coordinator.hass)
@property
def unique_id(self):
"""Return a unique ID to use for this entity."""
return self._device.unique_id
@property
def device_info(self):
"""Implementing this creates an entry in the device registry."""
return {
"identifiers": {(DOMAIN, self._device.unique_id)},
"name": self._device.prefname,
# TODO: Could use this to indicate tracker type (IRK, iBeacon etc).
"model": None,
"manufacturer": NAME,
}
@property
def device_state_attributes(self):
"""Return the state attributes."""
return {
"attribution": ATTRIBUTION,
"id": str(self.coordinator.data.get("id")),
"integration": DOMAIN,
}