2021-04-11 20:36:44 +00:00
|
|
|
"""Base class for Rituals Perfume Genie diffuser entity."""
|
2021-04-17 13:41:45 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
from pyrituals import Diffuser
|
|
|
|
|
2021-04-11 20:36:44 +00:00
|
|
|
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
|
|
|
|
2021-05-04 12:47:17 +00:00
|
|
|
from . import RitualsDataUpdateCoordinator
|
2021-07-12 18:40:16 +00:00
|
|
|
from .const import DOMAIN
|
2021-04-11 20:36:44 +00:00
|
|
|
|
|
|
|
MANUFACTURER = "Rituals Cosmetics"
|
2021-04-17 13:41:45 +00:00
|
|
|
MODEL = "The Perfume Genie"
|
|
|
|
MODEL2 = "The Perfume Genie 2.0"
|
2021-04-11 20:36:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
class DiffuserEntity(CoordinatorEntity):
|
|
|
|
"""Representation of a diffuser entity."""
|
|
|
|
|
2021-05-04 12:47:17 +00:00
|
|
|
coordinator: RitualsDataUpdateCoordinator
|
|
|
|
|
2021-04-17 13:41:45 +00:00
|
|
|
def __init__(
|
2021-05-04 12:47:17 +00:00
|
|
|
self,
|
|
|
|
diffuser: Diffuser,
|
|
|
|
coordinator: RitualsDataUpdateCoordinator,
|
|
|
|
entity_suffix: str,
|
2021-04-17 13:41:45 +00:00
|
|
|
) -> None:
|
2021-04-11 20:36:44 +00:00
|
|
|
"""Init from config, hookup diffuser and coordinator."""
|
|
|
|
super().__init__(coordinator)
|
|
|
|
self._diffuser = diffuser
|
|
|
|
|
2021-07-12 18:40:16 +00:00
|
|
|
hublot = self._diffuser.hublot
|
|
|
|
hubname = self._diffuser.name
|
2021-04-11 20:36:44 +00:00
|
|
|
|
2021-06-29 06:39:00 +00:00
|
|
|
self._attr_name = f"{hubname}{entity_suffix}"
|
|
|
|
self._attr_unique_id = f"{hublot}{entity_suffix}"
|
|
|
|
self._attr_device_info = {
|
|
|
|
"name": hubname,
|
|
|
|
"identifiers": {(DOMAIN, hublot)},
|
|
|
|
"manufacturer": MANUFACTURER,
|
|
|
|
"model": MODEL if diffuser.has_battery else MODEL2,
|
2021-07-12 18:40:16 +00:00
|
|
|
"sw_version": diffuser.version,
|
2021-06-29 06:39:00 +00:00
|
|
|
}
|
2021-04-11 20:36:44 +00:00
|
|
|
|
|
|
|
@property
|
2021-04-17 13:41:45 +00:00
|
|
|
def available(self) -> bool:
|
|
|
|
"""Return if the entity is available."""
|
2021-07-12 18:40:16 +00:00
|
|
|
return super().available and self._diffuser.is_online
|