mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 14:17:45 +00:00
Use properties instead of raw data in the rituals integration (#52587)
This commit is contained in:
parent
3e09787d85
commit
0a3aab935a
@ -11,7 +11,7 @@ from homeassistant.exceptions import ConfigEntryNotReady
|
|||||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
|
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
|
||||||
|
|
||||||
from .const import ACCOUNT_HASH, COORDINATORS, DEVICES, DOMAIN, HUBLOT
|
from .const import ACCOUNT_HASH, COORDINATORS, DEVICES, DOMAIN
|
||||||
|
|
||||||
PLATFORMS = ["binary_sensor", "number", "select", "sensor", "switch"]
|
PLATFORMS = ["binary_sensor", "number", "select", "sensor", "switch"]
|
||||||
|
|
||||||
@ -23,8 +23,7 @@ UPDATE_INTERVAL = timedelta(seconds=30)
|
|||||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
"""Set up Rituals Perfume Genie from a config entry."""
|
"""Set up Rituals Perfume Genie from a config entry."""
|
||||||
session = async_get_clientsession(hass)
|
session = async_get_clientsession(hass)
|
||||||
account = Account(session=session)
|
account = Account(session=session, account_hash=entry.data[ACCOUNT_HASH])
|
||||||
account.data = {ACCOUNT_HASH: entry.data.get(ACCOUNT_HASH)}
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
account_devices = await account.get_devices()
|
account_devices = await account.get_devices()
|
||||||
@ -37,7 +36,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
}
|
}
|
||||||
|
|
||||||
for device in account_devices:
|
for device in account_devices:
|
||||||
hublot = device.hub_data[HUBLOT]
|
hublot = device.hublot
|
||||||
|
|
||||||
coordinator = RitualsDataUpdateCoordinator(hass, device)
|
coordinator = RitualsDataUpdateCoordinator(hass, device)
|
||||||
await coordinator.async_refresh()
|
await coordinator.async_refresh()
|
||||||
@ -68,7 +67,7 @@ class RitualsDataUpdateCoordinator(DataUpdateCoordinator):
|
|||||||
super().__init__(
|
super().__init__(
|
||||||
hass,
|
hass,
|
||||||
_LOGGER,
|
_LOGGER,
|
||||||
name=f"{DOMAIN}-{device.hub_data[HUBLOT]}",
|
name=f"{DOMAIN}-{device.hublot}",
|
||||||
update_interval=UPDATE_INTERVAL,
|
update_interval=UPDATE_INTERVAL,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -47,12 +47,12 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
_LOGGER.exception("Unexpected exception")
|
_LOGGER.exception("Unexpected exception")
|
||||||
errors["base"] = "unknown"
|
errors["base"] = "unknown"
|
||||||
else:
|
else:
|
||||||
await self.async_set_unique_id(account.data[CONF_EMAIL])
|
await self.async_set_unique_id(account.email)
|
||||||
self._abort_if_unique_id_configured()
|
self._abort_if_unique_id_configured()
|
||||||
|
|
||||||
return self.async_create_entry(
|
return self.async_create_entry(
|
||||||
title=account.data[CONF_EMAIL],
|
title=account.email,
|
||||||
data={ACCOUNT_HASH: account.data[ACCOUNT_HASH]},
|
data={ACCOUNT_HASH: account.account_hash},
|
||||||
)
|
)
|
||||||
|
|
||||||
return self.async_show_form(
|
return self.async_show_form(
|
||||||
|
@ -1,9 +1,7 @@
|
|||||||
"""Constants for the Rituals Perfume Genie integration."""
|
"""Constants for the Rituals Perfume Genie integration."""
|
||||||
DOMAIN = "rituals_perfume_genie"
|
DOMAIN = "rituals_perfume_genie"
|
||||||
|
|
||||||
|
ACCOUNT_HASH = "account_hash"
|
||||||
|
|
||||||
COORDINATORS = "coordinators"
|
COORDINATORS = "coordinators"
|
||||||
DEVICES = "devices"
|
DEVICES = "devices"
|
||||||
|
|
||||||
ACCOUNT_HASH = "account_hash"
|
|
||||||
HUBLOT = "hublot"
|
|
||||||
SENSORS = "sensors"
|
|
||||||
|
@ -6,19 +6,12 @@ from pyrituals import Diffuser
|
|||||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||||
|
|
||||||
from . import RitualsDataUpdateCoordinator
|
from . import RitualsDataUpdateCoordinator
|
||||||
from .const import DOMAIN, HUBLOT, SENSORS
|
from .const import DOMAIN
|
||||||
|
|
||||||
MANUFACTURER = "Rituals Cosmetics"
|
MANUFACTURER = "Rituals Cosmetics"
|
||||||
MODEL = "The Perfume Genie"
|
MODEL = "The Perfume Genie"
|
||||||
MODEL2 = "The Perfume Genie 2.0"
|
MODEL2 = "The Perfume Genie 2.0"
|
||||||
|
|
||||||
ATTRIBUTES = "attributes"
|
|
||||||
ROOMNAME = "roomnamec"
|
|
||||||
STATUS = "status"
|
|
||||||
VERSION = "versionc"
|
|
||||||
|
|
||||||
AVAILABLE_STATE = 1
|
|
||||||
|
|
||||||
|
|
||||||
class DiffuserEntity(CoordinatorEntity):
|
class DiffuserEntity(CoordinatorEntity):
|
||||||
"""Representation of a diffuser entity."""
|
"""Representation of a diffuser entity."""
|
||||||
@ -35,8 +28,8 @@ class DiffuserEntity(CoordinatorEntity):
|
|||||||
super().__init__(coordinator)
|
super().__init__(coordinator)
|
||||||
self._diffuser = diffuser
|
self._diffuser = diffuser
|
||||||
|
|
||||||
hublot = self._diffuser.hub_data[HUBLOT]
|
hublot = self._diffuser.hublot
|
||||||
hubname = self._diffuser.hub_data[ATTRIBUTES][ROOMNAME]
|
hubname = self._diffuser.name
|
||||||
|
|
||||||
self._attr_name = f"{hubname}{entity_suffix}"
|
self._attr_name = f"{hubname}{entity_suffix}"
|
||||||
self._attr_unique_id = f"{hublot}{entity_suffix}"
|
self._attr_unique_id = f"{hublot}{entity_suffix}"
|
||||||
@ -45,10 +38,10 @@ class DiffuserEntity(CoordinatorEntity):
|
|||||||
"identifiers": {(DOMAIN, hublot)},
|
"identifiers": {(DOMAIN, hublot)},
|
||||||
"manufacturer": MANUFACTURER,
|
"manufacturer": MANUFACTURER,
|
||||||
"model": MODEL if diffuser.has_battery else MODEL2,
|
"model": MODEL if diffuser.has_battery else MODEL2,
|
||||||
"sw_version": diffuser.hub_data[SENSORS][VERSION],
|
"sw_version": diffuser.version,
|
||||||
}
|
}
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def available(self) -> bool:
|
def available(self) -> bool:
|
||||||
"""Return if the entity is available."""
|
"""Return if the entity is available."""
|
||||||
return super().available and self._diffuser.hub_data[STATUS] == AVAILABLE_STATE
|
return super().available and self._diffuser.is_online
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
"name": "Rituals Perfume Genie",
|
"name": "Rituals Perfume Genie",
|
||||||
"config_flow": true,
|
"config_flow": true,
|
||||||
"documentation": "https://www.home-assistant.io/integrations/rituals_perfume_genie",
|
"documentation": "https://www.home-assistant.io/integrations/rituals_perfume_genie",
|
||||||
"requirements": ["pyrituals==0.0.4"],
|
"requirements": ["pyrituals==0.0.5"],
|
||||||
"codeowners": ["@milanmeu"],
|
"codeowners": ["@milanmeu"],
|
||||||
"iot_class": "cloud_polling"
|
"iot_class": "cloud_polling"
|
||||||
}
|
}
|
||||||
|
@ -13,16 +13,9 @@ from homeassistant.core import HomeAssistant
|
|||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from . import RitualsDataUpdateCoordinator
|
from . import RitualsDataUpdateCoordinator
|
||||||
from .const import COORDINATORS, DEVICES, DOMAIN, SENSORS
|
from .const import COORDINATORS, DEVICES, DOMAIN
|
||||||
from .entity import DiffuserEntity
|
from .entity import DiffuserEntity
|
||||||
|
|
||||||
ID = "id"
|
|
||||||
PERFUME = "rfidc"
|
|
||||||
FILL = "fillc"
|
|
||||||
|
|
||||||
PERFUME_NO_CARTRIDGE_ID = 19
|
|
||||||
FILL_NO_CARTRIDGE_ID = 12
|
|
||||||
|
|
||||||
BATTERY_SUFFIX = " Battery"
|
BATTERY_SUFFIX = " Battery"
|
||||||
PERFUME_SUFFIX = " Perfume"
|
PERFUME_SUFFIX = " Perfume"
|
||||||
FILL_SUFFIX = " Fill"
|
FILL_SUFFIX = " Fill"
|
||||||
@ -58,9 +51,9 @@ class DiffuserPerfumeSensor(DiffuserEntity):
|
|||||||
"""Initialize the perfume sensor."""
|
"""Initialize the perfume sensor."""
|
||||||
super().__init__(diffuser, coordinator, PERFUME_SUFFIX)
|
super().__init__(diffuser, coordinator, PERFUME_SUFFIX)
|
||||||
|
|
||||||
self._attr_icon = "mdi:tag-text"
|
self._attr_icon = "mdi:tag-remove"
|
||||||
if diffuser.hub_data[SENSORS][PERFUME][ID] == PERFUME_NO_CARTRIDGE_ID:
|
if diffuser.has_cartridge:
|
||||||
self._attr_icon = "mdi:tag-remove"
|
self._attr_icon = "mdi:tag-text"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self) -> str:
|
def state(self) -> str:
|
||||||
@ -77,12 +70,9 @@ class DiffuserFillSensor(DiffuserEntity):
|
|||||||
"""Initialize the fill sensor."""
|
"""Initialize the fill sensor."""
|
||||||
super().__init__(diffuser, coordinator, FILL_SUFFIX)
|
super().__init__(diffuser, coordinator, FILL_SUFFIX)
|
||||||
|
|
||||||
@property
|
self._attr_icon = "mdi:beaker-question"
|
||||||
def icon(self) -> str:
|
if diffuser.has_cartridge:
|
||||||
"""Return the fill sensor icon."""
|
self.attr_icon = "mdi:beaker"
|
||||||
if self._diffuser.hub_data[SENSORS][FILL][ID] == FILL_NO_CARTRIDGE_ID:
|
|
||||||
return "mdi:beaker-question"
|
|
||||||
return "mdi:beaker"
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self) -> str:
|
def state(self) -> str:
|
||||||
|
@ -1706,7 +1706,7 @@ pyrepetier==3.0.5
|
|||||||
pyrisco==0.3.1
|
pyrisco==0.3.1
|
||||||
|
|
||||||
# homeassistant.components.rituals_perfume_genie
|
# homeassistant.components.rituals_perfume_genie
|
||||||
pyrituals==0.0.4
|
pyrituals==0.0.5
|
||||||
|
|
||||||
# homeassistant.components.ruckus_unleashed
|
# homeassistant.components.ruckus_unleashed
|
||||||
pyruckus==0.12
|
pyruckus==0.12
|
||||||
|
@ -969,7 +969,7 @@ pyqwikswitch==0.93
|
|||||||
pyrisco==0.3.1
|
pyrisco==0.3.1
|
||||||
|
|
||||||
# homeassistant.components.rituals_perfume_genie
|
# homeassistant.components.rituals_perfume_genie
|
||||||
pyrituals==0.0.4
|
pyrituals==0.0.5
|
||||||
|
|
||||||
# homeassistant.components.ruckus_unleashed
|
# homeassistant.components.ruckus_unleashed
|
||||||
pyruckus==0.12
|
pyruckus==0.12
|
||||||
|
@ -16,7 +16,8 @@ WRONG_PASSWORD = "wrong-passw0rd"
|
|||||||
def _mock_account(*_):
|
def _mock_account(*_):
|
||||||
account = MagicMock()
|
account = MagicMock()
|
||||||
account.authenticate = AsyncMock()
|
account.authenticate = AsyncMock()
|
||||||
account.data = {CONF_EMAIL: TEST_EMAIL, ACCOUNT_HASH: "any"}
|
account.account_hash = "any"
|
||||||
|
account.email = TEST_EMAIL
|
||||||
return account
|
return account
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user