mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 03:07:37 +00:00
Small tweaks to Rituals Perfume Genie (#52269)
This commit is contained in:
parent
94a0259743
commit
d37018cf87
@ -60,10 +60,10 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry):
|
||||
|
||||
|
||||
class RitualsDataUpdateCoordinator(DataUpdateCoordinator):
|
||||
"""Class to manage fetching Rituals Perufme Genie device data from single endpoint."""
|
||||
"""Class to manage fetching Rituals Perfume Genie device data from single endpoint."""
|
||||
|
||||
def __init__(self, hass: HomeAssistant, device: Diffuser) -> None:
|
||||
"""Initialize global Rituals Perufme Genie data updater."""
|
||||
"""Initialize global Rituals Perfume Genie data updater."""
|
||||
self._device = device
|
||||
super().__init__(
|
||||
hass,
|
||||
|
@ -26,18 +26,19 @@ async def async_setup_entry(
|
||||
"""Set up the diffuser binary sensors."""
|
||||
diffusers = hass.data[DOMAIN][config_entry.entry_id][DEVICES]
|
||||
coordinators = hass.data[DOMAIN][config_entry.entry_id][COORDINATORS]
|
||||
entities = []
|
||||
for hublot, diffuser in diffusers.items():
|
||||
if diffuser.has_battery:
|
||||
coordinator = coordinators[hublot]
|
||||
entities.append(DiffuserBatteryChargingBinarySensor(diffuser, coordinator))
|
||||
|
||||
async_add_entities(entities)
|
||||
async_add_entities(
|
||||
DiffuserBatteryChargingBinarySensor(diffuser, coordinators[hublot])
|
||||
for hublot, diffuser in diffusers.items()
|
||||
if diffuser.has_battery
|
||||
)
|
||||
|
||||
|
||||
class DiffuserBatteryChargingBinarySensor(DiffuserEntity, BinarySensorEntity):
|
||||
"""Representation of a diffuser battery charging binary sensor."""
|
||||
|
||||
_attr_device_class = DEVICE_CLASS_BATTERY_CHARGING
|
||||
|
||||
def __init__(
|
||||
self, diffuser: Diffuser, coordinator: RitualsDataUpdateCoordinator
|
||||
) -> None:
|
||||
@ -48,8 +49,3 @@ class DiffuserBatteryChargingBinarySensor(DiffuserEntity, BinarySensorEntity):
|
||||
def is_on(self) -> bool:
|
||||
"""Return the state of the battery charging binary sensor."""
|
||||
return self._diffuser.charging
|
||||
|
||||
@property
|
||||
def device_class(self) -> str:
|
||||
"""Return the device class of the battery charging binary sensor."""
|
||||
return DEVICE_CLASS_BATTERY_CHARGING
|
||||
|
@ -3,7 +3,6 @@ from __future__ import annotations
|
||||
|
||||
from pyrituals import Diffuser
|
||||
|
||||
from homeassistant.helpers.entity import DeviceInfo
|
||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||
|
||||
from . import RitualsDataUpdateCoordinator
|
||||
@ -35,32 +34,21 @@ class DiffuserEntity(CoordinatorEntity):
|
||||
"""Init from config, hookup diffuser and coordinator."""
|
||||
super().__init__(coordinator)
|
||||
self._diffuser = diffuser
|
||||
self._entity_suffix = entity_suffix
|
||||
self._hublot = self._diffuser.hub_data[HUBLOT]
|
||||
self._hubname = self._diffuser.hub_data[ATTRIBUTES][ROOMNAME]
|
||||
|
||||
@property
|
||||
def unique_id(self) -> str:
|
||||
"""Return the unique ID of the entity."""
|
||||
return f"{self._hublot}{self._entity_suffix}"
|
||||
hublot = self._diffuser.hub_data[HUBLOT]
|
||||
hubname = self._diffuser.hub_data[ATTRIBUTES][ROOMNAME]
|
||||
|
||||
@property
|
||||
def name(self) -> str:
|
||||
"""Return the name of the entity."""
|
||||
return f"{self._hubname}{self._entity_suffix}"
|
||||
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,
|
||||
"sw_version": diffuser.hub_data[SENSORS][VERSION],
|
||||
}
|
||||
|
||||
@property
|
||||
def available(self) -> bool:
|
||||
"""Return if the entity is available."""
|
||||
return super().available and self._diffuser.hub_data[STATUS] == AVAILABLE_STATE
|
||||
|
||||
@property
|
||||
def device_info(self) -> DeviceInfo:
|
||||
"""Return information about the device."""
|
||||
return {
|
||||
"name": self._hubname,
|
||||
"identifiers": {(DOMAIN, self._hublot)},
|
||||
"manufacturer": MANUFACTURER,
|
||||
"model": MODEL if self._diffuser.has_battery else MODEL2,
|
||||
"sw_version": self._diffuser.hub_data[SENSORS][VERSION],
|
||||
}
|
||||
|
@ -37,32 +37,21 @@ async def async_setup_entry(
|
||||
class DiffuserPerfumeAmount(DiffuserEntity, NumberEntity):
|
||||
"""Representation of a diffuser perfume amount number."""
|
||||
|
||||
_attr_icon = "mdi:gauge"
|
||||
_attr_max_value = MAX_PERFUME_AMOUNT
|
||||
_attr_min_value = MIN_PERFUME_AMOUNT
|
||||
|
||||
def __init__(
|
||||
self, diffuser: Diffuser, coordinator: RitualsDataUpdateCoordinator
|
||||
) -> None:
|
||||
"""Initialize the diffuser perfume amount number."""
|
||||
super().__init__(diffuser, coordinator, PERFUME_AMOUNT_SUFFIX)
|
||||
|
||||
@property
|
||||
def icon(self) -> str:
|
||||
"""Return the icon of the perfume amount entity."""
|
||||
return "mdi:gauge"
|
||||
|
||||
@property
|
||||
def value(self) -> int:
|
||||
"""Return the current perfume amount."""
|
||||
return self._diffuser.perfume_amount
|
||||
|
||||
@property
|
||||
def min_value(self) -> int:
|
||||
"""Return the minimum perfume amount."""
|
||||
return MIN_PERFUME_AMOUNT
|
||||
|
||||
@property
|
||||
def max_value(self) -> int:
|
||||
"""Return the maximum perfume amount."""
|
||||
return MAX_PERFUME_AMOUNT
|
||||
|
||||
async def async_set_value(self, value: float) -> None:
|
||||
"""Set the perfume amount."""
|
||||
if value.is_integer() and MIN_PERFUME_AMOUNT <= value <= MAX_PERFUME_AMOUNT:
|
||||
|
@ -58,12 +58,9 @@ class DiffuserPerfumeSensor(DiffuserEntity):
|
||||
"""Initialize the perfume sensor."""
|
||||
super().__init__(diffuser, coordinator, PERFUME_SUFFIX)
|
||||
|
||||
@property
|
||||
def icon(self) -> str:
|
||||
"""Return the perfume sensor icon."""
|
||||
if self._diffuser.hub_data[SENSORS][PERFUME][ID] == PERFUME_NO_CARTRIDGE_ID:
|
||||
return "mdi:tag-remove"
|
||||
return "mdi:tag-text"
|
||||
self._attr_icon = "mdi:tag-text"
|
||||
if diffuser.hub_data[SENSORS][PERFUME][ID] == PERFUME_NO_CARTRIDGE_ID:
|
||||
self._attr_icon = "mdi:tag-remove"
|
||||
|
||||
@property
|
||||
def state(self) -> str:
|
||||
@ -96,6 +93,9 @@ class DiffuserFillSensor(DiffuserEntity):
|
||||
class DiffuserBatterySensor(DiffuserEntity):
|
||||
"""Representation of a diffuser battery sensor."""
|
||||
|
||||
_attr_device_class = DEVICE_CLASS_BATTERY
|
||||
_attr_unit_of_measurement = PERCENTAGE
|
||||
|
||||
def __init__(
|
||||
self, diffuser: Diffuser, coordinator: RitualsDataUpdateCoordinator
|
||||
) -> None:
|
||||
@ -107,20 +107,13 @@ class DiffuserBatterySensor(DiffuserEntity):
|
||||
"""Return the state of the battery sensor."""
|
||||
return self._diffuser.battery_percentage
|
||||
|
||||
@property
|
||||
def device_class(self) -> str:
|
||||
"""Return the class of the battery sensor."""
|
||||
return DEVICE_CLASS_BATTERY
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self) -> str:
|
||||
"""Return the battery unit of measurement."""
|
||||
return PERCENTAGE
|
||||
|
||||
|
||||
class DiffuserWifiSensor(DiffuserEntity):
|
||||
"""Representation of a diffuser wifi sensor."""
|
||||
|
||||
_attr_device_class = DEVICE_CLASS_SIGNAL_STRENGTH
|
||||
_attr_unit_of_measurement = PERCENTAGE
|
||||
|
||||
def __init__(
|
||||
self, diffuser: Diffuser, coordinator: RitualsDataUpdateCoordinator
|
||||
) -> None:
|
||||
@ -131,13 +124,3 @@ class DiffuserWifiSensor(DiffuserEntity):
|
||||
def state(self) -> int:
|
||||
"""Return the state of the wifi sensor."""
|
||||
return self._diffuser.wifi_percentage
|
||||
|
||||
@property
|
||||
def device_class(self) -> str:
|
||||
"""Return the class of the wifi sensor."""
|
||||
return DEVICE_CLASS_SIGNAL_STRENGTH
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self) -> str:
|
||||
"""Return the wifi unit of measurement."""
|
||||
return PERCENTAGE
|
||||
|
@ -14,10 +14,6 @@ from . import RitualsDataUpdateCoordinator
|
||||
from .const import COORDINATORS, DEVICES, DOMAIN
|
||||
from .entity import DiffuserEntity
|
||||
|
||||
FAN = "fanc"
|
||||
|
||||
ON_STATE = "1"
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
@ -38,46 +34,37 @@ async def async_setup_entry(
|
||||
class DiffuserSwitch(SwitchEntity, DiffuserEntity):
|
||||
"""Representation of a diffuser switch."""
|
||||
|
||||
_attr_icon = "mdi:fan"
|
||||
|
||||
def __init__(
|
||||
self, diffuser: Diffuser, coordinator: RitualsDataUpdateCoordinator
|
||||
) -> None:
|
||||
"""Initialize the diffuser switch."""
|
||||
super().__init__(diffuser, coordinator, "")
|
||||
self._is_on = self._diffuser.is_on
|
||||
|
||||
@property
|
||||
def icon(self) -> str:
|
||||
"""Return the icon of the device."""
|
||||
return "mdi:fan"
|
||||
self._attr_is_on = self._diffuser.is_on
|
||||
|
||||
@property
|
||||
def extra_state_attributes(self) -> dict[str, Any]:
|
||||
"""Return the device state attributes."""
|
||||
attributes = {
|
||||
return {
|
||||
"fan_speed": self._diffuser.perfume_amount,
|
||||
"room_size": self._diffuser.room_size,
|
||||
}
|
||||
return attributes
|
||||
|
||||
@property
|
||||
def is_on(self) -> bool:
|
||||
"""If the device is currently on or off."""
|
||||
return self._is_on
|
||||
|
||||
async def async_turn_on(self, **kwargs: Any) -> None:
|
||||
"""Turn the device on."""
|
||||
await self._diffuser.turn_on()
|
||||
self._is_on = True
|
||||
self._attr_is_on = True
|
||||
self.async_write_ha_state()
|
||||
|
||||
async def async_turn_off(self, **kwargs: Any) -> None:
|
||||
"""Turn the device off."""
|
||||
await self._diffuser.turn_off()
|
||||
self._is_on = False
|
||||
self._attr_is_on = False
|
||||
self.async_write_ha_state()
|
||||
|
||||
@callback
|
||||
def _handle_coordinator_update(self) -> None:
|
||||
"""Handle updated data from the coordinator."""
|
||||
self._is_on = self._diffuser.is_on
|
||||
self._attr_is_on = self._diffuser.is_on
|
||||
self.async_write_ha_state()
|
||||
|
Loading…
x
Reference in New Issue
Block a user