Add binary sensor support to the Flo integration (#38267)
* update device * add binary sensor * updates post rebase * fix entity type post rebase * fix post rebase * fix add entities * fix name * review comments
This commit is contained in:
1 parent
03676693ce
commit
86aa758ecd
5 files changed
+108
-1
No files matched your search
@@ -0,0 +1,49 @@
|
||||
"""Support for Flo Water Monitor binary sensors."""
|
||||
|
||||
from typing import List
|
||||
|
||||
from homeassistant.components.binary_sensor import (
|
||||
DEVICE_CLASS_PROBLEM,
|
||||
BinarySensorEntity,
|
||||
)
|
||||
|
||||
from .const import DOMAIN as FLO_DOMAIN
|
||||
from .device import FloDeviceDataUpdateCoordinator
|
||||
from .entity import FloEntity
|
||||
|
||||
DEPENDENCIES = ["flo"]
|
||||
|
||||
|
||||
async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||
"""Set up the Flo sensors from config entry."""
|
||||
devices: List[FloDeviceDataUpdateCoordinator] = hass.data[FLO_DOMAIN]["devices"]
|
||||
entities = [FloPendingAlertsBinarySensor(device) for device in devices]
|
||||
async_add_entities(entities)
|
||||
|
||||
|
||||
class FloPendingAlertsBinarySensor(FloEntity, BinarySensorEntity):
|
||||
"""Binary sensor that reports on if there are any pending system alerts."""
|
||||
|
||||
def __init__(self, device):
|
||||
"""Initialize the pending alerts binary sensor."""
|
||||
super().__init__("pending_system_alerts", "Pending System Alerts", device)
|
||||
|
||||
@property
|
||||
def is_on(self):
|
||||
"""Return true if the Flo device has pending alerts."""
|
||||
return self._device.has_alerts
|
||||
|
||||
@property
|
||||
def device_state_attributes(self):
|
||||
"""Return the state attributes."""
|
||||
attr = {}
|
||||
if self._device.has_alerts:
|
||||
attr["info"] = self._device.pending_info_alerts_count
|
||||
attr["warning"] = self._device.pending_warning_alerts_count
|
||||
attr["critical"] = self._device.pending_critical_alerts_count
|
||||
return attr
|
||||
|
||||
@property
|
||||
def device_class(self):
|
||||
"""Return the device class for the binary sensor."""
|
||||
return DEVICE_CLASS_PROBLEM
|
||||
Reference in new issue
Block a user