Add binary sensor platform to Rituals Perfume Genie Integration (#49207)
* Add binary sensor platform to Rituals * Sort platforms
This commit is contained in:
parent
403c6b9e26
commit
ed54494b69
6 changed files with 52 additions and 17 deletions
|
@ -826,6 +826,7 @@ omit =
|
||||||
homeassistant/components/rest/switch.py
|
homeassistant/components/rest/switch.py
|
||||||
homeassistant/components/ring/camera.py
|
homeassistant/components/ring/camera.py
|
||||||
homeassistant/components/ripple/sensor.py
|
homeassistant/components/ripple/sensor.py
|
||||||
|
homeassistant/components/rituals_perfume_genie/binary_sensor.py
|
||||||
homeassistant/components/rituals_perfume_genie/entity.py
|
homeassistant/components/rituals_perfume_genie/entity.py
|
||||||
homeassistant/components/rituals_perfume_genie/sensor.py
|
homeassistant/components/rituals_perfume_genie/sensor.py
|
||||||
homeassistant/components/rituals_perfume_genie/switch.py
|
homeassistant/components/rituals_perfume_genie/switch.py
|
||||||
|
|
|
@ -14,7 +14,7 @@ from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
|
||||||
|
|
||||||
from .const import ACCOUNT_HASH, COORDINATORS, DEVICES, DOMAIN, HUB, HUBLOT
|
from .const import ACCOUNT_HASH, COORDINATORS, DEVICES, DOMAIN, HUB, HUBLOT
|
||||||
|
|
||||||
PLATFORMS = ["switch", "sensor"]
|
PLATFORMS = ["binary_sensor", "sensor", "switch"]
|
||||||
|
|
||||||
EMPTY_CREDENTIALS = ""
|
EMPTY_CREDENTIALS = ""
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,44 @@
|
||||||
|
"""Support for Rituals Perfume Genie binary sensors."""
|
||||||
|
from homeassistant.components.binary_sensor import (
|
||||||
|
DEVICE_CLASS_BATTERY_CHARGING,
|
||||||
|
BinarySensorEntity,
|
||||||
|
)
|
||||||
|
|
||||||
|
from .const import BATTERY, COORDINATORS, DEVICES, DOMAIN, HUB, ID
|
||||||
|
from .entity import SENSORS, DiffuserEntity
|
||||||
|
|
||||||
|
CHARGING_SUFFIX = " Battery Charging"
|
||||||
|
BATTERY_CHARGING_ID = 21
|
||||||
|
|
||||||
|
|
||||||
|
async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||||
|
"""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 BATTERY in diffuser.data[HUB][SENSORS]:
|
||||||
|
coordinator = coordinators[hublot]
|
||||||
|
entities.append(DiffuserBatteryChargingBinarySensor(diffuser, coordinator))
|
||||||
|
|
||||||
|
async_add_entities(entities)
|
||||||
|
|
||||||
|
|
||||||
|
class DiffuserBatteryChargingBinarySensor(DiffuserEntity, BinarySensorEntity):
|
||||||
|
"""Representation of a diffuser battery charging binary sensor."""
|
||||||
|
|
||||||
|
def __init__(self, diffuser, coordinator):
|
||||||
|
"""Initialize the battery charging binary sensor."""
|
||||||
|
super().__init__(diffuser, coordinator, CHARGING_SUFFIX)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def is_on(self):
|
||||||
|
"""Return the state of the battery charging binary sensor."""
|
||||||
|
return bool(
|
||||||
|
self.coordinator.data[HUB][SENSORS][BATTERY][ID] == BATTERY_CHARGING_ID
|
||||||
|
)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def device_class(self):
|
||||||
|
"""Return the device class of the battery charging binary sensor."""
|
||||||
|
return DEVICE_CLASS_BATTERY_CHARGING
|
|
@ -6,5 +6,8 @@ DEVICES = "devices"
|
||||||
|
|
||||||
ACCOUNT_HASH = "account_hash"
|
ACCOUNT_HASH = "account_hash"
|
||||||
ATTRIBUTES = "attributes"
|
ATTRIBUTES = "attributes"
|
||||||
|
BATTERY = "battc"
|
||||||
HUB = "hub"
|
HUB = "hub"
|
||||||
HUBLOT = "hublot"
|
HUBLOT = "hublot"
|
||||||
|
ID = "id"
|
||||||
|
SENSORS = "sensors"
|
||||||
|
|
|
@ -1,12 +1,11 @@
|
||||||
"""Base class for Rituals Perfume Genie diffuser entity."""
|
"""Base class for Rituals Perfume Genie diffuser entity."""
|
||||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||||
|
|
||||||
from .const import ATTRIBUTES, DOMAIN, HUB, HUBLOT
|
from .const import ATTRIBUTES, DOMAIN, HUB, HUBLOT, SENSORS
|
||||||
|
|
||||||
MANUFACTURER = "Rituals Cosmetics"
|
MANUFACTURER = "Rituals Cosmetics"
|
||||||
MODEL = "Diffuser"
|
MODEL = "Diffuser"
|
||||||
|
|
||||||
SENSORS = "sensors"
|
|
||||||
ROOMNAME = "roomnamec"
|
ROOMNAME = "roomnamec"
|
||||||
VERSION = "versionc"
|
VERSION = "versionc"
|
||||||
|
|
||||||
|
|
|
@ -1,24 +1,20 @@
|
||||||
"""Support for Rituals Perfume Genie sensors."""
|
"""Support for Rituals Perfume Genie sensors."""
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
ATTR_BATTERY_CHARGING,
|
|
||||||
ATTR_BATTERY_LEVEL,
|
ATTR_BATTERY_LEVEL,
|
||||||
DEVICE_CLASS_BATTERY,
|
DEVICE_CLASS_BATTERY,
|
||||||
DEVICE_CLASS_SIGNAL_STRENGTH,
|
DEVICE_CLASS_SIGNAL_STRENGTH,
|
||||||
PERCENTAGE,
|
PERCENTAGE,
|
||||||
)
|
)
|
||||||
|
|
||||||
from .const import COORDINATORS, DEVICES, DOMAIN, HUB
|
from .const import BATTERY, COORDINATORS, DEVICES, DOMAIN, HUB, ID, SENSORS
|
||||||
from .entity import SENSORS, DiffuserEntity
|
from .entity import DiffuserEntity
|
||||||
|
|
||||||
ID = "id"
|
|
||||||
TITLE = "title"
|
TITLE = "title"
|
||||||
ICON = "icon"
|
ICON = "icon"
|
||||||
WIFI = "wific"
|
WIFI = "wific"
|
||||||
BATTERY = "battc"
|
|
||||||
PERFUME = "rfidc"
|
PERFUME = "rfidc"
|
||||||
FILL = "fillc"
|
FILL = "fillc"
|
||||||
|
|
||||||
BATTERY_CHARGING_ID = 21
|
|
||||||
PERFUME_NO_CARTRIDGE_ID = 19
|
PERFUME_NO_CARTRIDGE_ID = 19
|
||||||
FILL_NO_CARTRIDGE_ID = 12
|
FILL_NO_CARTRIDGE_ID = 12
|
||||||
|
|
||||||
|
@ -106,13 +102,6 @@ class DiffuserBatterySensor(DiffuserEntity):
|
||||||
"battery-low.png": 10,
|
"battery-low.png": 10,
|
||||||
}[self.coordinator.data[HUB][SENSORS][BATTERY][ICON]]
|
}[self.coordinator.data[HUB][SENSORS][BATTERY][ICON]]
|
||||||
|
|
||||||
@property
|
|
||||||
def _charging(self):
|
|
||||||
"""Return battery charging state."""
|
|
||||||
return bool(
|
|
||||||
self.coordinator.data[HUB][SENSORS][BATTERY][ID] == BATTERY_CHARGING_ID
|
|
||||||
)
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def device_class(self):
|
def device_class(self):
|
||||||
"""Return the class of the battery sensor."""
|
"""Return the class of the battery sensor."""
|
||||||
|
@ -123,7 +112,6 @@ class DiffuserBatterySensor(DiffuserEntity):
|
||||||
"""Return the battery state attributes."""
|
"""Return the battery state attributes."""
|
||||||
return {
|
return {
|
||||||
ATTR_BATTERY_LEVEL: self.coordinator.data[HUB][SENSORS][BATTERY][TITLE],
|
ATTR_BATTERY_LEVEL: self.coordinator.data[HUB][SENSORS][BATTERY][TITLE],
|
||||||
ATTR_BATTERY_CHARGING: self._charging,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|
Loading…
Add table
Reference in a new issue