2020-08-30 12:16:41 +00:00
|
|
|
"""Binary sensor for Shelly."""
|
|
|
|
from homeassistant.components.binary_sensor import (
|
2020-09-03 08:54:25 +00:00
|
|
|
DEVICE_CLASS_GAS,
|
2020-08-30 12:16:41 +00:00
|
|
|
DEVICE_CLASS_MOISTURE,
|
|
|
|
DEVICE_CLASS_OPENING,
|
2020-09-08 21:22:44 +00:00
|
|
|
DEVICE_CLASS_PROBLEM,
|
2020-08-30 12:16:41 +00:00
|
|
|
DEVICE_CLASS_SMOKE,
|
2020-09-02 06:56:27 +00:00
|
|
|
DEVICE_CLASS_VIBRATION,
|
2020-08-30 12:16:41 +00:00
|
|
|
BinarySensorEntity,
|
|
|
|
)
|
|
|
|
|
2020-09-07 12:13:20 +00:00
|
|
|
from .entity import (
|
|
|
|
BlockAttributeDescription,
|
|
|
|
ShellyBlockAttributeEntity,
|
|
|
|
async_setup_entry_attribute_entities,
|
|
|
|
)
|
2020-08-30 12:16:41 +00:00
|
|
|
|
|
|
|
SENSORS = {
|
2020-09-08 21:22:44 +00:00
|
|
|
("device", "overtemp"): BlockAttributeDescription(
|
|
|
|
name="Overheating", device_class=DEVICE_CLASS_PROBLEM
|
|
|
|
),
|
|
|
|
("device", "overpower"): BlockAttributeDescription(
|
|
|
|
name="Over Power", device_class=DEVICE_CLASS_PROBLEM
|
|
|
|
),
|
|
|
|
("light", "overpower"): BlockAttributeDescription(
|
|
|
|
name="Over Power", device_class=DEVICE_CLASS_PROBLEM
|
|
|
|
),
|
|
|
|
("relay", "overpower"): BlockAttributeDescription(
|
|
|
|
name="Over Power", device_class=DEVICE_CLASS_PROBLEM
|
|
|
|
),
|
2020-09-07 12:13:20 +00:00
|
|
|
("sensor", "dwIsOpened"): BlockAttributeDescription(
|
|
|
|
name="Door", device_class=DEVICE_CLASS_OPENING
|
|
|
|
),
|
|
|
|
("sensor", "flood"): BlockAttributeDescription(
|
|
|
|
name="flood", device_class=DEVICE_CLASS_MOISTURE
|
|
|
|
),
|
|
|
|
("sensor", "gas"): BlockAttributeDescription(
|
|
|
|
name="gas",
|
|
|
|
device_class=DEVICE_CLASS_GAS,
|
|
|
|
value=lambda value: value in ["mild", "heavy"],
|
|
|
|
device_state_attributes=lambda block: {"detected": block.gas},
|
|
|
|
),
|
|
|
|
("sensor", "smoke"): BlockAttributeDescription(
|
|
|
|
name="smoke", device_class=DEVICE_CLASS_SMOKE
|
|
|
|
),
|
|
|
|
("sensor", "vibration"): BlockAttributeDescription(
|
|
|
|
name="vibration", device_class=DEVICE_CLASS_VIBRATION
|
|
|
|
),
|
2020-08-30 12:16:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async def async_setup_entry(hass, config_entry, async_add_entities):
|
|
|
|
"""Set up sensors for device."""
|
2020-09-07 12:13:20 +00:00
|
|
|
await async_setup_entry_attribute_entities(
|
|
|
|
hass, config_entry, async_add_entities, SENSORS, ShellyBinarySensor
|
|
|
|
)
|
2020-08-30 12:16:41 +00:00
|
|
|
|
|
|
|
|
2020-09-07 12:13:20 +00:00
|
|
|
class ShellyBinarySensor(ShellyBlockAttributeEntity, BinarySensorEntity):
|
|
|
|
"""Shelly binary sensor entity."""
|
2020-08-30 12:16:41 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def is_on(self):
|
2020-09-03 08:54:25 +00:00
|
|
|
"""Return true if sensor state is on."""
|
2020-09-07 12:13:20 +00:00
|
|
|
return bool(self.attribute_value)
|