2020-07-11 01:20:50 +00:00
|
|
|
"""An abstract class common to all Bond entities."""
|
|
|
|
from typing import Any, Dict, Optional
|
|
|
|
|
|
|
|
from homeassistant.const import ATTR_NAME
|
|
|
|
|
|
|
|
from .const import DOMAIN
|
2020-07-12 16:31:53 +00:00
|
|
|
from .utils import BondDevice, BondHub
|
2020-07-11 01:20:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
class BondEntity:
|
|
|
|
"""Generic Bond entity encapsulating common features of any Bond controlled device."""
|
|
|
|
|
2020-07-12 16:31:53 +00:00
|
|
|
def __init__(self, hub: BondHub, device: BondDevice):
|
2020-07-11 01:20:50 +00:00
|
|
|
"""Initialize entity with API and device info."""
|
2020-07-12 16:31:53 +00:00
|
|
|
self._hub = hub
|
2020-07-11 01:20:50 +00:00
|
|
|
self._device = device
|
|
|
|
|
|
|
|
@property
|
|
|
|
def unique_id(self) -> Optional[str]:
|
|
|
|
"""Get unique ID for the entity."""
|
|
|
|
return self._device.device_id
|
|
|
|
|
|
|
|
@property
|
|
|
|
def name(self) -> Optional[str]:
|
|
|
|
"""Get entity name."""
|
|
|
|
return self._device.name
|
|
|
|
|
|
|
|
@property
|
|
|
|
def device_info(self) -> Optional[Dict[str, Any]]:
|
|
|
|
"""Get a an HA device representing this Bond controlled device."""
|
2020-07-12 16:31:53 +00:00
|
|
|
return {
|
|
|
|
ATTR_NAME: self.name,
|
|
|
|
"identifiers": {(DOMAIN, self._device.device_id)},
|
|
|
|
"via_device": (DOMAIN, self._hub.bond_id),
|
|
|
|
}
|
2020-07-11 01:20:50 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def assumed_state(self) -> bool:
|
|
|
|
"""Let HA know this entity relies on an assumed state tracked by Bond."""
|
|
|
|
return True
|