core/homeassistant/components/crownstone/devices.py

46 lines
1.2 KiB
Python
Raw Normal View History

2021-09-14 19:46:52 +00:00
"""Base classes for Crownstone devices."""
from __future__ import annotations
from crownstone_cloud.cloud_models.crownstones import Crownstone
from homeassistant.const import (
ATTR_IDENTIFIERS,
ATTR_MANUFACTURER,
ATTR_MODEL,
ATTR_NAME,
ATTR_SW_VERSION,
)
from homeassistant.helpers.entity import DeviceInfo, Entity
2021-09-14 19:46:52 +00:00
from .const import CROWNSTONE_INCLUDE_TYPES, DOMAIN
class CrownstoneBaseEntity(Entity):
"""Base entity class for Crownstone devices."""
_attr_should_poll = False
2021-09-14 19:46:52 +00:00
def __init__(self, device: Crownstone) -> None:
"""Initialize the device."""
self.device = device
@property
def cloud_id(self) -> str:
"""
Return the unique identifier for this device.
Used as device ID and to generate unique entity ID's.
"""
return str(self.device.cloud_id)
@property
def device_info(self) -> DeviceInfo:
"""Return device info."""
return {
ATTR_IDENTIFIERS: {(DOMAIN, self.cloud_id)},
ATTR_NAME: self.device.name,
ATTR_MANUFACTURER: "Crownstone",
ATTR_MODEL: CROWNSTONE_INCLUDE_TYPES[self.device.type],
ATTR_SW_VERSION: self.device.sw_version,
}