2021-02-01 17:12:56 +00:00
|
|
|
"""Support for Plaato Airlock sensors."""
|
2021-12-16 15:00:22 +00:00
|
|
|
from __future__ import annotations
|
2021-02-01 17:12:56 +00:00
|
|
|
|
|
|
|
from pyplaato.plaato import PlaatoKeg
|
|
|
|
|
|
|
|
from homeassistant.components.binary_sensor import (
|
2021-12-16 15:00:22 +00:00
|
|
|
BinarySensorDeviceClass,
|
2021-02-01 17:12:56 +00:00
|
|
|
BinarySensorEntity,
|
|
|
|
)
|
2022-01-03 10:35:02 +00:00
|
|
|
from homeassistant.config_entries import ConfigEntry
|
|
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
2021-02-01 17:12:56 +00:00
|
|
|
|
|
|
|
from .const import CONF_USE_WEBHOOK, COORDINATOR, DOMAIN
|
|
|
|
from .entity import PlaatoEntity
|
|
|
|
|
|
|
|
|
2022-01-03 10:35:02 +00:00
|
|
|
async def async_setup_entry(
|
|
|
|
hass: HomeAssistant,
|
|
|
|
config_entry: ConfigEntry,
|
|
|
|
async_add_entities: AddEntitiesCallback,
|
|
|
|
) -> None:
|
2021-02-01 17:12:56 +00:00
|
|
|
"""Set up Plaato from a config entry."""
|
|
|
|
|
|
|
|
if config_entry.data[CONF_USE_WEBHOOK]:
|
2021-02-05 17:28:06 +00:00
|
|
|
return
|
2021-02-01 17:12:56 +00:00
|
|
|
|
|
|
|
coordinator = hass.data[DOMAIN][config_entry.entry_id][COORDINATOR]
|
|
|
|
async_add_entities(
|
|
|
|
PlaatoBinarySensor(
|
|
|
|
hass.data[DOMAIN][config_entry.entry_id],
|
|
|
|
sensor_type,
|
|
|
|
coordinator,
|
|
|
|
)
|
2021-02-05 17:28:06 +00:00
|
|
|
for sensor_type in coordinator.data.binary_sensors
|
2021-02-01 17:12:56 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class PlaatoBinarySensor(PlaatoEntity, BinarySensorEntity):
|
|
|
|
"""Representation of a Binary Sensor."""
|
|
|
|
|
|
|
|
@property
|
|
|
|
def is_on(self):
|
|
|
|
"""Return true if the binary sensor is on."""
|
|
|
|
if self._coordinator is not None:
|
|
|
|
return self._coordinator.data.binary_sensors.get(self._sensor_type)
|
|
|
|
return False
|
|
|
|
|
|
|
|
@property
|
2021-12-16 15:00:22 +00:00
|
|
|
def device_class(self) -> BinarySensorDeviceClass | None:
|
|
|
|
"""Return the class of this device, from BinarySensorDeviceClass."""
|
2021-02-01 17:12:56 +00:00
|
|
|
if self._coordinator is None:
|
|
|
|
return None
|
|
|
|
if self._sensor_type is PlaatoKeg.Pins.LEAK_DETECTION:
|
2021-12-16 15:00:22 +00:00
|
|
|
return BinarySensorDeviceClass.PROBLEM
|
2021-02-01 17:12:56 +00:00
|
|
|
if self._sensor_type is PlaatoKeg.Pins.POURING:
|
2021-12-16 15:00:22 +00:00
|
|
|
return BinarySensorDeviceClass.OPENING
|
2022-01-20 08:58:12 +00:00
|
|
|
return None
|