Add Braava support to iRobot Roomba component (#33616)

* 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
This commit is contained in:
Xiaonan Shen 2020-04-18 15:32:41 -07:00 committed by GitHub
parent b3eba49a2f
commit 61a5793073
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 520 additions and 374 deletions

View file

@ -5,6 +5,7 @@ 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__)
@ -17,23 +18,15 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
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(BinarySensorDevice):
class RoombaBinStatus(IRobotEntity, BinarySensorDevice):
"""Class to hold Roomba Sensor basic info."""
ICON = "mdi:delete-variant"
def __init__(self, roomba, blid):
"""Initialize the sensor object."""
self.vacuum = roomba
self.vacuum_state = roomba_reported_state(roomba)
self._blid = blid
self._name = self.vacuum_state.get("name")
self._identifier = f"roomba_{self._blid}"
self._bin_status = None
@property
def name(self):
"""Return the name of the sensor."""
@ -52,23 +45,8 @@ class RoombaBinStatus(BinarySensorDevice):
@property
def state(self):
"""Return the state of the sensor."""
return self._bin_status
@property
def device_info(self):
"""Return the device info of the vacuum cleaner."""
return {
"identifiers": {(DOMAIN, self._identifier)},
"name": str(self._name),
}
async def async_update(self):
"""Return the update info of the vacuum cleaner."""
# No data, no update
if not self.vacuum.master_state:
_LOGGER.debug("Roomba %s has no data yet. Skip update", self.name)
return
self._bin_status = (
bin_status = (
roomba_reported_state(self.vacuum).get("bin", {}).get("full", False)
)
_LOGGER.debug("Update Full Bin status from the vacuum: %s", self._bin_status)
_LOGGER.debug("Update Full Bin status from the vacuum: %s", bin_status)
return bin_status