* Add Braava support to iRobot Roomba component * Replace async_add_job with async_add_executor_job in roomba * Improve readability in roomba * Improve error handling in roomba * Cleanup async_update in roomba * Split into multiple files in roomba * Hide protocal details in braava * Switch to push in braava * Bump roombapy version to 1.5.1 * Add roomba files to .coveragerc * Fix typo * Remove side effects from init in roomba * Implement StateVacuumDevice in Roomba * Add IRobotEntity base class to braava * Fix state in roomba * Add @shenxn as a codeowner of braava
52 lines
1.5 KiB
Python
52 lines
1.5 KiB
Python
"""Roomba binary sensor entities."""
|
|
import logging
|
|
|
|
from homeassistant.components.binary_sensor import BinarySensorDevice
|
|
|
|
from . import roomba_reported_state
|
|
from .const import BLID, DOMAIN, ROOMBA_SESSION
|
|
from .irobot_base import IRobotEntity
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
|
async def async_setup_entry(hass, config_entry, async_add_entities):
|
|
"""Set up the iRobot Roomba vacuum cleaner."""
|
|
domain_data = hass.data[DOMAIN][config_entry.entry_id]
|
|
roomba = domain_data[ROOMBA_SESSION]
|
|
blid = domain_data[BLID]
|
|
status = roomba_reported_state(roomba).get("bin", {})
|
|
if "full" in status:
|
|
roomba_vac = RoombaBinStatus(roomba, blid)
|
|
roomba_vac.register_callback()
|
|
async_add_entities([roomba_vac], True)
|
|
|
|
|
|
class RoombaBinStatus(IRobotEntity, BinarySensorDevice):
|
|
"""Class to hold Roomba Sensor basic info."""
|
|
|
|
ICON = "mdi:delete-variant"
|
|
|
|
@property
|
|
def name(self):
|
|
"""Return the name of the sensor."""
|
|
return f"{self._name} Bin Full"
|
|
|
|
@property
|
|
def unique_id(self):
|
|
"""Return the ID of this sensor."""
|
|
return f"bin_{self._blid}"
|
|
|
|
@property
|
|
def icon(self):
|
|
"""Return the icon of this sensor."""
|
|
return self.ICON
|
|
|
|
@property
|
|
def state(self):
|
|
"""Return the state of the sensor."""
|
|
bin_status = (
|
|
roomba_reported_state(self.vacuum).get("bin", {}).get("full", False)
|
|
)
|
|
_LOGGER.debug("Update Full Bin status from the vacuum: %s", bin_status)
|
|
return bin_status
|