Add binary sensor platform to Rituals Perfume Genie Integration (#49207)
* Add binary sensor platform to Rituals * Sort platformspull/49229/head
parent
403c6b9e26
commit
ed54494b69
|
@ -826,6 +826,7 @@ omit =
|
|||
homeassistant/components/rest/switch.py
|
||||
homeassistant/components/ring/camera.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/sensor.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
|
||||
|
||||
PLATFORMS = ["switch", "sensor"]
|
||||
PLATFORMS = ["binary_sensor", "sensor", "switch"]
|
||||
|
||||
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"
|
||||
ATTRIBUTES = "attributes"
|
||||
BATTERY = "battc"
|
||||
HUB = "hub"
|
||||
HUBLOT = "hublot"
|
||||
ID = "id"
|
||||
SENSORS = "sensors"
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
"""Base class for Rituals Perfume Genie diffuser entity."""
|
||||
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"
|
||||
MODEL = "Diffuser"
|
||||
|
||||
SENSORS = "sensors"
|
||||
ROOMNAME = "roomnamec"
|
||||
VERSION = "versionc"
|
||||
|
||||
|
|
|
@ -1,24 +1,20 @@
|
|||
"""Support for Rituals Perfume Genie sensors."""
|
||||
from homeassistant.const import (
|
||||
ATTR_BATTERY_CHARGING,
|
||||
ATTR_BATTERY_LEVEL,
|
||||
DEVICE_CLASS_BATTERY,
|
||||
DEVICE_CLASS_SIGNAL_STRENGTH,
|
||||
PERCENTAGE,
|
||||
)
|
||||
|
||||
from .const import COORDINATORS, DEVICES, DOMAIN, HUB
|
||||
from .entity import SENSORS, DiffuserEntity
|
||||
from .const import BATTERY, COORDINATORS, DEVICES, DOMAIN, HUB, ID, SENSORS
|
||||
from .entity import DiffuserEntity
|
||||
|
||||
ID = "id"
|
||||
TITLE = "title"
|
||||
ICON = "icon"
|
||||
WIFI = "wific"
|
||||
BATTERY = "battc"
|
||||
PERFUME = "rfidc"
|
||||
FILL = "fillc"
|
||||
|
||||
BATTERY_CHARGING_ID = 21
|
||||
PERFUME_NO_CARTRIDGE_ID = 19
|
||||
FILL_NO_CARTRIDGE_ID = 12
|
||||
|
||||
|
@ -106,13 +102,6 @@ class DiffuserBatterySensor(DiffuserEntity):
|
|||
"battery-low.png": 10,
|
||||
}[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
|
||||
def device_class(self):
|
||||
"""Return the class of the battery sensor."""
|
||||
|
@ -123,7 +112,6 @@ class DiffuserBatterySensor(DiffuserEntity):
|
|||
"""Return the battery state attributes."""
|
||||
return {
|
||||
ATTR_BATTERY_LEVEL: self.coordinator.data[HUB][SENSORS][BATTERY][TITLE],
|
||||
ATTR_BATTERY_CHARGING: self._charging,
|
||||
}
|
||||
|
||||
@property
|
||||
|
|
Loading…
Reference in New Issue